2010-03-23 18:30:50 +01:00
|
|
|
#include "nixexpr.hh"
|
|
|
|
#include "parser.hh"
|
|
|
|
#include "hash.hh"
|
|
|
|
#include "util.hh"
|
|
|
|
#include "nixexpr-ast.hh"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
2010-03-28 20:27:07 +02:00
|
|
|
#include <cstring>
|
2010-03-23 18:30:50 +01:00
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
|
|
|
|
void doTest(string s)
|
|
|
|
{
|
|
|
|
EvalState state;
|
2010-03-30 11:22:33 +02:00
|
|
|
Expr e = parseExprFromString(state, s, absPath("."));
|
2010-03-25 00:40:00 +01:00
|
|
|
printMsg(lvlError, format(">>>>> %1%") % e);
|
2010-03-24 13:41:08 +01:00
|
|
|
Value v;
|
2010-03-29 16:37:56 +02:00
|
|
|
state.strictEval(e, v);
|
2010-03-24 13:11:38 +01:00
|
|
|
printMsg(lvlError, format("result: %1%") % v);
|
2010-03-23 18:30:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void run(Strings args)
|
|
|
|
{
|
2010-03-24 13:41:08 +01:00
|
|
|
printMsg(lvlError, format("size of value: %1% bytes") % sizeof(Value));
|
2010-03-23 18:30:50 +01:00
|
|
|
|
|
|
|
doTest("123");
|
|
|
|
doTest("{ x = 1; y = 2; }");
|
|
|
|
doTest("{ x = 1; y = 2; }.y");
|
|
|
|
doTest("rec { x = 1; y = x; }.y");
|
2010-03-24 12:06:05 +01:00
|
|
|
doTest("(x: x) 1");
|
|
|
|
doTest("(x: y: y) 1 2");
|
2010-03-25 00:40:00 +01:00
|
|
|
doTest("x: x");
|
|
|
|
doTest("({x, y}: x) { x = 1; y = 2; }");
|
|
|
|
doTest("({x, y}@args: args.x) { x = 1; y = 2; }");
|
2010-03-25 13:19:41 +01:00
|
|
|
doTest("(args@{x, y}: args.x) { x = 1; y = 2; }");
|
2010-03-25 13:45:23 +01:00
|
|
|
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; }");
|
2010-03-25 13:51:14 +01:00
|
|
|
//doTest("({x ? y, y ? x}: y) { }");
|
2010-03-25 14:10:04 +01:00
|
|
|
doTest("let x = 1; in x");
|
2010-03-25 15:51:04 +01:00
|
|
|
doTest("with { x = 1; }; x");
|
|
|
|
doTest("let x = 2; in with { x = 1; }; x"); // => 2
|
|
|
|
doTest("with { x = 1; }; with { x = 2; }; x"); // => 1
|
2010-03-25 16:38:37 +01:00
|
|
|
doTest("[ 1 2 3 ]");
|
|
|
|
doTest("[ 1 2 ] ++ [ 3 4 5 ]");
|
2010-03-26 14:27:26 +01:00
|
|
|
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");
|
2010-03-26 16:45:53 +01:00
|
|
|
doTest("true");
|
2010-03-30 16:39:27 +02:00
|
|
|
doTest("builtins.true");
|
2010-03-26 16:45:53 +01:00
|
|
|
doTest("true == false");
|
|
|
|
doTest("__head [ 1 2 3 ]");
|
|
|
|
doTest("__add 1 2");
|
2010-03-29 11:43:55 +02:00
|
|
|
doTest("null");
|
2010-03-30 16:39:27 +02:00
|
|
|
doTest("null");
|
2010-03-28 20:27:07 +02:00
|
|
|
doTest("\"foo\"");
|
|
|
|
doTest("let s = \"bar\"; in \"foo${s}\"");
|
2010-03-29 12:13:51 +02:00
|
|
|
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");
|
2010-03-30 11:22:33 +02:00
|
|
|
doTest("/etc/passwd");
|
2010-03-30 16:39:27 +02:00
|
|
|
//doTest("import ./foo.nix");
|
2010-03-30 15:47:59 +02:00
|
|
|
doTest("map (x: __add 1 x) [ 1 2 3 ]");
|
2010-03-30 16:39:27 +02:00
|
|
|
doTest("map (builtins.add 1) [ 1 2 3 ]");
|
2010-03-23 18:30:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void printHelp()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string programId = "eval-test";
|