2017-03-18 22:41:02 +03:00
|
|
|
# to run these tests:
|
2017-04-25 03:12:43 +03:00
|
|
|
# nix-instantiate --eval --strict nixpkgs/lib/tests/misc.nix
|
2017-03-18 22:41:02 +03:00
|
|
|
# if the resulting list is empty, all tests passed
|
2017-04-25 03:12:43 +03:00
|
|
|
with import ../default.nix;
|
2009-03-07 02:21:17 +03:00
|
|
|
|
2020-01-28 01:03:38 +03:00
|
|
|
let
|
|
|
|
|
|
|
|
testSanitizeDerivationName = { name, expected }:
|
|
|
|
let
|
|
|
|
drv = derivation {
|
|
|
|
name = strings.sanitizeDerivationName name;
|
|
|
|
builder = "x";
|
|
|
|
system = "x";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
# Evaluate the derivation so an invalid name would be caught
|
|
|
|
expr = builtins.seq drv.drvPath drv.name;
|
|
|
|
inherit expected;
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2009-03-31 17:03:50 +04:00
|
|
|
runTests {
|
2009-03-07 02:21:17 +03:00
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
# TRIVIAL
|
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testId = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = id 1;
|
|
|
|
expected = 1;
|
|
|
|
};
|
2015-11-24 12:00:44 +03:00
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testConst = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = const 2 3;
|
|
|
|
expected = 2;
|
|
|
|
};
|
2012-05-13 23:10:57 +04:00
|
|
|
|
2019-10-18 18:57:33 +03:00
|
|
|
testPipe = {
|
|
|
|
expr = pipe 2 [
|
|
|
|
(x: x + 2) # 2 + 2 = 4
|
|
|
|
(x: x * 2) # 4 * 2 = 8
|
|
|
|
];
|
|
|
|
expected = 8;
|
|
|
|
};
|
|
|
|
|
|
|
|
testPipeEmpty = {
|
|
|
|
expr = pipe 2 [];
|
|
|
|
expected = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
testPipeStrings = {
|
|
|
|
expr = pipe [ 3 4 ] [
|
|
|
|
(map toString)
|
|
|
|
(map (s: s + "\n"))
|
|
|
|
concatStrings
|
|
|
|
];
|
|
|
|
expected = ''
|
|
|
|
3
|
|
|
|
4
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2012-05-13 23:10:57 +04:00
|
|
|
/*
|
2009-11-23 00:28:41 +03:00
|
|
|
testOr = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = or true false;
|
|
|
|
expected = true;
|
|
|
|
};
|
2012-05-13 23:10:57 +04:00
|
|
|
*/
|
2015-11-24 12:00:44 +03:00
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testAnd = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = and true false;
|
|
|
|
expected = false;
|
|
|
|
};
|
2015-11-24 12:00:44 +03:00
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testFix = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = fix (x: {a = if x ? a then "a" else "b";});
|
|
|
|
expected = {a = "a";};
|
|
|
|
};
|
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
testComposeExtensions = {
|
|
|
|
expr = let obj = makeExtensible (self: { foo = self.bar; });
|
|
|
|
f = self: super: { bar = false; baz = true; };
|
|
|
|
g = self: super: { bar = super.baz or false; };
|
|
|
|
f_o_g = composeExtensions f g;
|
|
|
|
composed = obj.extend f_o_g;
|
|
|
|
in composed.foo;
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
2020-11-11 05:36:19 +03:00
|
|
|
testComposeManyExtensions0 = {
|
|
|
|
expr = let obj = makeExtensible (self: { foo = true; });
|
|
|
|
emptyComposition = composeManyExtensions [];
|
|
|
|
composed = obj.extend emptyComposition;
|
|
|
|
in composed.foo;
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testComposeManyExtensions =
|
|
|
|
let f = self: super: { bar = false; baz = true; };
|
|
|
|
g = self: super: { bar = super.baz or false; };
|
|
|
|
h = self: super: { qux = super.bar or false; };
|
|
|
|
obj = makeExtensible (self: { foo = self.qux; });
|
|
|
|
in {
|
|
|
|
expr = let composition = composeManyExtensions [f g h];
|
|
|
|
composed = obj.extend composition;
|
|
|
|
in composed.foo;
|
|
|
|
expected = (obj.extend (composeExtensions f (composeExtensions g h))).foo;
|
|
|
|
};
|
|
|
|
|
2018-06-10 22:25:48 +03:00
|
|
|
testBitAnd = {
|
|
|
|
expr = (bitAnd 3 10);
|
|
|
|
expected = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
testBitOr = {
|
|
|
|
expr = (bitOr 3 10);
|
|
|
|
expected = 11;
|
|
|
|
};
|
|
|
|
|
|
|
|
testBitXor = {
|
|
|
|
expr = (bitXor 3 10);
|
|
|
|
expected = 9;
|
|
|
|
};
|
|
|
|
|
2020-07-20 14:14:19 +03:00
|
|
|
testToHexString = {
|
|
|
|
expr = toHexString 250;
|
2020-04-20 13:00:23 +03:00
|
|
|
expected = "FA";
|
|
|
|
};
|
|
|
|
|
2020-07-20 14:14:19 +03:00
|
|
|
testToBaseDigits = {
|
|
|
|
expr = toBaseDigits 2 6;
|
2020-04-20 13:00:23 +03:00
|
|
|
expected = [ 1 1 0 ];
|
|
|
|
};
|
|
|
|
|
2021-07-23 22:10:31 +03:00
|
|
|
testFunctionArgsFunctor = {
|
|
|
|
expr = functionArgs { __functor = self: { a, b }: null; };
|
|
|
|
expected = { a = false; b = false; };
|
|
|
|
};
|
|
|
|
|
|
|
|
testFunctionArgsSetFunctionArgs = {
|
|
|
|
expr = functionArgs (setFunctionArgs (args: args.x) { x = false; });
|
|
|
|
expected = { x = false; };
|
|
|
|
};
|
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
# STRINGS
|
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testConcatMapStrings = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = concatMapStrings (x: x + ";") ["a" "b" "c"];
|
|
|
|
expected = "a;b;c;";
|
|
|
|
};
|
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testConcatStringsSep = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = concatStringsSep "," ["a" "b" "c"];
|
|
|
|
expected = "a,b,c";
|
|
|
|
};
|
|
|
|
|
2022-12-10 17:56:30 +03:00
|
|
|
testConcatLines = {
|
|
|
|
expr = concatLines ["a" "b" "c"];
|
|
|
|
expected = "a\nb\nc\n";
|
|
|
|
};
|
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
testSplitStringsSimple = {
|
|
|
|
expr = strings.splitString "." "a.b.c.d";
|
|
|
|
expected = [ "a" "b" "c" "d" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsEmpty = {
|
|
|
|
expr = strings.splitString "." "a..b";
|
|
|
|
expected = [ "a" "" "b" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsOne = {
|
|
|
|
expr = strings.splitString ":" "a.b";
|
|
|
|
expected = [ "a.b" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsNone = {
|
|
|
|
expr = strings.splitString "." "";
|
|
|
|
expected = [ "" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsFirstEmpty = {
|
|
|
|
expr = strings.splitString "/" "/a/b/c";
|
|
|
|
expected = [ "" "a" "b" "c" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsLastEmpty = {
|
|
|
|
expr = strings.splitString ":" "2001:db8:0:0042::8a2e:370:";
|
|
|
|
expected = [ "2001" "db8" "0" "0042" "" "8a2e" "370" "" ];
|
|
|
|
};
|
2019-09-24 12:27:14 +03:00
|
|
|
|
2020-10-18 13:15:40 +03:00
|
|
|
testSplitStringsRegex = {
|
|
|
|
expr = strings.splitString "\\[{}]()^$?*+|." "A\\[{}]()^$?*+|.B";
|
|
|
|
expected = [ "A" "B" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitStringsDerivation = {
|
|
|
|
expr = take 3 (strings.splitString "/" (derivation {
|
|
|
|
name = "name";
|
|
|
|
builder = "builder";
|
|
|
|
system = "system";
|
|
|
|
}));
|
|
|
|
expected = ["" "nix" "store"];
|
|
|
|
};
|
|
|
|
|
2019-09-24 12:27:14 +03:00
|
|
|
testSplitVersionSingle = {
|
|
|
|
expr = versions.splitVersion "1";
|
|
|
|
expected = [ "1" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitVersionDouble = {
|
|
|
|
expr = versions.splitVersion "1.2";
|
|
|
|
expected = [ "1" "2" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testSplitVersionTriple = {
|
|
|
|
expr = versions.splitVersion "1.2.3";
|
|
|
|
expected = [ "1" "2" "3" ];
|
|
|
|
};
|
2017-04-12 01:43:52 +03:00
|
|
|
|
2022-12-20 20:38:47 +03:00
|
|
|
testPadVersionLess = {
|
|
|
|
expr = versions.pad 3 "1.2";
|
|
|
|
expected = "1.2.0";
|
|
|
|
};
|
|
|
|
|
|
|
|
testPadVersionLessExtra = {
|
|
|
|
expr = versions.pad 3 "1.3-rc1";
|
|
|
|
expected = "1.3.0-rc1";
|
|
|
|
};
|
|
|
|
|
|
|
|
testPadVersionMore = {
|
|
|
|
expr = versions.pad 3 "1.2.3.4";
|
|
|
|
expected = "1.2.3";
|
|
|
|
};
|
|
|
|
|
2017-05-30 22:48:32 +03:00
|
|
|
testIsStorePath = {
|
|
|
|
expr =
|
|
|
|
let goodPath =
|
2017-06-10 00:30:10 +03:00
|
|
|
"${builtins.storeDir}/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11";
|
2017-05-30 22:48:32 +03:00
|
|
|
in {
|
|
|
|
storePath = isStorePath goodPath;
|
2020-02-10 18:20:41 +03:00
|
|
|
storePathDerivation = isStorePath (import ../.. { system = "x86_64-linux"; }).hello;
|
2017-05-30 22:48:32 +03:00
|
|
|
storePathAppendix = isStorePath
|
|
|
|
"${goodPath}/bin/python";
|
|
|
|
nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath)));
|
2018-10-20 14:23:58 +03:00
|
|
|
asPath = isStorePath (/. + goodPath);
|
2017-05-30 22:48:32 +03:00
|
|
|
otherPath = isStorePath "/something/else";
|
|
|
|
otherVals = {
|
|
|
|
attrset = isStorePath {};
|
|
|
|
list = isStorePath [];
|
|
|
|
int = isStorePath 42;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
storePath = true;
|
2018-03-10 01:21:12 +03:00
|
|
|
storePathDerivation = true;
|
2017-05-30 22:48:32 +03:00
|
|
|
storePathAppendix = false;
|
|
|
|
nonAbsolute = false;
|
|
|
|
asPath = true;
|
|
|
|
otherPath = false;
|
|
|
|
otherVals = {
|
|
|
|
attrset = false;
|
|
|
|
list = false;
|
|
|
|
int = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-10-03 12:28:03 +03:00
|
|
|
testEscapeXML = {
|
|
|
|
expr = escapeXML ''"test" 'test' < & >'';
|
|
|
|
expected = ""test" 'test' < & >";
|
|
|
|
};
|
|
|
|
|
2022-04-27 11:02:49 +03:00
|
|
|
testToShellVars = {
|
|
|
|
expr = ''
|
|
|
|
${toShellVars {
|
|
|
|
STRing01 = "just a 'string'";
|
|
|
|
_array_ = [ "with" "more strings" ];
|
|
|
|
assoc."with some" = ''
|
|
|
|
strings
|
|
|
|
possibly newlines
|
|
|
|
'';
|
2022-05-07 14:37:03 +03:00
|
|
|
drv = {
|
|
|
|
outPath = "/drv";
|
|
|
|
foo = "ignored attribute";
|
|
|
|
};
|
|
|
|
path = /path;
|
|
|
|
stringable = {
|
|
|
|
__toString = _: "hello toString";
|
|
|
|
bar = "ignored attribute";
|
|
|
|
};
|
2022-04-27 11:02:49 +03:00
|
|
|
}}
|
|
|
|
'';
|
|
|
|
expected = ''
|
|
|
|
STRing01='just a '\'''string'\''''
|
|
|
|
declare -a _array_=('with' 'more strings')
|
|
|
|
declare -A assoc=(['with some']='strings
|
|
|
|
possibly newlines
|
|
|
|
')
|
2022-05-07 14:37:03 +03:00
|
|
|
drv='/drv'
|
|
|
|
path='/path'
|
|
|
|
stringable='hello toString'
|
2022-04-27 11:02:49 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-04-27 09:58:20 +03:00
|
|
|
testHasInfixFalse = {
|
|
|
|
expr = hasInfix "c" "abde";
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
testHasInfixTrue = {
|
|
|
|
expr = hasInfix "c" "abcde";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testHasInfixDerivation = {
|
|
|
|
expr = hasInfix "hello" (import ../.. { system = "x86_64-linux"; }).hello;
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testHasInfixPath = {
|
|
|
|
expr = hasInfix "tests" ./.;
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testHasInfixPathStoreDir = {
|
|
|
|
expr = hasInfix builtins.storeDir ./.;
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testHasInfixToString = {
|
|
|
|
expr = hasInfix "a" { __toString = _: "a"; };
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
2022-06-23 23:46:23 +03:00
|
|
|
testNormalizePath = {
|
|
|
|
expr = strings.normalizePath "//a/b//c////d/";
|
|
|
|
expected = "/a/b/c/d/";
|
|
|
|
};
|
|
|
|
|
|
|
|
testCharToInt = {
|
|
|
|
expr = strings.charToInt "A";
|
|
|
|
expected = 65;
|
|
|
|
};
|
|
|
|
|
|
|
|
testEscapeC = {
|
|
|
|
expr = strings.escapeC [ " " ] "Hello World";
|
|
|
|
expected = "Hello\\x20World";
|
|
|
|
};
|
|
|
|
|
2023-03-02 23:41:51 +03:00
|
|
|
testEscapeURL = testAllTrue [
|
|
|
|
("" == strings.escapeURL "")
|
|
|
|
("Hello" == strings.escapeURL "Hello")
|
|
|
|
("Hello%20World" == strings.escapeURL "Hello World")
|
|
|
|
("Hello%2FWorld" == strings.escapeURL "Hello/World")
|
|
|
|
("42%25" == strings.escapeURL "42%")
|
|
|
|
("%20%3F%26%3D%23%2B%25%21%3C%3E%23%22%7B%7D%7C%5C%5E%5B%5D%60%09%3A%2F%40%24%27%28%29%2A%2C%3B" == strings.escapeURL " ?&=#+%!<>#\"{}|\\^[]`\t:/@$'()*,;")
|
|
|
|
];
|
|
|
|
|
2022-05-22 05:34:11 +03:00
|
|
|
testToInt = testAllTrue [
|
|
|
|
# Naive
|
|
|
|
(123 == toInt "123")
|
|
|
|
(0 == toInt "0")
|
|
|
|
# Whitespace Padding
|
|
|
|
(123 == toInt " 123")
|
|
|
|
(123 == toInt "123 ")
|
|
|
|
(123 == toInt " 123 ")
|
|
|
|
(123 == toInt " 123 ")
|
|
|
|
(0 == toInt " 0")
|
|
|
|
(0 == toInt "0 ")
|
|
|
|
(0 == toInt " 0 ")
|
2022-12-10 15:02:40 +03:00
|
|
|
(-1 == toInt "-1")
|
|
|
|
(-1 == toInt " -1 ")
|
2022-05-22 05:34:11 +03:00
|
|
|
];
|
|
|
|
|
2022-05-23 10:39:48 +03:00
|
|
|
testToIntFails = testAllTrue [
|
|
|
|
( builtins.tryEval (toInt "") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toInt "123 123") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toInt "0 123") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toInt " 0d ") == { success = false; value = false; } )
|
2022-07-10 03:12:31 +03:00
|
|
|
( builtins.tryEval (toInt " 1d ") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toInt " d0 ") == { success = false; value = false; } )
|
2022-07-09 02:37:45 +03:00
|
|
|
( builtins.tryEval (toInt "00") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toInt "01") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toInt "002") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toInt " 002 ") == { success = false; value = false; } )
|
2022-05-23 10:39:48 +03:00
|
|
|
( builtins.tryEval (toInt " foo ") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toInt " foo 123 ") == { success = false; value = false; } )
|
2022-07-09 02:37:45 +03:00
|
|
|
( builtins.tryEval (toInt " foo123 ") == { success = false; value = false; } )
|
|
|
|
];
|
|
|
|
|
|
|
|
testToIntBase10 = testAllTrue [
|
|
|
|
# Naive
|
|
|
|
(123 == toIntBase10 "123")
|
|
|
|
(0 == toIntBase10 "0")
|
|
|
|
# Whitespace Padding
|
|
|
|
(123 == toIntBase10 " 123")
|
|
|
|
(123 == toIntBase10 "123 ")
|
|
|
|
(123 == toIntBase10 " 123 ")
|
|
|
|
(123 == toIntBase10 " 123 ")
|
|
|
|
(0 == toIntBase10 " 0")
|
|
|
|
(0 == toIntBase10 "0 ")
|
|
|
|
(0 == toIntBase10 " 0 ")
|
|
|
|
# Zero Padding
|
|
|
|
(123 == toIntBase10 "0123")
|
|
|
|
(123 == toIntBase10 "0000123")
|
|
|
|
(0 == toIntBase10 "000000")
|
|
|
|
# Whitespace and Zero Padding
|
|
|
|
(123 == toIntBase10 " 0123")
|
|
|
|
(123 == toIntBase10 "0123 ")
|
|
|
|
(123 == toIntBase10 " 0123 ")
|
|
|
|
(123 == toIntBase10 " 0000123")
|
|
|
|
(123 == toIntBase10 "0000123 ")
|
|
|
|
(123 == toIntBase10 " 0000123 ")
|
|
|
|
(0 == toIntBase10 " 000000")
|
|
|
|
(0 == toIntBase10 "000000 ")
|
|
|
|
(0 == toIntBase10 " 000000 ")
|
2022-12-10 15:02:40 +03:00
|
|
|
(-1 == toIntBase10 "-1")
|
|
|
|
(-1 == toIntBase10 " -1 ")
|
2022-07-09 02:37:45 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
testToIntBase10Fails = testAllTrue [
|
|
|
|
( builtins.tryEval (toIntBase10 "") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toIntBase10 "123 123") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toIntBase10 "0 123") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toIntBase10 " 0d ") == { success = false; value = false; } )
|
2022-07-10 03:12:31 +03:00
|
|
|
( builtins.tryEval (toIntBase10 " 1d ") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toIntBase10 " d0 ") == { success = false; value = false; } )
|
2022-07-09 02:37:45 +03:00
|
|
|
( builtins.tryEval (toIntBase10 " foo ") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toIntBase10 " foo 123 ") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toIntBase10 " foo 00123 ") == { success = false; value = false; } )
|
|
|
|
( builtins.tryEval (toIntBase10 " foo00123 ") == { success = false; value = false; } )
|
2022-05-23 10:39:48 +03:00
|
|
|
];
|
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
# LISTS
|
|
|
|
|
2009-11-23 00:28:41 +03:00
|
|
|
testFilter = {
|
2009-03-31 17:03:50 +04:00
|
|
|
expr = filter (x: x != "a") ["a" "b" "c" "a"];
|
|
|
|
expected = ["b" "c"];
|
|
|
|
};
|
|
|
|
|
2017-03-18 22:41:02 +03:00
|
|
|
testFold =
|
|
|
|
let
|
|
|
|
f = op: fold: fold op 0 (range 0 100);
|
|
|
|
# fold with associative operator
|
|
|
|
assoc = f builtins.add;
|
|
|
|
# fold with non-associative operator
|
|
|
|
nonAssoc = f builtins.sub;
|
|
|
|
in {
|
|
|
|
expr = {
|
|
|
|
assocRight = assoc foldr;
|
|
|
|
# right fold with assoc operator is same as left fold
|
|
|
|
assocRightIsLeft = assoc foldr == assoc foldl;
|
|
|
|
nonAssocRight = nonAssoc foldr;
|
|
|
|
nonAssocLeft = nonAssoc foldl;
|
|
|
|
# with non-assoc operator the fold results are not the same
|
|
|
|
nonAssocRightIsNotLeft = nonAssoc foldl != nonAssoc foldr;
|
|
|
|
# fold is an alias for foldr
|
|
|
|
foldIsRight = nonAssoc fold == nonAssoc foldr;
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
assocRight = 5050;
|
|
|
|
assocRightIsLeft = true;
|
|
|
|
nonAssocRight = 50;
|
|
|
|
nonAssocLeft = (-5050);
|
|
|
|
nonAssocRightIsNotLeft = true;
|
|
|
|
foldIsRight = true;
|
|
|
|
};
|
|
|
|
};
|
2009-03-31 17:03:50 +04:00
|
|
|
|
2009-12-09 00:47:14 +03:00
|
|
|
testTake = testAllTrue [
|
|
|
|
([] == (take 0 [ 1 2 3 ]))
|
|
|
|
([1] == (take 1 [ 1 2 3 ]))
|
|
|
|
([ 1 2 ] == (take 2 [ 1 2 3 ]))
|
|
|
|
([ 1 2 3 ] == (take 3 [ 1 2 3 ]))
|
|
|
|
([ 1 2 3 ] == (take 4 [ 1 2 3 ]))
|
|
|
|
];
|
|
|
|
|
2012-08-28 16:40:24 +04:00
|
|
|
testFoldAttrs = {
|
|
|
|
expr = foldAttrs (n: a: [n] ++ a) [] [
|
|
|
|
{ a = 2; b = 7; }
|
|
|
|
{ a = 3; c = 8; }
|
|
|
|
];
|
|
|
|
expected = { a = [ 2 3 ]; b = [7]; c = [8];};
|
|
|
|
};
|
2009-12-09 00:47:14 +03:00
|
|
|
|
2012-11-20 16:54:38 +04:00
|
|
|
testSort = {
|
|
|
|
expr = sort builtins.lessThan [ 40 2 30 42 ];
|
|
|
|
expected = [2 30 40 42];
|
|
|
|
};
|
2015-11-24 12:00:44 +03:00
|
|
|
|
2022-12-17 23:57:17 +03:00
|
|
|
testReplicate = {
|
|
|
|
expr = replicate 3 "a";
|
|
|
|
expected = ["a" "a" "a"];
|
|
|
|
};
|
|
|
|
|
2015-11-24 12:00:44 +03:00
|
|
|
testToIntShouldConvertStringToInt = {
|
|
|
|
expr = toInt "27";
|
|
|
|
expected = 27;
|
|
|
|
};
|
|
|
|
|
|
|
|
testToIntShouldThrowErrorIfItCouldNotConvertToInt = {
|
|
|
|
expr = builtins.tryEval (toInt "\"foo\"");
|
|
|
|
expected = { success = false; value = false; };
|
|
|
|
};
|
|
|
|
|
2015-12-04 18:17:45 +03:00
|
|
|
testHasAttrByPathTrue = {
|
|
|
|
expr = hasAttrByPath ["a" "b"] { a = { b = "yey"; }; };
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testHasAttrByPathFalse = {
|
|
|
|
expr = hasAttrByPath ["a" "b"] { a = { c = "yey"; }; };
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
2016-11-06 03:51:13 +03:00
|
|
|
|
2018-08-15 01:13:32 +03:00
|
|
|
# ATTRSETS
|
|
|
|
|
2022-11-16 20:20:38 +03:00
|
|
|
testConcatMapAttrs = {
|
|
|
|
expr = concatMapAttrs
|
|
|
|
(name: value: {
|
|
|
|
${name} = value;
|
|
|
|
${name + value} = value;
|
|
|
|
})
|
|
|
|
{
|
|
|
|
foo = "bar";
|
|
|
|
foobar = "baz";
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
foo = "bar";
|
|
|
|
foobar = "baz";
|
|
|
|
foobarbaz = "baz";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-28 13:04:19 +03:00
|
|
|
# code from example
|
|
|
|
testFoldlAttrs = {
|
|
|
|
expr = {
|
|
|
|
example = foldlAttrs
|
|
|
|
(acc: name: value: {
|
|
|
|
sum = acc.sum + value;
|
|
|
|
names = acc.names ++ [ name ];
|
|
|
|
})
|
|
|
|
{ sum = 0; names = [ ]; }
|
|
|
|
{
|
|
|
|
foo = 1;
|
|
|
|
bar = 10;
|
|
|
|
};
|
|
|
|
# should just return the initial value
|
|
|
|
emptySet = foldlAttrs (throw "function not needed") 123 { };
|
|
|
|
# should just evaluate to the last value
|
|
|
|
accNotNeeded = foldlAttrs (_acc: _name: v: v) (throw "accumulator not needed") { z = 3; a = 2; };
|
|
|
|
# the accumulator doesnt have to be an attrset it can be as trivial as being just a number or string
|
|
|
|
trivialAcc = foldlAttrs (acc: _name: v: acc * 10 + v) 1 { z = 1; a = 2; };
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
example = {
|
|
|
|
sum = 11;
|
|
|
|
names = [ "bar" "foo" ];
|
|
|
|
};
|
|
|
|
emptySet = 123;
|
|
|
|
accNotNeeded = 3;
|
|
|
|
trivialAcc = 121;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-08-15 01:13:32 +03:00
|
|
|
# code from the example
|
|
|
|
testRecursiveUpdateUntil = {
|
|
|
|
expr = recursiveUpdateUntil (path: l: r: path == ["foo"]) {
|
|
|
|
# first attribute set
|
|
|
|
foo.bar = 1;
|
|
|
|
foo.baz = 2;
|
|
|
|
bar = 3;
|
|
|
|
} {
|
|
|
|
#second attribute set
|
|
|
|
foo.bar = 1;
|
|
|
|
foo.quz = 2;
|
|
|
|
baz = 4;
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
foo.bar = 1; # 'foo.*' from the second set
|
|
|
|
foo.quz = 2; #
|
|
|
|
bar = 3; # 'bar' from the first set
|
|
|
|
baz = 4; # 'baz' from the second set
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-09-17 23:40:08 +03:00
|
|
|
testOverrideExistingEmpty = {
|
|
|
|
expr = overrideExisting {} { a = 1; };
|
|
|
|
expected = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
testOverrideExistingDisjoint = {
|
|
|
|
expr = overrideExisting { b = 2; } { a = 1; };
|
|
|
|
expected = { b = 2; };
|
|
|
|
};
|
|
|
|
|
|
|
|
testOverrideExistingOverride = {
|
|
|
|
expr = overrideExisting { a = 3; b = 2; } { a = 1; };
|
|
|
|
expected = { a = 1; b = 2; };
|
|
|
|
};
|
2018-08-15 01:13:32 +03:00
|
|
|
|
2017-04-12 01:43:52 +03:00
|
|
|
# GENERATORS
|
|
|
|
# these tests assume attributes are converted to lists
|
|
|
|
# in alphabetical order
|
2016-11-06 03:51:13 +03:00
|
|
|
|
2016-12-07 01:19:34 +03:00
|
|
|
testMkKeyValueDefault = {
|
2017-11-09 17:58:14 +03:00
|
|
|
expr = generators.mkKeyValueDefault {} ":" "f:oo" "bar";
|
2016-12-05 00:11:24 +03:00
|
|
|
expected = ''f\:oo:bar'';
|
|
|
|
};
|
|
|
|
|
2018-03-26 18:31:05 +03:00
|
|
|
testMkValueString = {
|
|
|
|
expr = let
|
|
|
|
vals = {
|
|
|
|
int = 42;
|
|
|
|
string = ''fo"o'';
|
|
|
|
bool = true;
|
|
|
|
bool2 = false;
|
|
|
|
null = null;
|
|
|
|
# float = 42.23; # floats are strange
|
|
|
|
};
|
|
|
|
in mapAttrs
|
|
|
|
(const (generators.mkValueStringDefault {}))
|
|
|
|
vals;
|
|
|
|
expected = {
|
|
|
|
int = "42";
|
|
|
|
string = ''fo"o'';
|
|
|
|
bool = "true";
|
|
|
|
bool2 = "false";
|
|
|
|
null = "null";
|
|
|
|
# float = "42.23" true false [ "bar" ] ]'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-12-05 00:11:24 +03:00
|
|
|
testToKeyValue = {
|
|
|
|
expr = generators.toKeyValue {} {
|
|
|
|
key = "value";
|
|
|
|
"other=key" = "baz";
|
|
|
|
};
|
|
|
|
expected = ''
|
|
|
|
key=value
|
|
|
|
other\=key=baz
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-06 03:51:13 +03:00
|
|
|
testToINIEmpty = {
|
|
|
|
expr = generators.toINI {} {};
|
|
|
|
expected = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
testToINIEmptySection = {
|
|
|
|
expr = generators.toINI {} { foo = {}; bar = {}; };
|
|
|
|
expected = ''
|
|
|
|
[bar]
|
|
|
|
|
|
|
|
[foo]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-03-10 04:38:28 +03:00
|
|
|
testToINIDuplicateKeys = {
|
|
|
|
expr = generators.toINI { listsAsDuplicateKeys = true; } { foo.bar = true; baz.qux = [ 1 false ]; };
|
|
|
|
expected = ''
|
|
|
|
[baz]
|
|
|
|
qux=1
|
|
|
|
qux=false
|
|
|
|
|
|
|
|
[foo]
|
|
|
|
bar=true
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-06 03:51:13 +03:00
|
|
|
testToINIDefaultEscapes = {
|
|
|
|
expr = generators.toINI {} {
|
|
|
|
"no [ and ] allowed unescaped" = {
|
|
|
|
"and also no = in keys" = 42;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
expected = ''
|
|
|
|
[no \[ and \] allowed unescaped]
|
|
|
|
and also no \= in keys=42
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
testToINIDefaultFull = {
|
|
|
|
expr = generators.toINI {} {
|
|
|
|
"section 1" = {
|
|
|
|
attribute1 = 5;
|
|
|
|
x = "Me-se JarJar Binx";
|
2018-03-26 18:31:05 +03:00
|
|
|
# booleans are converted verbatim by default
|
|
|
|
boolean = false;
|
2016-11-06 03:51:13 +03:00
|
|
|
};
|
|
|
|
"foo[]" = {
|
|
|
|
"he\\h=he" = "this is okay";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
expected = ''
|
|
|
|
[foo\[\]]
|
|
|
|
he\h\=he=this is okay
|
|
|
|
|
|
|
|
[section 1]
|
|
|
|
attribute1=5
|
2018-03-26 18:31:05 +03:00
|
|
|
boolean=false
|
2016-11-06 03:51:13 +03:00
|
|
|
x=Me-se JarJar Binx
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-03-14 12:14:18 +03:00
|
|
|
testToINIWithGlobalSectionEmpty = {
|
|
|
|
expr = generators.toINIWithGlobalSection {} {
|
|
|
|
globalSection = {
|
|
|
|
};
|
|
|
|
sections = {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
expected = ''
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
testToINIWithGlobalSectionGlobalEmptyIsTheSameAsToINI =
|
|
|
|
let
|
|
|
|
sections = {
|
|
|
|
"section 1" = {
|
|
|
|
attribute1 = 5;
|
|
|
|
x = "Me-se JarJar Binx";
|
|
|
|
};
|
|
|
|
"foo" = {
|
|
|
|
"he\\h=he" = "this is okay";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
expr =
|
|
|
|
generators.toINIWithGlobalSection {} {
|
|
|
|
globalSection = {};
|
|
|
|
sections = sections;
|
|
|
|
};
|
|
|
|
expected = generators.toINI {} sections;
|
|
|
|
};
|
|
|
|
|
|
|
|
testToINIWithGlobalSectionFull = {
|
|
|
|
expr = generators.toINIWithGlobalSection {} {
|
|
|
|
globalSection = {
|
|
|
|
foo = "bar";
|
|
|
|
test = false;
|
|
|
|
};
|
|
|
|
sections = {
|
|
|
|
"section 1" = {
|
|
|
|
attribute1 = 5;
|
|
|
|
x = "Me-se JarJar Binx";
|
|
|
|
};
|
|
|
|
"foo" = {
|
|
|
|
"he\\h=he" = "this is okay";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
expected = ''
|
|
|
|
foo=bar
|
|
|
|
test=false
|
|
|
|
|
|
|
|
[foo]
|
|
|
|
he\h\=he=this is okay
|
|
|
|
|
|
|
|
[section 1]
|
|
|
|
attribute1=5
|
|
|
|
x=Me-se JarJar Binx
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-11-06 16:14:24 +03:00
|
|
|
/* right now only invocation check */
|
|
|
|
testToJSONSimple =
|
|
|
|
let val = {
|
|
|
|
foobar = [ "baz" 1 2 3 ];
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
expr = generators.toJSON {} val;
|
2017-04-19 22:41:28 +03:00
|
|
|
# trivial implementation
|
2016-11-06 16:14:24 +03:00
|
|
|
expected = builtins.toJSON val;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* right now only invocation check */
|
|
|
|
testToYAMLSimple =
|
|
|
|
let val = {
|
|
|
|
list = [ { one = 1; } { two = 2; } ];
|
|
|
|
all = 42;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
expr = generators.toYAML {} val;
|
2017-04-19 22:41:28 +03:00
|
|
|
# trivial implementation
|
2016-11-06 16:14:24 +03:00
|
|
|
expected = builtins.toJSON val;
|
|
|
|
};
|
|
|
|
|
2020-09-17 19:08:44 +03:00
|
|
|
testToPretty =
|
|
|
|
let
|
2021-12-13 14:03:32 +03:00
|
|
|
deriv = derivation { name = "test"; builder = "/bin/sh"; system = "aarch64-linux"; };
|
2020-09-17 19:08:44 +03:00
|
|
|
in {
|
2020-09-04 18:46:12 +03:00
|
|
|
expr = mapAttrs (const (generators.toPretty { multiline = false; })) rec {
|
2017-06-06 23:41:22 +03:00
|
|
|
int = 42;
|
2018-10-13 20:55:00 +03:00
|
|
|
float = 0.1337;
|
2017-06-06 23:41:22 +03:00
|
|
|
bool = true;
|
2020-09-17 18:58:04 +03:00
|
|
|
emptystring = "";
|
2022-11-07 15:01:13 +03:00
|
|
|
string = "fn\${o}\"r\\d";
|
2020-09-17 18:58:04 +03:00
|
|
|
newlinestring = "\n";
|
2018-05-22 23:42:02 +03:00
|
|
|
path = /. + "/foo";
|
2017-06-06 23:41:22 +03:00
|
|
|
null_ = null;
|
|
|
|
function = x: x;
|
2017-06-12 08:07:59 +03:00
|
|
|
functionArgs = { arg ? 4, foo }: arg;
|
2017-06-06 23:41:22 +03:00
|
|
|
list = [ 3 4 function [ false ] ];
|
2020-09-17 19:14:18 +03:00
|
|
|
emptylist = [];
|
2022-11-07 15:01:13 +03:00
|
|
|
attrs = { foo = null; "foo b/ar" = "baz"; };
|
2020-09-17 19:14:18 +03:00
|
|
|
emptyattrs = {};
|
2020-09-17 19:08:44 +03:00
|
|
|
drv = deriv;
|
2017-06-06 23:41:22 +03:00
|
|
|
};
|
|
|
|
expected = rec {
|
|
|
|
int = "42";
|
2022-11-03 17:56:27 +03:00
|
|
|
float = "0.1337";
|
2017-06-06 23:41:22 +03:00
|
|
|
bool = "true";
|
2020-09-17 18:58:04 +03:00
|
|
|
emptystring = ''""'';
|
2022-11-07 15:01:13 +03:00
|
|
|
string = ''"fn\''${o}\"r\\d"'';
|
2020-09-17 18:58:04 +03:00
|
|
|
newlinestring = "\"\\n\"";
|
2018-04-25 16:04:30 +03:00
|
|
|
path = "/foo";
|
2017-06-06 23:41:22 +03:00
|
|
|
null_ = "null";
|
2020-09-17 19:08:44 +03:00
|
|
|
function = "<function>";
|
|
|
|
functionArgs = "<function, args: {arg?, foo}>";
|
2017-06-06 23:41:22 +03:00
|
|
|
list = "[ 3 4 ${function} [ false ] ]";
|
2020-09-17 19:14:18 +03:00
|
|
|
emptylist = "[ ]";
|
2022-11-07 15:01:13 +03:00
|
|
|
attrs = "{ foo = null; \"foo b/ar\" = \"baz\"; }";
|
2020-09-17 19:14:18 +03:00
|
|
|
emptyattrs = "{ }";
|
2022-11-04 19:31:41 +03:00
|
|
|
drv = "<derivation ${deriv.name}>";
|
2017-06-06 23:41:22 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-07-23 11:43:44 +03:00
|
|
|
testToPrettyLimit =
|
|
|
|
let
|
|
|
|
a.b = 1;
|
|
|
|
a.c = a;
|
|
|
|
in {
|
2021-08-26 01:28:49 +03:00
|
|
|
expr = generators.toPretty { } (generators.withRecursion { throwOnDepthLimit = false; depthLimit = 2; } a);
|
|
|
|
expected = "{\n b = 1;\n c = {\n b = \"<unevaluated>\";\n c = {\n b = \"<unevaluated>\";\n c = \"<unevaluated>\";\n };\n };\n}";
|
2021-07-23 11:43:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
testToPrettyLimitThrow =
|
|
|
|
let
|
|
|
|
a.b = 1;
|
|
|
|
a.c = a;
|
|
|
|
in {
|
2021-08-26 01:28:49 +03:00
|
|
|
expr = (builtins.tryEval
|
|
|
|
(generators.toPretty { } (generators.withRecursion { depthLimit = 2; } a))).success;
|
2021-07-23 11:43:44 +03:00
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
2022-04-12 13:26:25 +03:00
|
|
|
testWithRecursionDealsWithFunctors =
|
|
|
|
let
|
|
|
|
functor = {
|
|
|
|
__functor = self: { a, b, }: null;
|
|
|
|
};
|
|
|
|
a = {
|
|
|
|
value = "1234";
|
|
|
|
b = functor;
|
|
|
|
c.d = functor;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
expr = generators.toPretty { } (generators.withRecursion { depthLimit = 1; throwOnDepthLimit = false; } a);
|
|
|
|
expected = "{\n b = <function, args: {a, b}>;\n c = {\n d = \"<unevaluated>\";\n };\n value = \"<unevaluated>\";\n}";
|
|
|
|
};
|
|
|
|
|
2020-09-04 18:46:12 +03:00
|
|
|
testToPrettyMultiline = {
|
|
|
|
expr = mapAttrs (const (generators.toPretty { })) rec {
|
|
|
|
list = [ 3 4 [ false ] ];
|
|
|
|
attrs = { foo = null; bar.foo = "baz"; };
|
2020-09-17 18:58:04 +03:00
|
|
|
newlinestring = "\n";
|
|
|
|
multilinestring = ''
|
|
|
|
hello
|
2022-11-07 15:01:13 +03:00
|
|
|
''${there}
|
|
|
|
te'''st
|
2020-09-17 18:58:04 +03:00
|
|
|
'';
|
|
|
|
multilinestring' = ''
|
|
|
|
hello
|
|
|
|
there
|
|
|
|
test'';
|
2020-09-04 18:46:12 +03:00
|
|
|
};
|
|
|
|
expected = rec {
|
|
|
|
list = ''
|
|
|
|
[
|
|
|
|
3
|
|
|
|
4
|
|
|
|
[
|
|
|
|
false
|
|
|
|
]
|
|
|
|
]'';
|
|
|
|
attrs = ''
|
|
|
|
{
|
|
|
|
bar = {
|
|
|
|
foo = "baz";
|
|
|
|
};
|
|
|
|
foo = null;
|
|
|
|
}'';
|
2020-09-17 18:58:04 +03:00
|
|
|
newlinestring = "''\n \n''";
|
|
|
|
multilinestring = ''
|
|
|
|
'''
|
|
|
|
hello
|
2022-11-07 15:01:13 +03:00
|
|
|
'''''${there}
|
|
|
|
te''''st
|
2020-09-17 18:58:04 +03:00
|
|
|
''''';
|
|
|
|
multilinestring' = ''
|
|
|
|
'''
|
|
|
|
hello
|
|
|
|
there
|
|
|
|
test''''';
|
|
|
|
|
2017-06-06 23:41:22 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testToPrettyAllowPrettyValues = {
|
|
|
|
expr = generators.toPretty { allowPrettyValues = true; }
|
|
|
|
{ __pretty = v: "«" + v + "»"; val = "foo"; };
|
|
|
|
expected = "«foo»";
|
|
|
|
};
|
|
|
|
|
2020-01-23 01:24:06 +03:00
|
|
|
|
|
|
|
# CLI
|
|
|
|
|
|
|
|
testToGNUCommandLine = {
|
2020-01-23 01:37:10 +03:00
|
|
|
expr = cli.toGNUCommandLine {} {
|
|
|
|
data = builtins.toJSON { id = 0; };
|
|
|
|
X = "PUT";
|
|
|
|
retry = 3;
|
|
|
|
retry-delay = null;
|
|
|
|
url = [ "https://example.com/foo" "https://example.com/bar" ];
|
|
|
|
silent = false;
|
|
|
|
verbose = true;
|
|
|
|
};
|
2020-01-23 01:24:06 +03:00
|
|
|
|
2020-01-23 01:37:10 +03:00
|
|
|
expected = [
|
|
|
|
"-X" "PUT"
|
|
|
|
"--data" "{\"id\":0}"
|
|
|
|
"--retry" "3"
|
|
|
|
"--url" "https://example.com/foo"
|
|
|
|
"--url" "https://example.com/bar"
|
|
|
|
"--verbose"
|
|
|
|
];
|
2020-01-23 01:24:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
testToGNUCommandLineShell = {
|
2020-01-23 01:37:10 +03:00
|
|
|
expr = cli.toGNUCommandLineShell {} {
|
|
|
|
data = builtins.toJSON { id = 0; };
|
|
|
|
X = "PUT";
|
|
|
|
retry = 3;
|
|
|
|
retry-delay = null;
|
|
|
|
url = [ "https://example.com/foo" "https://example.com/bar" ];
|
|
|
|
silent = false;
|
|
|
|
verbose = true;
|
|
|
|
};
|
2019-12-12 03:30:05 +03:00
|
|
|
|
2020-01-06 00:03:00 +03:00
|
|
|
expected = "'-X' 'PUT' '--data' '{\"id\":0}' '--retry' '3' '--url' 'https://example.com/foo' '--url' 'https://example.com/bar' '--verbose'";
|
2019-12-12 03:30:05 +03:00
|
|
|
};
|
2020-01-28 01:03:38 +03:00
|
|
|
|
|
|
|
testSanitizeDerivationNameLeadingDots = testSanitizeDerivationName {
|
|
|
|
name = "..foo";
|
|
|
|
expected = "foo";
|
|
|
|
};
|
|
|
|
|
2022-03-30 12:20:44 +03:00
|
|
|
testSanitizeDerivationNameUnicode = testSanitizeDerivationName {
|
|
|
|
name = "fö";
|
|
|
|
expected = "f-";
|
|
|
|
};
|
|
|
|
|
2020-01-28 01:03:38 +03:00
|
|
|
testSanitizeDerivationNameAscii = testSanitizeDerivationName {
|
|
|
|
name = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
|
|
|
expected = "-+--.-0123456789-=-?-ABCDEFGHIJKLMNOPQRSTUVWXYZ-_-abcdefghijklmnopqrstuvwxyz-";
|
|
|
|
};
|
|
|
|
|
|
|
|
testSanitizeDerivationNameTooLong = testSanitizeDerivationName {
|
|
|
|
name = "This string is loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong";
|
|
|
|
expected = "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong";
|
|
|
|
};
|
|
|
|
|
|
|
|
testSanitizeDerivationNameTooLongWithInvalid = testSanitizeDerivationName {
|
|
|
|
name = "Hello there aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&&&&&&&";
|
|
|
|
expected = "there-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-";
|
|
|
|
};
|
|
|
|
|
|
|
|
testSanitizeDerivationNameEmpty = testSanitizeDerivationName {
|
|
|
|
name = "";
|
|
|
|
expected = "unknown";
|
|
|
|
};
|
2020-09-04 16:50:13 +03:00
|
|
|
|
|
|
|
testFreeformOptions = {
|
|
|
|
expr =
|
|
|
|
let
|
|
|
|
submodule = { lib, ... }: {
|
|
|
|
freeformType = lib.types.attrsOf (lib.types.submodule {
|
|
|
|
options.bar = lib.mkOption {};
|
|
|
|
});
|
|
|
|
options.bar = lib.mkOption {};
|
|
|
|
};
|
|
|
|
|
|
|
|
module = { lib, ... }: {
|
|
|
|
options.foo = lib.mkOption {
|
|
|
|
type = lib.types.submodule submodule;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
options = (evalModules {
|
|
|
|
modules = [ module ];
|
|
|
|
}).options;
|
|
|
|
|
2020-12-18 18:42:42 +03:00
|
|
|
locs = filter (o: ! o.internal) (optionAttrSetToDocList options);
|
2020-09-04 16:50:13 +03:00
|
|
|
in map (o: o.loc) locs;
|
2022-03-24 04:44:43 +03:00
|
|
|
expected = [ [ "_module" "args" ] [ "foo" ] [ "foo" "<name>" "bar" ] [ "foo" "bar" ] ];
|
2020-09-04 16:50:13 +03:00
|
|
|
};
|
|
|
|
|
2021-01-25 18:59:46 +03:00
|
|
|
testCartesianProductOfEmptySet = {
|
|
|
|
expr = cartesianProductOfSets {};
|
|
|
|
expected = [ {} ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testCartesianProductOfOneSet = {
|
|
|
|
expr = cartesianProductOfSets { a = [ 1 2 3 ]; };
|
|
|
|
expected = [ { a = 1; } { a = 2; } { a = 3; } ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testCartesianProductOfTwoSets = {
|
|
|
|
expr = cartesianProductOfSets { a = [ 1 ]; b = [ 10 20 ]; };
|
|
|
|
expected = [
|
|
|
|
{ a = 1; b = 10; }
|
|
|
|
{ a = 1; b = 20; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
testCartesianProductOfTwoSetsWithOneEmpty = {
|
|
|
|
expr = cartesianProductOfSets { a = [ ]; b = [ 10 20 ]; };
|
|
|
|
expected = [ ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testCartesianProductOfThreeSets = {
|
|
|
|
expr = cartesianProductOfSets {
|
|
|
|
a = [ 1 2 3 ];
|
|
|
|
b = [ 10 20 30 ];
|
|
|
|
c = [ 100 200 300 ];
|
|
|
|
};
|
|
|
|
expected = [
|
|
|
|
{ a = 1; b = 10; c = 100; }
|
|
|
|
{ a = 1; b = 10; c = 200; }
|
|
|
|
{ a = 1; b = 10; c = 300; }
|
|
|
|
|
|
|
|
{ a = 1; b = 20; c = 100; }
|
|
|
|
{ a = 1; b = 20; c = 200; }
|
|
|
|
{ a = 1; b = 20; c = 300; }
|
|
|
|
|
|
|
|
{ a = 1; b = 30; c = 100; }
|
|
|
|
{ a = 1; b = 30; c = 200; }
|
|
|
|
{ a = 1; b = 30; c = 300; }
|
|
|
|
|
|
|
|
{ a = 2; b = 10; c = 100; }
|
|
|
|
{ a = 2; b = 10; c = 200; }
|
|
|
|
{ a = 2; b = 10; c = 300; }
|
|
|
|
|
|
|
|
{ a = 2; b = 20; c = 100; }
|
|
|
|
{ a = 2; b = 20; c = 200; }
|
|
|
|
{ a = 2; b = 20; c = 300; }
|
|
|
|
|
|
|
|
{ a = 2; b = 30; c = 100; }
|
|
|
|
{ a = 2; b = 30; c = 200; }
|
|
|
|
{ a = 2; b = 30; c = 300; }
|
|
|
|
|
|
|
|
{ a = 3; b = 10; c = 100; }
|
|
|
|
{ a = 3; b = 10; c = 200; }
|
|
|
|
{ a = 3; b = 10; c = 300; }
|
|
|
|
|
|
|
|
{ a = 3; b = 20; c = 100; }
|
|
|
|
{ a = 3; b = 20; c = 200; }
|
|
|
|
{ a = 3; b = 20; c = 300; }
|
|
|
|
|
|
|
|
{ a = 3; b = 30; c = 100; }
|
|
|
|
{ a = 3; b = 30; c = 200; }
|
|
|
|
{ a = 3; b = 30; c = 300; }
|
|
|
|
];
|
|
|
|
};
|
2021-12-02 20:12:51 +03:00
|
|
|
|
|
|
|
# The example from the showAttrPath documentation
|
|
|
|
testShowAttrPathExample = {
|
|
|
|
expr = showAttrPath [ "foo" "10" "bar" ];
|
|
|
|
expected = "foo.\"10\".bar";
|
|
|
|
};
|
|
|
|
|
|
|
|
testShowAttrPathEmpty = {
|
|
|
|
expr = showAttrPath [];
|
|
|
|
expected = "<root attribute path>";
|
|
|
|
};
|
|
|
|
|
|
|
|
testShowAttrPathVarious = {
|
|
|
|
expr = showAttrPath [
|
|
|
|
"."
|
|
|
|
"foo"
|
|
|
|
"2"
|
|
|
|
"a2-b"
|
|
|
|
"_bc'de"
|
|
|
|
];
|
2021-12-02 21:34:08 +03:00
|
|
|
expected = ''".".foo."2".a2-b._bc'de'';
|
|
|
|
};
|
|
|
|
|
|
|
|
testGroupBy = {
|
|
|
|
expr = groupBy (n: toString (mod n 5)) (range 0 16);
|
|
|
|
expected = {
|
|
|
|
"0" = [ 0 5 10 15 ];
|
|
|
|
"1" = [ 1 6 11 16 ];
|
|
|
|
"2" = [ 2 7 12 ];
|
|
|
|
"3" = [ 3 8 13 ];
|
|
|
|
"4" = [ 4 9 14 ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testGroupBy' = {
|
|
|
|
expr = groupBy' builtins.add 0 (x: boolToString (x > 2)) [ 5 1 2 3 4 ];
|
|
|
|
expected = { false = 3; true = 12; };
|
2021-12-02 20:12:51 +03:00
|
|
|
};
|
2021-11-22 22:34:01 +03:00
|
|
|
|
|
|
|
# The example from the updateManyAttrsByPath documentation
|
|
|
|
testUpdateManyAttrsByPathExample = {
|
|
|
|
expr = updateManyAttrsByPath [
|
|
|
|
{
|
|
|
|
path = [ "a" "b" ];
|
|
|
|
update = old: { d = old.c; };
|
|
|
|
}
|
|
|
|
{
|
|
|
|
path = [ "a" "b" "c" ];
|
|
|
|
update = old: old + 1;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
path = [ "x" "y" ];
|
|
|
|
update = old: "xy";
|
|
|
|
}
|
|
|
|
] { a.b.c = 0; };
|
|
|
|
expected = { a = { b = { d = 1; }; }; x = { y = "xy"; }; };
|
|
|
|
};
|
|
|
|
|
|
|
|
# If there are no updates, the value is passed through
|
|
|
|
testUpdateManyAttrsByPathNone = {
|
|
|
|
expr = updateManyAttrsByPath [] "something";
|
|
|
|
expected = "something";
|
|
|
|
};
|
|
|
|
|
|
|
|
# A single update to the root path is just like applying the function directly
|
|
|
|
testUpdateManyAttrsByPathSingleIncrement = {
|
|
|
|
expr = updateManyAttrsByPath [
|
|
|
|
{
|
|
|
|
path = [ ];
|
|
|
|
update = old: old + 1;
|
|
|
|
}
|
|
|
|
] 0;
|
|
|
|
expected = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Multiple updates can be applied are done in order
|
|
|
|
testUpdateManyAttrsByPathMultipleIncrements = {
|
|
|
|
expr = updateManyAttrsByPath [
|
|
|
|
{
|
|
|
|
path = [ ];
|
|
|
|
update = old: old + "a";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
path = [ ];
|
|
|
|
update = old: old + "b";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
path = [ ];
|
|
|
|
update = old: old + "c";
|
|
|
|
}
|
|
|
|
] "";
|
|
|
|
expected = "abc";
|
|
|
|
};
|
|
|
|
|
|
|
|
# If an update doesn't use the value, all previous updates are not evaluated
|
|
|
|
testUpdateManyAttrsByPathLazy = {
|
|
|
|
expr = updateManyAttrsByPath [
|
|
|
|
{
|
|
|
|
path = [ ];
|
|
|
|
update = old: old + throw "nope";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
path = [ ];
|
|
|
|
update = old: "untainted";
|
|
|
|
}
|
|
|
|
] (throw "start");
|
|
|
|
expected = "untainted";
|
|
|
|
};
|
|
|
|
|
|
|
|
# Deeply nested attributes can be updated without affecting others
|
|
|
|
testUpdateManyAttrsByPathDeep = {
|
|
|
|
expr = updateManyAttrsByPath [
|
|
|
|
{
|
|
|
|
path = [ "a" "b" "c" ];
|
|
|
|
update = old: old + 1;
|
|
|
|
}
|
|
|
|
] {
|
|
|
|
a.b.c = 0;
|
|
|
|
|
|
|
|
a.b.z = 0;
|
|
|
|
a.y.z = 0;
|
|
|
|
x.y.z = 0;
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
a.b.c = 1;
|
|
|
|
|
|
|
|
a.b.z = 0;
|
|
|
|
a.y.z = 0;
|
|
|
|
x.y.z = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# Nested attributes are updated first
|
|
|
|
testUpdateManyAttrsByPathNestedBeforehand = {
|
|
|
|
expr = updateManyAttrsByPath [
|
|
|
|
{
|
|
|
|
path = [ "a" ];
|
|
|
|
update = old: old // { x = old.b; };
|
|
|
|
}
|
|
|
|
{
|
|
|
|
path = [ "a" "b" ];
|
|
|
|
update = old: old + 1;
|
|
|
|
}
|
|
|
|
] {
|
|
|
|
a.b = 0;
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
a.b = 1;
|
|
|
|
a.x = 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-25 20:54:19 +03:00
|
|
|
## Levenshtein distance functions and co.
|
|
|
|
testCommonPrefixLengthEmpty = {
|
|
|
|
expr = strings.commonPrefixLength "" "hello";
|
|
|
|
expected = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
testCommonPrefixLengthSame = {
|
|
|
|
expr = strings.commonPrefixLength "hello" "hello";
|
|
|
|
expected = 5;
|
|
|
|
};
|
|
|
|
|
|
|
|
testCommonPrefixLengthDiffering = {
|
|
|
|
expr = strings.commonPrefixLength "hello" "hey";
|
|
|
|
expected = 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
testCommonSuffixLengthEmpty = {
|
|
|
|
expr = strings.commonSuffixLength "" "hello";
|
|
|
|
expected = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
testCommonSuffixLengthSame = {
|
|
|
|
expr = strings.commonSuffixLength "hello" "hello";
|
|
|
|
expected = 5;
|
|
|
|
};
|
|
|
|
|
|
|
|
testCommonSuffixLengthDiffering = {
|
|
|
|
expr = strings.commonSuffixLength "test" "rest";
|
|
|
|
expected = 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinEmpty = {
|
|
|
|
expr = strings.levenshtein "" "";
|
|
|
|
expected = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinOnlyAdd = {
|
|
|
|
expr = strings.levenshtein "" "hello there";
|
|
|
|
expected = 11;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinOnlyRemove = {
|
|
|
|
expr = strings.levenshtein "hello there" "";
|
|
|
|
expected = 11;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinOnlyTransform = {
|
|
|
|
expr = strings.levenshtein "abcdef" "ghijkl";
|
|
|
|
expected = 6;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinMixed = {
|
|
|
|
expr = strings.levenshtein "kitchen" "sitting";
|
|
|
|
expected = 5;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostZeroFalse = {
|
|
|
|
expr = strings.levenshteinAtMost 0 "foo" "boo";
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostZeroTrue = {
|
|
|
|
expr = strings.levenshteinAtMost 0 "foo" "foo";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostOneFalse = {
|
|
|
|
expr = strings.levenshteinAtMost 1 "car" "ct";
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostOneTrue = {
|
|
|
|
expr = strings.levenshteinAtMost 1 "car" "cr";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
# We test levenshteinAtMost 2 particularly well because it uses a complicated
|
|
|
|
# implementation
|
|
|
|
testLevenshteinAtMostTwoIsEmpty = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "" "";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoIsZero = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "abcdef" "abcdef";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoIsOne = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "abcdef" "abddef";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff0False = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "abcdef" "aczyef";
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff0Outer = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "abcdef" "zbcdez";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff0DelLeft = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "abcdef" "bcdefz";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff0DelRight = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "abcdef" "zabcde";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff1False = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "abcdef" "bddez";
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff1DelLeft = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "abcdef" "bcdez";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff1DelRight = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "abcdef" "zbcde";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff2False = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "hello" "hxo";
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff2True = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "hello" "heo";
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostTwoDiff3 = {
|
|
|
|
expr = strings.levenshteinAtMost 2 "hello" "ho";
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostThreeFalse = {
|
|
|
|
expr = strings.levenshteinAtMost 3 "hello" "Holla!";
|
|
|
|
expected = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
testLevenshteinAtMostThreeTrue = {
|
|
|
|
expr = strings.levenshteinAtMost 3 "hello" "Holla";
|
|
|
|
expected = true;
|
|
|
|
};
|
2022-09-15 19:29:38 +03:00
|
|
|
|
2022-06-25 14:53:02 +03:00
|
|
|
# lazyDerivation
|
|
|
|
|
|
|
|
testLazyDerivationIsLazyInDerivationForAttrNames = {
|
|
|
|
expr = attrNames (lazyDerivation {
|
|
|
|
derivation = throw "not lazy enough";
|
|
|
|
});
|
|
|
|
# It's ok to add attribute names here when lazyDerivation is improved
|
|
|
|
# in accordance with its inline comments.
|
|
|
|
expected = [ "drvPath" "meta" "name" "out" "outPath" "outputName" "outputs" "system" "type" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testLazyDerivationIsLazyInDerivationForPassthruAttr = {
|
|
|
|
expr = (lazyDerivation {
|
|
|
|
derivation = throw "not lazy enough";
|
|
|
|
passthru.tests = "whatever is in tests";
|
|
|
|
}).tests;
|
|
|
|
expected = "whatever is in tests";
|
|
|
|
};
|
|
|
|
|
|
|
|
testLazyDerivationIsLazyInDerivationForPassthruAttr2 = {
|
|
|
|
# passthru.tests is not a special case. It works for any attr.
|
|
|
|
expr = (lazyDerivation {
|
|
|
|
derivation = throw "not lazy enough";
|
|
|
|
passthru.foo = "whatever is in foo";
|
|
|
|
}).foo;
|
|
|
|
expected = "whatever is in foo";
|
|
|
|
};
|
|
|
|
|
|
|
|
testLazyDerivationIsLazyInDerivationForMeta = {
|
|
|
|
expr = (lazyDerivation {
|
|
|
|
derivation = throw "not lazy enough";
|
|
|
|
meta = "whatever is in meta";
|
|
|
|
}).meta;
|
|
|
|
expected = "whatever is in meta";
|
|
|
|
};
|
|
|
|
|
|
|
|
testLazyDerivationReturnsDerivationAttrs = let
|
|
|
|
derivation = {
|
|
|
|
type = "derivation";
|
|
|
|
outputs = ["out"];
|
|
|
|
out = "test out";
|
|
|
|
outPath = "test outPath";
|
|
|
|
outputName = "out";
|
|
|
|
drvPath = "test drvPath";
|
|
|
|
name = "test name";
|
|
|
|
system = "test system";
|
|
|
|
meta = "test meta";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
expr = lazyDerivation { inherit derivation; };
|
|
|
|
expected = derivation;
|
|
|
|
};
|
|
|
|
|
2022-09-15 19:29:38 +03:00
|
|
|
testTypeDescriptionInt = {
|
|
|
|
expr = (with types; int).description;
|
|
|
|
expected = "signed integer";
|
|
|
|
};
|
|
|
|
testTypeDescriptionListOfInt = {
|
|
|
|
expr = (with types; listOf int).description;
|
|
|
|
expected = "list of signed integer";
|
|
|
|
};
|
|
|
|
testTypeDescriptionListOfListOfInt = {
|
|
|
|
expr = (with types; listOf (listOf int)).description;
|
|
|
|
expected = "list of list of signed integer";
|
|
|
|
};
|
|
|
|
testTypeDescriptionListOfEitherStrOrBool = {
|
|
|
|
expr = (with types; listOf (either str bool)).description;
|
|
|
|
expected = "list of (string or boolean)";
|
|
|
|
};
|
|
|
|
testTypeDescriptionEitherListOfStrOrBool = {
|
|
|
|
expr = (with types; either (listOf bool) str).description;
|
|
|
|
expected = "(list of boolean) or string";
|
|
|
|
};
|
|
|
|
testTypeDescriptionEitherStrOrListOfBool = {
|
|
|
|
expr = (with types; either str (listOf bool)).description;
|
|
|
|
expected = "string or list of boolean";
|
|
|
|
};
|
|
|
|
testTypeDescriptionOneOfListOfStrOrBool = {
|
|
|
|
expr = (with types; oneOf [ (listOf bool) str ]).description;
|
|
|
|
expected = "(list of boolean) or string";
|
|
|
|
};
|
|
|
|
testTypeDescriptionOneOfListOfStrOrBoolOrNumber = {
|
|
|
|
expr = (with types; oneOf [ (listOf bool) str number ]).description;
|
|
|
|
expected = "(list of boolean) or string or signed integer or floating point number";
|
|
|
|
};
|
|
|
|
testTypeDescriptionEitherListOfBoolOrEitherStringOrNumber = {
|
|
|
|
expr = (with types; either (listOf bool) (either str number)).description;
|
|
|
|
expected = "(list of boolean) or string or signed integer or floating point number";
|
|
|
|
};
|
|
|
|
testTypeDescriptionEitherEitherListOfBoolOrStringOrNumber = {
|
|
|
|
expr = (with types; either (either (listOf bool) str) number).description;
|
|
|
|
expected = "(list of boolean) or string or signed integer or floating point number";
|
|
|
|
};
|
|
|
|
testTypeDescriptionEitherNullOrBoolOrString = {
|
|
|
|
expr = (with types; either (nullOr bool) str).description;
|
|
|
|
expected = "null or boolean or string";
|
|
|
|
};
|
|
|
|
testTypeDescriptionEitherListOfEitherBoolOrStrOrInt = {
|
|
|
|
expr = (with types; either (listOf (either bool str)) int).description;
|
|
|
|
expected = "(list of (boolean or string)) or signed integer";
|
|
|
|
};
|
|
|
|
testTypeDescriptionEitherIntOrListOrEitherBoolOrStr = {
|
|
|
|
expr = (with types; either int (listOf (either bool str))).description;
|
|
|
|
expected = "signed integer or list of (boolean or string)";
|
|
|
|
};
|
2009-03-31 17:03:50 +04:00
|
|
|
}
|