diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-12-03 11:04:48 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-12-03 11:08:08 +0200 |
commit | 772b1e013bb0068d7347d0bbe2ff73c67358ee1b (patch) | |
tree | 8d7bdd8999ed62db77015e60d6115eb6ff235912 /tests | |
parent | becea217436a79b7ef37a023da6cb4c560225a71 (diff) |
Implement if-else conditions
if
if!
elif
elif!
else
The expression should evaluate to true of false. The if! and elif!
versions are provided as shortcuts to writing if (!...).
See tests/if-else for examples.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/if-else/buildfile | 114 | ||||
-rw-r--r-- | tests/if-else/test.out | 9 | ||||
-rwxr-xr-x | tests/if-else/test.sh | 3 |
3 files changed, 126 insertions, 0 deletions
diff --git a/tests/if-else/buildfile b/tests/if-else/buildfile new file mode 100644 index 0000000..30da40f --- /dev/null +++ b/tests/if-else/buildfile @@ -0,0 +1,114 @@ +#else # else without if +#elif # elif without if +#elif! # elif! without if +#if # expected if-expression +#if test # expected true or false +#if true # expected { +#x +#if true # expected newline after { +#{x +#if true # expected newline after } +#{ +#}x + +if true +{ + print 1 +} +else +{ + print 0 +} + +if! true +{ + print 0 +} +else +{ + print 1 +} + +if false +{ + print 0 +} +else +{ + print 1 +} + +if false +{ + print 0 +} +elif true +{ + print 1 +} +else +{ + print 0 +} + +if true +{ + print 1 +} +elif true +{ + print 0 +} +else +{ + print 0 +} + +# Empty block +# +if true +{ +} +else +{ + print 0 +} + +# Nested if-else +# +if true +{ + if true + { + print 1 + } +} +else +{ + if true + { + print 0 + } +} + +t = true +f = false + +if $t +{ + print 1 +} + +if! $f +{ + print 1 +} + +./: + +# EOF test. +# +if true +{ + print 1 +} diff --git a/tests/if-else/test.out b/tests/if-else/test.out new file mode 100644 index 0000000..bb08505 --- /dev/null +++ b/tests/if-else/test.out @@ -0,0 +1,9 @@ +1 +1 +1 +1 +1 +1 +1 +1 +1 diff --git a/tests/if-else/test.sh b/tests/if-else/test.sh new file mode 100755 index 0000000..b898b3c --- /dev/null +++ b/tests/if-else/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +valgrind -q b -q | diff -u test.out - |