summary refs log tree commit diff
path: root/lib/tests/misc.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2023-08-14 21:15:54 +0200
committerGitHub <noreply@github.com>2023-08-14 21:15:54 +0200
commit87c5a6a84fcb94fd52507c24bb31c3b844775190 (patch)
tree847a78a99a35e132a81fb6706fa338c23934261f /lib/tests/misc.nix
parent50d11650a71acbead4f84e75b5900680a1edd3f2 (diff)
parent9fdc0bb2bfa2d1dd631bb39f3b9e7cfec16bcd54 (diff)
downloadnixpkgs-87c5a6a84fcb94fd52507c24bb31c3b844775190.tar
nixpkgs-87c5a6a84fcb94fd52507c24bb31c3b844775190.tar.gz
nixpkgs-87c5a6a84fcb94fd52507c24bb31c3b844775190.tar.bz2
nixpkgs-87c5a6a84fcb94fd52507c24bb31c3b844775190.tar.lz
nixpkgs-87c5a6a84fcb94fd52507c24bb31c3b844775190.tar.xz
nixpkgs-87c5a6a84fcb94fd52507c24bb31c3b844775190.tar.zst
nixpkgs-87c5a6a84fcb94fd52507c24bb31c3b844775190.zip
Merge pull request #243511 from tweag/lib.lists.hasPrefix
`lib.lists.{hasPrefix,removePrefix}`: init
Diffstat (limited to 'lib/tests/misc.nix')
-rw-r--r--lib/tests/misc.nix38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index 887ea39a080..dcfa4c540f0 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -492,6 +492,44 @@ runTests {
     ([ 1 2 3 ] == (take 4 [  1 2 3 ]))
   ];
 
+  testListHasPrefixExample1 = {
+    expr = lists.hasPrefix [ 1 2 ] [ 1 2 3 4 ];
+    expected = true;
+  };
+  testListHasPrefixExample2 = {
+    expr = lists.hasPrefix [ 0 1 ] [ 1 2 3 4 ];
+    expected = false;
+  };
+  testListHasPrefixLazy = {
+    expr = lists.hasPrefix [ 1 ] [ 1 (abort "lib.lists.hasPrefix is not lazy") ];
+    expected = true;
+  };
+  testListHasPrefixEmptyPrefix = {
+    expr = lists.hasPrefix [ ] [ 1 2 ];
+    expected = true;
+  };
+  testListHasPrefixEmptyList = {
+    expr = lists.hasPrefix [ 1 2 ] [ ];
+    expected = false;
+  };
+
+  testListRemovePrefixExample1 = {
+    expr = lists.removePrefix [ 1 2 ] [ 1 2 3 4 ];
+    expected = [ 3 4 ];
+  };
+  testListRemovePrefixExample2 = {
+    expr = (builtins.tryEval (lists.removePrefix [ 0 1 ] [ 1 2 3 4 ])).success;
+    expected = false;
+  };
+  testListRemovePrefixEmptyPrefix = {
+    expr = lists.removePrefix [ ] [ 1 2 ];
+    expected = [ 1 2 ];
+  };
+  testListRemovePrefixEmptyList = {
+    expr = (builtins.tryEval (lists.removePrefix [ 1 2 ] [ ])).success;
+    expected = false;
+  };
+
   testFoldAttrs = {
     expr = foldAttrs (n: a: [n] ++ a) [] [
     { a = 2; b = 7; }