aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-07-11 13:29:04 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-07-11 13:29:04 +0000
commit7cd88b1dec29f33188e789d780ec2e4ebb155d20 (patch)
treec2a3934a763e6968af7fce554a5840516fa6208e /tests
parentd567baabbd99fdb92e67295a77aef76ef970e65c (diff)
* Generalised the dependencyClosure primop to builtins.genericClosure,
which is hopefully more useful. * New primops: length, mul, div.
Diffstat (limited to 'tests')
-rw-r--r--tests/lang/eval-okay-closure.exp.xml343
-rw-r--r--tests/lang/eval-okay-closure.nix13
-rw-r--r--tests/lang/lib.nix24
3 files changed, 380 insertions, 0 deletions
diff --git a/tests/lang/eval-okay-closure.exp.xml b/tests/lang/eval-okay-closure.exp.xml
new file mode 100644
index 000000000..dffc03a99
--- /dev/null
+++ b/tests/lang/eval-okay-closure.exp.xml
@@ -0,0 +1,343 @@
+<?xml version='1.0' encoding='utf-8'?>
+<expr>
+ <list>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="-13" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="-12" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="-11" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="-9" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="-8" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="-7" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="-5" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="-4" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="-3" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="-1" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="0" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="1" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="2" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="4" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="5" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="6" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="8" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="9" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="10" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="13" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="14" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="15" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="17" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="18" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="19" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="22" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="23" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="26" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="27" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="28" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="31" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="32" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="35" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="36" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="40" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="41" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="44" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="45" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="49" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="53" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="54" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="58" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="62" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="foo">
+ <bool value="true" />
+ </attr>
+ <attr name="key">
+ <int value="67" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="71" />
+ </attr>
+ </attrs>
+ <attrs>
+ <attr name="key">
+ <int value="80" />
+ </attr>
+ </attrs>
+ </list>
+</expr>
diff --git a/tests/lang/eval-okay-closure.nix b/tests/lang/eval-okay-closure.nix
new file mode 100644
index 000000000..cccd4dc35
--- /dev/null
+++ b/tests/lang/eval-okay-closure.nix
@@ -0,0 +1,13 @@
+let
+
+ closure = builtins.genericClosure {
+ startSet = [{key = 80;}];
+ operator = {key, foo ? false}:
+ if builtins.lessThan key 0
+ then []
+ else [{key = builtins.sub key 9;} {key = builtins.sub key 13; foo = true;}];
+ };
+
+ sort = (import ./lib.nix).sortBy (a: b: builtins.lessThan a.key b.key);
+
+in sort closure
diff --git a/tests/lang/lib.nix b/tests/lang/lib.nix
index e508f28ba..551b67aed 100644
--- a/tests/lang/lib.nix
+++ b/tests/lang/lib.nix
@@ -25,4 +25,28 @@ rec {
in !(lessThan lenFileName lenExt) &&
substring (sub lenFileName lenExt) lenFileName fileName == ext;
+ # Split a list at the given position.
+ splitAt = pos: list:
+ if pos == 0 then {first = []; second = list;} else
+ if list == [] then {first = []; second = [];} else
+ let res = splitAt (sub pos 1) (tail list);
+ in {first = [(head list)] ++ res.first; second = res.second;};
+
+ # Stable merge sort.
+ sortBy = comp: list:
+ if lessThan 1 (length list)
+ then
+ let
+ split = splitAt (div (length list) 2) list;
+ first = sortBy comp split.first;
+ second = sortBy comp split.second;
+ in mergeLists comp first second
+ else list;
+
+ mergeLists = comp: list1: list2:
+ if list1 == [] then list2 else
+ if list2 == [] then list1 else
+ if comp (head list2) (head list1) then [(head list2)] ++ mergeLists comp list1 (tail list2) else
+ [(head list1)] ++ mergeLists comp (tail list1) list2;
+
}