diff options
author | Rutger Broekhoff | 2025-07-07 21:52:08 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2025-07-07 21:52:08 +0200 |
commit | ba61dfd69504ec6263a9dee9931d93adeb6f3142 (patch) | |
tree | d6c9b78e50eeab24e0c1c09ab45909a6ae3fd5db /test/testdata/eval-okay-arithmetic.nix | |
download | verified-dyn-lang-interp-ba61dfd69504ec6263a9dee9931d93adeb6f3142.tar.gz verified-dyn-lang-interp-ba61dfd69504ec6263a9dee9931d93adeb6f3142.zip |
Initialize repository
Diffstat (limited to 'test/testdata/eval-okay-arithmetic.nix')
-rw-r--r-- | test/testdata/eval-okay-arithmetic.nix | 59 |
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 @@ | |||
1 | with import ./lib.nix; | ||
2 | |||
3 | let { | ||
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 | } | ||