From 79cb3221c2babe6f560f2e3e463e899631a32b33 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 23 Nov 2016 14:58:30 +0200 Subject: Implement few builtin functions that can operate on any value type() null() empty () identity() --- tests/function/buildfile | 2 +- tests/function/builtin/buildfile | 7 ++++ tests/function/builtin/testscript | 68 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/function/builtin/buildfile create mode 100644 tests/function/builtin/testscript (limited to 'tests/function') diff --git a/tests/function/buildfile b/tests/function/buildfile index 52288ca..6c26737 100644 --- a/tests/function/buildfile +++ b/tests/function/buildfile @@ -2,6 +2,6 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -d = path/ +d = builtin/ path/ ./: $d include $d diff --git a/tests/function/builtin/buildfile b/tests/function/builtin/buildfile new file mode 100644 index 0000000..5a49ad0 --- /dev/null +++ b/tests/function/builtin/buildfile @@ -0,0 +1,7 @@ +# file : tests/function/builtin/buildfile +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +./: test{testscript} + +test{*}: test = $effect($build.path) diff --git a/tests/function/builtin/testscript b/tests/function/builtin/testscript new file mode 100644 index 0000000..1a4c5d1 --- /dev/null +++ b/tests/function/builtin/testscript @@ -0,0 +1,68 @@ +# file : tests/function/path/testscript +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + ++mkdir build ++cat <>>build/bootstrap.build +project = test +amalgamation = +EOI + +test.options += -q --buildfile - noop + +: type +: +{ + $* <'print $type([string])' >'string' : empty-typed + $* <'print $type("")' >'' : empty-untyped + + $* <'print $type([string null])' >'string' : null-typed + $* <'print $type([null])' >'' : null-untyped + + $* <'print $type([string] abc)' >'string' : value-typed + $* <'print $type(abc)' >'' : value-untyped +} + +: null +: +{ + $* <'print $null("")' >'false' : empty + $* <'print $null(abc)' >'false' : value + $* <'print $null([null])' >'true' : null +} + +: empty +: +{ + $* <'true' : empty-untyped + x = + print \$empty\(\$x) + EOI + + $* <'print $empty([string])' >'true' : empty-typed + $* <'print $empty(abc)' >'false' : name + $* <'print $empty(abc cxx{foo})' >'false' : names + $* <'print $empty([bool] false)' >'false' : bool +} + +: identity +: +{ + $* <'print $identity([string])' >''; + $* <'print $type($identity([string]))' >'string' : empty-typed + + $* <'print $identity("")' >'{}'; + $* <'print $type($identity(""))' >'' : empty-untyped + + $* <'print $identity([string null])' >'[null]'; + $* <'print $type($identity([string null]))' >'string' : null-typed + + $* <'print $identity([null])' >'[null]'; + $* <'print $type($identity([null]))' >'' : null-untyped + + $* <'print $identity([string] abc)' >'abc'; + $* <'print $type($identity([string] abc))' >'string' : null-typed + + $* <'print $identity(abc)' >'abc'; + $* <'print $type($identity(abc))' >'' : null-untyped +} -- cgit v1.1