aboutsummaryrefslogtreecommitdiff
path: root/tests/lang
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lang')
-rw-r--r--tests/lang/eval-okay-arithmetic.exp1
-rw-r--r--tests/lang/eval-okay-arithmetic.nix18
-rw-r--r--tests/lang/eval-okay-flatten.nix15
-rw-r--r--tests/lang/eval-okay-list.nix10
-rw-r--r--tests/lang/eval-okay-map.exp2
-rw-r--r--tests/lang/eval-okay-map.nix4
-rw-r--r--tests/lang/lib.nix18
7 files changed, 45 insertions, 23 deletions
diff --git a/tests/lang/eval-okay-arithmetic.exp b/tests/lang/eval-okay-arithmetic.exp
new file mode 100644
index 000000000..433cb1c9b
--- /dev/null
+++ b/tests/lang/eval-okay-arithmetic.exp
@@ -0,0 +1 @@
+Int(1275)
diff --git a/tests/lang/eval-okay-arithmetic.nix b/tests/lang/eval-okay-arithmetic.nix
new file mode 100644
index 000000000..735f01cf4
--- /dev/null
+++ b/tests/lang/eval-okay-arithmetic.nix
@@ -0,0 +1,18 @@
+with import ./lib.nix;
+
+let {
+
+ range = first: last: [first] ++ (if first == last then [] else range (builtins.add first 1) last);
+
+ /* Supposedly tail recursive version:
+
+ range_ = accum: first: last:
+ if first == last then ([first] ++ accum)
+ else range_ ([first] ++ accum) (builtins.add first 1) last;
+
+ range = range_ [];
+ */
+
+ body = sum (range 1 50);
+
+}
diff --git a/tests/lang/eval-okay-flatten.nix b/tests/lang/eval-okay-flatten.nix
index 2019263b8..fe911e968 100644
--- a/tests/lang/eval-okay-flatten.nix
+++ b/tests/lang/eval-okay-flatten.nix
@@ -1,17 +1,6 @@
-let {
-
- fold = op: nul: list:
- if list == []
- then nul
- else op (builtins.head list) (fold op nul (builtins.tail list));
+with import ./lib.nix;
- concat =
- fold (x: y: x + y) "";
-
- flatten = x:
- if builtins.isList x
- then fold (x: y: (flatten x) ++ y) [] x
- else [x];
+let {
l = ["1" "2" ["3" ["4"] ["5" "6"]] "7"];
diff --git a/tests/lang/eval-okay-list.nix b/tests/lang/eval-okay-list.nix
index 72a120d0d..d433bcf90 100644
--- a/tests/lang/eval-okay-list.nix
+++ b/tests/lang/eval-okay-list.nix
@@ -1,12 +1,6 @@
-let {
-
- fold = op: nul: list:
- if list == []
- then nul
- else op (builtins.head list) (fold op nul (builtins.tail list));
+with import ./lib.nix;
- concat =
- fold (x: y: x + y) "";
+let {
body = concat ["foo" "bar" "bla" "test"];
diff --git a/tests/lang/eval-okay-map.exp b/tests/lang/eval-okay-map.exp
index ab8e7a278..703cb0a30 100644
--- a/tests/lang/eval-okay-map.exp
+++ b/tests/lang/eval-okay-map.exp
@@ -1 +1 @@
-List([Call(Function1("x",OpPlus(Var("x"),Str("bar")),Pos("(string)",1,7)),Str("foo")),Call(Function1("x",OpPlus(Var("x"),Str("bar")),Pos("(string)",1,7)),Str("bla")),Call(Function1("x",OpPlus(Var("x"),Str("bar")),Pos("(string)",1,7)),Str("xyzzy"))])
+Str("foobarblabarxyzzybar")
diff --git a/tests/lang/eval-okay-map.nix b/tests/lang/eval-okay-map.nix
index 924446657..a76c1d811 100644
--- a/tests/lang/eval-okay-map.nix
+++ b/tests/lang/eval-okay-map.nix
@@ -1 +1,3 @@
-map (x: x + "bar") [ "foo" "bla" "xyzzy" ] \ No newline at end of file
+with import ./lib.nix;
+
+concat (map (x: x + "bar") [ "foo" "bla" "xyzzy" ]) \ No newline at end of file
diff --git a/tests/lang/lib.nix b/tests/lang/lib.nix
new file mode 100644
index 000000000..f888453ff
--- /dev/null
+++ b/tests/lang/lib.nix
@@ -0,0 +1,18 @@
+rec {
+
+ fold = op: nul: list:
+ if list == []
+ then nul
+ else op (builtins.head list) (fold op nul (builtins.tail list));
+
+ concat =
+ fold (x: y: x + y) "";
+
+ flatten = x:
+ if builtins.isList x
+ then fold (x: y: (flatten x) ++ y) [] x
+ else [x];
+
+ sum = fold (x: y: builtins.add x y) 0;
+
+}