From 54870fb76b5f59cc2e6d69a8c7a8ef17853a0029 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 5 Dec 2016 15:09:04 +0200 Subject: Add comma, ternary, logical operators support in eval context --- unit-tests/function/call.test | 3 +- unit-tests/function/driver.cxx | 1 + unit-tests/function/syntax.test | 2 ++ unit-tests/lexer/buildfile | 2 +- unit-tests/lexer/eval.test | 76 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 unit-tests/lexer/eval.test (limited to 'unit-tests') diff --git a/unit-tests/function/call.test b/unit-tests/function/call.test index d16b91c..9129785 100644 --- a/unit-tests/function/call.test +++ b/unit-tests/function/call.test @@ -25,8 +25,7 @@ $* <'print $dummy.abs([abs_dir_path] .)' >'true' : variadic : -# @@ TMP: add some args -$* <'print $variadic([bool] true)' >'1' +$* <'print $variadic([bool] true, foo, bar)' >'3' : fail : diff --git a/unit-tests/function/driver.cxx b/unit-tests/function/driver.cxx index 3dea374..235af0c 100644 --- a/unit-tests/function/driver.cxx +++ b/unit-tests/function/driver.cxx @@ -38,6 +38,7 @@ namespace build2 f["dummy0"] = []() {return "abc";}; f["dummy1"] = [](string s) {return s;}; + f["dummy2"] = [](uint64_t x, uint64_t y) {return x + y;}; f["ambig"] = [](names a, optional) {return a;}; f["ambig"] = [](names a, optional) {return a;}; diff --git a/unit-tests/function/syntax.test b/unit-tests/function/syntax.test index d644fd1..11ff3c1 100644 --- a/unit-tests/function/syntax.test +++ b/unit-tests/function/syntax.test @@ -12,6 +12,8 @@ $* <'$dump(d/t{x y z})' >'d/t{x} d/t{y} d/t{z}' : one-names $* <'print a$dummy1 ([string] b)c' >'abc' : concat +$* <'print $dummy2([uint64] 123, [uint64] 321)' >'444' : multi-arg + : quoting : Verify we can inhibit function call with quoting : diff --git a/unit-tests/lexer/buildfile b/unit-tests/lexer/buildfile index d9bd2df..bdd8dd1 100644 --- a/unit-tests/lexer/buildfile +++ b/unit-tests/lexer/buildfile @@ -8,6 +8,6 @@ import libs = libbutl%lib{butl} src = token lexer diagnostics utility variable name b-options types-parsers exe{driver}: cxx{driver} ../../build2/cxx{$src} $libs \ -test{comment quoting} +test{comment eval quoting} include ../../build2/ diff --git a/unit-tests/lexer/eval.test b/unit-tests/lexer/eval.test new file mode 100644 index 0000000..0f4f79b --- /dev/null +++ b/unit-tests/lexer/eval.test @@ -0,0 +1,76 @@ +# file : unit-tests/lexer/eval.test +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +test.arguments = eval + +: punctuation +: +$* <:'x:x{x}x[x]x$x?x,x(x)' >>EOO +'x' +: +'x' +{ +'x' +} +'x' +[ +'x' +] +'x' +$ +'x' +? +'x' +, +'x' +( +'x' +) +EOO + +: logical +: +$* <:'x|x||x&x&&x!x!!x)' >>EOO +'x|x' +|| +'x&x' +&& +'x' +! +'x' +! +! +'x' +) +EOO + +: comparison +: +$* <:'x=x==x!=xx>=)' >>EOO +'x=x' +== +'x' +!= +'x' +< +'x' +<= +'x' +> +'x' +>= +) +EOO + +: newline +: +$* <'x' >- 2>>EOE != 0 +stdin:1:2: error: newline in evaluation context +EOE + +: eof +: +$* <:'' 2>>EOE != 0 +stdin:1:1: error: unterminated evaluation context +EOE -- cgit v1.1