diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-12T09·14+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-12T09·14+0000 |
commit | c3f228f296321991ef54e46fc621a292824b13e1 (patch) | |
tree | 5b581ec345b155bc01042ac7fbe983162d90d5ed /src/libexpr/eval-test.cc | |
parent | f3dc7ab877c736ec1500f6b503ab71a62ce90305 (diff) |
Diffstat (limited to 'src/libexpr/eval-test.cc')
-rw-r--r-- | src/libexpr/eval-test.cc | 113 |
1 files changed, 58 insertions, 55 deletions
diff --git a/src/libexpr/eval-test.cc b/src/libexpr/eval-test.cc index eac95094fd1f..77861dea95be 100644 --- a/src/libexpr/eval-test.cc +++ b/src/libexpr/eval-test.cc @@ -10,9 +10,8 @@ using namespace nix; -void doTest(string s) +void doTest(EvalState & state, string s) { - EvalState state; Expr e = parseExprFromString(state, s, absPath(".")); printMsg(lvlError, format(">>>>> %1%") % e); Value v; @@ -24,61 +23,65 @@ void doTest(string s) void run(Strings args) { + EvalState state; + printMsg(lvlError, format("size of value: %1% bytes") % sizeof(Value)); - doTest("123"); - doTest("{ x = 1; y = 2; }"); - doTest("{ x = 1; y = 2; }.y"); - doTest("rec { x = 1; y = x; }.y"); - doTest("(x: x) 1"); - doTest("(x: y: y) 1 2"); - doTest("x: x"); - doTest("({x, y}: x) { x = 1; y = 2; }"); - doTest("({x, y}@args: args.x) { x = 1; y = 2; }"); - doTest("(args@{x, y}: args.x) { x = 1; y = 2; }"); - doTest("({x ? 1}: x) { }"); - doTest("({x ? 1, y ? x}: y) { x = 2; }"); - doTest("({x, y, ...}: x) { x = 1; y = 2; z = 3; }"); - doTest("({x, y, ...}@args: args.z) { x = 1; y = 2; z = 3; }"); - //doTest("({x ? y, y ? x}: y) { }"); - doTest("let x = 1; in x"); - doTest("with { x = 1; }; x"); - doTest("let x = 2; in with { x = 1; }; x"); // => 2 - doTest("with { x = 1; }; with { x = 2; }; x"); // => 1 - doTest("[ 1 2 3 ]"); - doTest("[ 1 2 ] ++ [ 3 4 5 ]"); - doTest("123 == 123"); - doTest("123 == 456"); - doTest("let id = x: x; in [1 2] == [(id 1) (id 2)]"); - doTest("let id = x: x; in [1 2] == [(id 1) (id 3)]"); - doTest("[1 2] == [3 (let x = x; in x)]"); - doTest("{ x = 1; y.z = 2; } == { y = { z = 2; }; x = 1; }"); - doTest("{ x = 1; y = 2; } == { x = 2; }"); - doTest("{ x = [ 1 2 ]; } == { x = [ 1 ] ++ [ 2 ]; }"); - doTest("1 != 1"); - doTest("true"); - doTest("builtins.true"); - doTest("true == false"); - doTest("__head [ 1 2 3 ]"); - doTest("__add 1 2"); - doTest("null"); - doTest("null"); - doTest("\"foo\""); - doTest("let s = \"bar\"; in \"foo${s}\""); - doTest("if true then 1 else 2"); - doTest("if false then 1 else 2"); - doTest("if false || true then 1 else 2"); - doTest("let x = x; in if true || x then 1 else 2"); - doTest("/etc/passwd"); - //doTest("import ./foo.nix"); - doTest("map (x: __add 1 x) [ 1 2 3 ]"); - doTest("map (builtins.add 1) [ 1 2 3 ]"); - doTest("builtins.hasAttr \"x\" { x = 1; }"); - doTest("let x = 1; as = rec { inherit x; y = as.x; }; in as.y"); - doTest("let as = { x = 1; }; bs = rec { inherit (as) x; y = x; }; in bs.y"); - doTest("let as = rec { inherit (y) x; y = { x = 1; }; }; in as.x"); - doTest("builtins.toXML 123"); - doTest("builtins.toXML { a.b = \"x\" + \"y\"; c = [ 1 2 ] ++ [ 3 4 ]; }"); + doTest(state, "123"); + doTest(state, "{ x = 1; y = 2; }"); + doTest(state, "{ x = 1; y = 2; }.y"); + doTest(state, "rec { x = 1; y = x; }.y"); + doTest(state, "(x: x) 1"); + doTest(state, "(x: y: y) 1 2"); + doTest(state, "x: x"); + doTest(state, "({x, y}: x) { x = 1; y = 2; }"); + doTest(state, "({x, y}@args: args.x) { x = 1; y = 2; }"); + doTest(state, "(args@{x, y}: args.x) { x = 1; y = 2; }"); + doTest(state, "({x ? 1}: x) { }"); + doTest(state, "({x ? 1, y ? x}: y) { x = 2; }"); + doTest(state, "({x, y, ...}: x) { x = 1; y = 2; z = 3; }"); + doTest(state, "({x, y, ...}@args: args.z) { x = 1; y = 2; z = 3; }"); + //doTest(state, "({x ? y, y ? x}: y) { }"); + doTest(state, "let x = 1; in x"); + doTest(state, "with { x = 1; }; x"); + doTest(state, "let x = 2; in with { x = 1; }; x"); // => 2 + doTest(state, "with { x = 1; }; with { x = 2; }; x"); // => 1 + doTest(state, "[ 1 2 3 ]"); + doTest(state, "[ 1 2 ] ++ [ 3 4 5 ]"); + doTest(state, "123 == 123"); + doTest(state, "123 == 456"); + doTest(state, "let id = x: x; in [1 2] == [(id 1) (id 2)]"); + doTest(state, "let id = x: x; in [1 2] == [(id 1) (id 3)]"); + doTest(state, "[1 2] == [3 (let x = x; in x)]"); + doTest(state, "{ x = 1; y.z = 2; } == { y = { z = 2; }; x = 1; }"); + doTest(state, "{ x = 1; y = 2; } == { x = 2; }"); + doTest(state, "{ x = [ 1 2 ]; } == { x = [ 1 ] ++ [ 2 ]; }"); + doTest(state, "1 != 1"); + doTest(state, "true"); + doTest(state, "builtins.true"); + doTest(state, "true == false"); + doTest(state, "__head [ 1 2 3 ]"); + doTest(state, "__add 1 2"); + doTest(state, "null"); + doTest(state, "null"); + doTest(state, "\"foo\""); + doTest(state, "let s = \"bar\"; in \"foo${s}\""); + doTest(state, "if true then 1 else 2"); + doTest(state, "if false then 1 else 2"); + doTest(state, "if false || true then 1 else 2"); + doTest(state, "let x = x; in if true || x then 1 else 2"); + doTest(state, "/etc/passwd"); + //doTest(state, "import ./foo.nix"); + doTest(state, "map (x: __add 1 x) [ 1 2 3 ]"); + doTest(state, "map (builtins.add 1) [ 1 2 3 ]"); + doTest(state, "builtins.hasAttr \"x\" { x = 1; }"); + doTest(state, "let x = 1; as = rec { inherit x; y = as.x; }; in as.y"); + doTest(state, "let as = { x = 1; }; bs = rec { inherit (as) x; y = x; }; in bs.y"); + doTest(state, "let as = rec { inherit (y) x; y = { x = 1; }; }; in as.x"); + doTest(state, "builtins.toXML 123"); + doTest(state, "builtins.toXML { a.b = \"x\" + \"y\"; c = [ 1 2 ] ++ [ 3 4 ]; }"); + + state.printStats(); } |