aboutsummaryrefslogtreecommitdiffstats
path: root/test/testdata/eval-okay-arithmetic.nix
diff options
context:
space:
mode:
Diffstat (limited to 'test/testdata/eval-okay-arithmetic.nix')
-rw-r--r--test/testdata/eval-okay-arithmetic.nix59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/testdata/eval-okay-arithmetic.nix b/test/testdata/eval-okay-arithmetic.nix
new file mode 100644
index 0000000..7e9e6a0
--- /dev/null
+++ b/test/testdata/eval-okay-arithmetic.nix
@@ -0,0 +1,59 @@
1with import ./lib.nix;
2
3let {
4
5 /* Supposedly tail recursive version:
6
7 range_ = accum: first: last:
8 if first == last then ([first] ++ accum)
9 else range_ ([first] ++ accum) (builtins.add first 1) last;
10
11 range = range_ [];
12 */
13
14 x = 12;
15
16 err = abort "urgh";
17
18 body = sum
19 [ (sum (range 1 50))
20 (123 + 456)
21 (0 + -10 + -(-11) + -x)
22 (10 - 7 - -2)
23 (10 - (6 - -1))
24 (10 - 1 + 2)
25 (3 * 4 * 5)
26 (56088 / 123 / 2)
27 (3 + 4 * const 5 0 - 6 / id 2)
28
29 (builtins.bitAnd 12 10) # 0b1100 & 0b1010 = 8
30 (builtins.bitOr 12 10) # 0b1100 | 0b1010 = 14
31 (builtins.bitXor 12 10) # 0b1100 ^ 0b1010 = 6
32
33 (if 3 < 7 then 1 else err)
34 (if 7 < 3 then err else 1)
35 (if 3 < 3 then err else 1)
36
37 (if 3 <= 7 then 1 else err)
38 (if 7 <= 3 then err else 1)
39 (if 3 <= 3 then 1 else err)
40
41 (if 3 > 7 then err else 1)
42 (if 7 > 3 then 1 else err)
43 (if 3 > 3 then err else 1)
44
45 (if 3 >= 7 then err else 1)
46 (if 7 >= 3 then 1 else err)
47 (if 3 >= 3 then 1 else err)
48
49 (if 2 > 1 == 1 < 2 then 1 else err)
50 (if 1 + 2 * 3 >= 7 then 1 else err)
51 (if 1 + 2 * 3 < 7 then err else 1)
52
53 # Not integer, but so what.
54 (if "aa" < "ab" then 1 else err)
55 (if "aa" < "aa" then err else 1)
56 (if "foo" < "foobar" then 1 else err)
57 ];
58
59}