From 1071643259102ecee344c8161f2ca398cf1266ef Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 23 May 2025 12:15:14 +0200 Subject: [PATCH] tests/functional/lang: Clean up lib.nix That file was written once in 2008 and never updated since, and let's just say that a lot of things have changed since Change-Id: I66b0c87ecbba6ca653470966c9514edb21882ca3 --- tests/functional/lang/eval-okay-attrnames.exp | 2 +- tests/functional/lang/eval-okay-attrnames.nix | 6 +-- tests/functional/lang/eval-okay-autoargs.nix | 2 +- tests/functional/lang/eval-okay-closure.nix | 2 +- tests/functional/lang/eval-okay-flatten.exp | 1 - tests/functional/lang/eval-okay-flatten.nix | 8 ---- tests/functional/lang/eval-okay-list.nix | 4 +- .../functional/lang/eval-okay-listtoattrs.nix | 7 ++-- tests/functional/lang/eval-okay-map.nix | 4 +- tests/functional/lang/lib.nix | 38 +------------------ 10 files changed, 13 insertions(+), 61 deletions(-) delete mode 100644 tests/functional/lang/eval-okay-flatten.exp delete mode 100644 tests/functional/lang/eval-okay-flatten.nix diff --git a/tests/functional/lang/eval-okay-attrnames.exp b/tests/functional/lang/eval-okay-attrnames.exp index b4aa387e0..90aecf200 100644 --- a/tests/functional/lang/eval-okay-attrnames.exp +++ b/tests/functional/lang/eval-okay-attrnames.exp @@ -1 +1 @@ -"newxfoonewxy" +[ "newx" "foo" "newx" "y" ] diff --git a/tests/functional/lang/eval-okay-attrnames.nix b/tests/functional/lang/eval-okay-attrnames.nix index e5b26e9f2..c97b9fa76 100644 --- a/tests/functional/lang/eval-okay-attrnames.nix +++ b/tests/functional/lang/eval-okay-attrnames.nix @@ -1,5 +1,3 @@ -with import ./lib.nix; - let attrs = {y = "y"; x = "x"; foo = "foo";} // rec {x = "newx"; bar = x;}; @@ -8,4 +6,6 @@ let values = map (name: builtins.getAttr name attrs) names; -in assert values == builtins.attrValues attrs; concat values +in +assert values == builtins.attrValues attrs; +values diff --git a/tests/functional/lang/eval-okay-autoargs.nix b/tests/functional/lang/eval-okay-autoargs.nix index 815f51b1d..ff1218527 100644 --- a/tests/functional/lang/eval-okay-autoargs.nix +++ b/tests/functional/lang/eval-okay-autoargs.nix @@ -11,5 +11,5 @@ in }: { - result = lib.concat [xyzzy xyzzy2 fb]; + result = lib.id (builtins.concatStringsSep "" [xyzzy xyzzy2 fb]); } diff --git a/tests/functional/lang/eval-okay-closure.nix b/tests/functional/lang/eval-okay-closure.nix index cccd4dc35..663acdc56 100644 --- a/tests/functional/lang/eval-okay-closure.nix +++ b/tests/functional/lang/eval-okay-closure.nix @@ -8,6 +8,6 @@ let 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); + sort = builtins.sort (a: b: builtins.lessThan a.key b.key); in sort closure diff --git a/tests/functional/lang/eval-okay-flatten.exp b/tests/functional/lang/eval-okay-flatten.exp deleted file mode 100644 index b979b2b8b..000000000 --- a/tests/functional/lang/eval-okay-flatten.exp +++ /dev/null @@ -1 +0,0 @@ -"1234567" diff --git a/tests/functional/lang/eval-okay-flatten.nix b/tests/functional/lang/eval-okay-flatten.nix deleted file mode 100644 index b1fb0f878..000000000 --- a/tests/functional/lang/eval-okay-flatten.nix +++ /dev/null @@ -1,8 +0,0 @@ -with import ./lib.nix; - -let - - l = ["1" "2" ["3" ["4"] ["5" "6"]] "7"]; - -in -concat (flatten l) diff --git a/tests/functional/lang/eval-okay-list.nix b/tests/functional/lang/eval-okay-list.nix index eb6e60f23..627c37311 100644 --- a/tests/functional/lang/eval-okay-list.nix +++ b/tests/functional/lang/eval-okay-list.nix @@ -1,3 +1 @@ -with import ./lib.nix; - -concat ["foo" "bar" "bla" "test"] +builtins.concatStringsSep "" ["foo" "bar" "bla" "test"] diff --git a/tests/functional/lang/eval-okay-listtoattrs.nix b/tests/functional/lang/eval-okay-listtoattrs.nix index 4186e029b..53b9a0e96 100644 --- a/tests/functional/lang/eval-okay-listtoattrs.nix +++ b/tests/functional/lang/eval-okay-listtoattrs.nix @@ -1,11 +1,10 @@ # this test shows how to use listToAttrs and that evaluation is still lazy (throw isn't called) -with import ./lib.nix; - -let +let asi = name: value : { inherit name value; }; list = [ ( asi "a" "A" ) ( asi "b" "B" ) ]; a = builtins.listToAttrs list; b = builtins.listToAttrs ( list ++ list ); r = builtins.listToAttrs [ (asi "result" [ a b ]) ( asi "throw" (throw "this should not be thrown")) ]; x = builtins.listToAttrs [ (asi "foo" "bar") (asi "foo" "bla") ]; -in concat (map (x: x.a) r.result) + x.foo +in +builtins.concatStringsSep "" (map (x: x.a) r.result) + x.foo diff --git a/tests/functional/lang/eval-okay-map.nix b/tests/functional/lang/eval-okay-map.nix index a76c1d811..e5bbf1ce5 100644 --- a/tests/functional/lang/eval-okay-map.nix +++ b/tests/functional/lang/eval-okay-map.nix @@ -1,3 +1 @@ -with import ./lib.nix; - -concat (map (x: x + "bar") [ "foo" "bla" "xyzzy" ]) \ No newline at end of file +builtins.concatStringsSep "" (map (x: x + "bar") [ "foo" "bla" "xyzzy" ]) diff --git a/tests/functional/lang/lib.nix b/tests/functional/lang/lib.nix index 028a53831..71369da45 100644 --- a/tests/functional/lang/lib.nix +++ b/tests/functional/lang/lib.nix @@ -7,15 +7,7 @@ rec { then nul else op (head list) (fold op nul (tail list)); - concat = - fold (x: y: x + y) ""; - - and = fold (x: y: x && y) true; - - flatten = x: - if isList x - then fold (x: y: (flatten x) ++ y) [] x - else [x]; + and = all id; sum = foldl' (x: y: add x y) 0; @@ -23,33 +15,7 @@ rec { let lenFileName = stringLength fileName; lenExt = stringLength ext; 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; - - id = x: x; + substring (sub lenFileName lenExt) lenFileName fileName == ext; id = x: x; const = x: y: x;