aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-12-05 15:09:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-12-05 15:09:04 +0200
commit54870fb76b5f59cc2e6d69a8c7a8ef17853a0029 (patch)
tree770b01aa56348ec75f17fb834a2a7123ba9c3f73 /tests
parentef7cb7ea3e6fcb21a4fcf38602b3f43f03232ace (diff)
Add comma, ternary, logical operators support in eval context
Diffstat (limited to 'tests')
-rw-r--r--tests/buildfile2
-rw-r--r--tests/eval/buildfile5
-rw-r--r--tests/eval/comma.test13
-rw-r--r--tests/eval/comp.test47
-rw-r--r--tests/eval/or-and.test28
-rw-r--r--tests/eval/qual.test28
-rw-r--r--tests/eval/ternary.test30
-rw-r--r--tests/eval/value.test23
8 files changed, 175 insertions, 1 deletions
diff --git a/tests/buildfile b/tests/buildfile
index b05e2e7..a2fff9f 100644
--- a/tests/buildfile
+++ b/tests/buildfile
@@ -2,6 +2,6 @@
# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-d = directive/ expansion/ function/ test/ value/
+d = directive/ eval/ expansion/ function/ test/ value/
./: $d file{common.test}
include $d
diff --git a/tests/eval/buildfile b/tests/eval/buildfile
new file mode 100644
index 0000000..184a72a
--- /dev/null
+++ b/tests/eval/buildfile
@@ -0,0 +1,5 @@
+# file : tests/eval/buildfile
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+./: test{comma comp or-and qual ternary value}
diff --git a/tests/eval/comma.test b/tests/eval/comma.test
new file mode 100644
index 0000000..0e9384a
--- /dev/null
+++ b/tests/eval/comma.test
@@ -0,0 +1,13 @@
+# file : tests/eval/comma.test
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+# Test value packs (eval-comma).
+
+.include ../common.test
+
+: comma
+:
+$* <'print (foo, bar)' 2>>EOE != 0
+<stdin>:1:7: error: expected single value
+EOE
diff --git a/tests/eval/comp.test b/tests/eval/comp.test
new file mode 100644
index 0000000..4ef6c2d
--- /dev/null
+++ b/tests/eval/comp.test
@@ -0,0 +1,47 @@
+# file : tests/eval/comp.test
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+# Test comparison operators (eval-comp).
+
+.include ../common.test
+
+$* <'print (foo == bar)' >'false' : eq-false
+$* <'print (foo == foo)' >'true' : eq-true
+
+$* <'print (foo != foo)' >'false' : ne-false
+$* <'print (foo != bar)' >'true' : ne-true
+
+$* <'print (foo < bar)' >'false' : lt-false
+$* <'print (bar < foo)' >'true' : lt-true
+
+$* <'print (bar > foo)' >'false' : gt-false
+$* <'print (foo > bar)' >'true' : gt-true
+
+$* <'print (foo <= bar)' >'false' : le-false
+$* <'print (bar <= foo)' >'true' : le-true
+$* <'print (bar <= bar)' >'true' : le-true-eq
+
+$* <'print (bar >= foo)' >'false' : gt-false
+$* <'print (foo >= bar)' >'true' : gt-true
+$* <'print (foo >= foo)' >'true' : gt-true-eq
+
+: associativity
+:
+$* <'print (foo == bar == false)' >'true'
+
+: type
+:
+{
+ $* <'print ((foo bar) == foo bar)' >'true' : untyped-list
+ $* <'print ("" == "")' >'true' : untyped-empty
+
+ $* <'print (0 < 00)' >'true' : untyped-untyped
+ $* <'print (0 < [null])' >'false' : untyped-null
+ $* <'print ([uint64] 00 < 0)' >'false' : uint64-untyped
+ $* <'print ([uint64] 00 < [null])' >'false' : uint64-null
+ $* <'print ([uint64] 00 < [uint64] 0)' >'false' : uint64-uint64
+ $* <'print ([uint64] 00 < [string] 0)' 2>>EOE != 0 : uint64-string
+ <stdin>:1:20: error: comparison between uint64 and string
+ EOE
+}
diff --git a/tests/eval/or-and.test b/tests/eval/or-and.test
new file mode 100644
index 0000000..b9fb0b7
--- /dev/null
+++ b/tests/eval/or-and.test
@@ -0,0 +1,28 @@
+# file : tests/eval/or-and.test
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+# Test logical operators (eval-or, eval-and).
+
+.include ../common.test
+
+$* <'print (false || false)' >'false' : or-false
+$* <'print (false || true)' >'true' : or-true-1
+$* <'print (true || false)' >'true' : or-true-2
+
+$* <'print (false && true)' >'false' : and-false-1
+$* <'print (true && false)' >'false' : and-false-2
+$* <'print (true && true)' >'true' : and-true
+
+: associativity
+:
+: Also tests short-circuit.
+:
+{
+ $* <'print (true || $bogus($foo) || false)' >'true' : or
+ $* <'print (false && $bogus($foo) && false)' >'false' : and
+}
+
+: priority
+:
+$* <'print (false && true || true)' >'true'
diff --git a/tests/eval/qual.test b/tests/eval/qual.test
new file mode 100644
index 0000000..719ee9f
--- /dev/null
+++ b/tests/eval/qual.test
@@ -0,0 +1,28 @@
+# file : tests/eval/qual.test
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+# Test qualified name (eval-qual).
+
+.include ../common.test
+
+$* <'print (file{foo}: bar)' >'file{foo}:bar' : target
+$* <'print (foo/dir{}: bar)' >'dir{foo/}:bar' : scope
+
+: attribute
+:
+$* <'([string] foo:bar)' 2>>EOE != 0
+<stdin>:1:2: error: attributes before qualified variable name
+EOE
+
+: leader
+:
+$* <'(foo == foo:bar)' 2>>EOE != 0
+<stdin>:1:12: error: unexpected ':'
+EOE
+
+: trailer
+:
+$* <'(foo:bar == foo)' 2>>EOE != 0
+<stdin>:1:10: error: expected ')' after variable name
+EOE
diff --git a/tests/eval/ternary.test b/tests/eval/ternary.test
new file mode 100644
index 0000000..30a7e05
--- /dev/null
+++ b/tests/eval/ternary.test
@@ -0,0 +1,30 @@
+# file : tests/eval/ternary.test
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+# Test the ternary operator (eval-ternary).
+
+.include ../common.test
+
+$* <'print (true ? foo : bar)' >'foo' : true
+$* <'print (false ? foo : bar)' >'bar' : false
+
+: associativity
+:
+{
+ $* <'print (true ? false ? foo : bar : baz)' >'bar' : middle
+ $* <'print (true ? foo : true ? bar : baz)' >'foo' : right
+ $* <'print (true ? false ? foo : bar : true ? baz : fox)' >'bar' : both
+ $* <'print (false ? foo ? false ? bar : false : baz : fox)' >'fox' : chain
+}
+
+: short-circuit
+:
+{
+ $* <'print (false ? $bogus() : foo)' >'foo' : middle
+ $* <'print (true ? foo : $bogus())' >'foo' : right
+
+ # @@ TODO: complate pre-parse support in parse_name().
+ #
+ #$* <'print (true ? foo : $out_base/{foo bar})' >'foo' : pre-parse
+}
diff --git a/tests/eval/value.test b/tests/eval/value.test
new file mode 100644
index 0000000..cf91ec1
--- /dev/null
+++ b/tests/eval/value.test
@@ -0,0 +1,23 @@
+# file : tests/eval/value.test
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+# Test value part of the grammar (eval-value).
+
+.include ../common.test
+
+$* <'print (foo)' >'foo' : value
+$* <'print ()' >'' : value-empty
+$* <'print ((foo bar))' >'foo bar' : eval
+$* <'print (!false)' >'true' : not
+$* <'print (!!true)' >'true' : not-double
+
+: attribute
+:
+{
+ $* <'print $type([string] foo)' >'string' : type
+ $* <'print ([uint64] 001)' >'1' : value
+ $* <'print $null([null])' >'true' : null
+ $* <'print $type([string] (foo == bar))' >'string' : eval
+ $* <'print $type([string] !true)' >'string' : not
+}