Merge pull request #97133 from Infinisil/improved-toPretty
Improve `generators.toPretty`
This commit is contained in:
@@ -445,32 +445,90 @@ runTests {
|
||||
expected = builtins.toJSON val;
|
||||
};
|
||||
|
||||
testToPretty = {
|
||||
expr = mapAttrs (const (generators.toPretty {})) rec {
|
||||
testToPretty =
|
||||
let
|
||||
deriv = derivation { name = "test"; builder = "/bin/sh"; system = builtins.currentSystem; };
|
||||
in {
|
||||
expr = mapAttrs (const (generators.toPretty { multiline = false; })) rec {
|
||||
int = 42;
|
||||
float = 0.1337;
|
||||
bool = true;
|
||||
emptystring = "";
|
||||
string = ''fno"rd'';
|
||||
newlinestring = "\n";
|
||||
path = /. + "/foo";
|
||||
null_ = null;
|
||||
function = x: x;
|
||||
functionArgs = { arg ? 4, foo }: arg;
|
||||
list = [ 3 4 function [ false ] ];
|
||||
emptylist = [];
|
||||
attrs = { foo = null; "foo bar" = "baz"; };
|
||||
drv = derivation { name = "test"; system = builtins.currentSystem; };
|
||||
emptyattrs = {};
|
||||
drv = deriv;
|
||||
};
|
||||
expected = rec {
|
||||
int = "42";
|
||||
float = "~0.133700";
|
||||
bool = "true";
|
||||
emptystring = ''""'';
|
||||
string = ''"fno\"rd"'';
|
||||
newlinestring = "\"\\n\"";
|
||||
path = "/foo";
|
||||
null_ = "null";
|
||||
function = "<λ>";
|
||||
functionArgs = "<λ:{(arg),foo}>";
|
||||
function = "<function>";
|
||||
functionArgs = "<function, args: {arg?, foo}>";
|
||||
list = "[ 3 4 ${function} [ false ] ]";
|
||||
attrs = "{ \"foo\" = null; \"foo bar\" = \"baz\"; }";
|
||||
drv = "<δ:test>";
|
||||
emptylist = "[ ]";
|
||||
attrs = "{ foo = null; \"foo bar\" = \"baz\"; }";
|
||||
emptyattrs = "{ }";
|
||||
drv = "<derivation ${deriv.drvPath}>";
|
||||
};
|
||||
};
|
||||
|
||||
testToPrettyMultiline = {
|
||||
expr = mapAttrs (const (generators.toPretty { })) rec {
|
||||
list = [ 3 4 [ false ] ];
|
||||
attrs = { foo = null; bar.foo = "baz"; };
|
||||
newlinestring = "\n";
|
||||
multilinestring = ''
|
||||
hello
|
||||
there
|
||||
test
|
||||
'';
|
||||
multilinestring' = ''
|
||||
hello
|
||||
there
|
||||
test'';
|
||||
};
|
||||
expected = rec {
|
||||
list = ''
|
||||
[
|
||||
3
|
||||
4
|
||||
[
|
||||
false
|
||||
]
|
||||
]'';
|
||||
attrs = ''
|
||||
{
|
||||
bar = {
|
||||
foo = "baz";
|
||||
};
|
||||
foo = null;
|
||||
}'';
|
||||
newlinestring = "''\n \n''";
|
||||
multilinestring = ''
|
||||
'''
|
||||
hello
|
||||
there
|
||||
test
|
||||
''''';
|
||||
multilinestring' = ''
|
||||
'''
|
||||
hello
|
||||
there
|
||||
test''''';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user