fix keyword separator in operations
This commit is contained in:
parent
f1f7668117
commit
ffcaaabeed
2 changed files with 11 additions and 2 deletions
7
lib.nix
7
lib.nix
|
@ -32,7 +32,8 @@ let
|
|||
getType = expr: if isAttrs expr && expr ? _type then expr._type else null;
|
||||
|
||||
validString = expr:
|
||||
if isString expr || isPath expr then toString expr
|
||||
if isRaw expr then validString expr.raw
|
||||
else if isString expr || isPath expr then toString expr
|
||||
else error "Value '${toString expr}' is not a valid string";
|
||||
|
||||
validFuncName = fnName:
|
||||
|
@ -93,7 +94,7 @@ let
|
|||
kw_while = raw "while";
|
||||
kw_repeat = raw "repeat";
|
||||
|
||||
op = operation: left: right: wrapParen (join " ${operation} " [ left right ]);
|
||||
op = operation: left: right: wrapParen (join " ${validString operation} " [ left right ]);
|
||||
|
||||
add = op "+";
|
||||
sub = op "-";
|
||||
|
@ -203,4 +204,6 @@ in
|
|||
# useful aliases
|
||||
var = raw;
|
||||
vars = map raw;
|
||||
|
||||
inherit validString;
|
||||
}
|
||||
|
|
|
@ -162,6 +162,12 @@ with nix2lua; pkgs.lib.runTests {
|
|||
(10 > 5)
|
||||
'';
|
||||
};
|
||||
"test returns rendered condition" = {
|
||||
expr = toLua (set "name"
|
||||
(and (gte (var "a") 1) (lte (var "a") 10))
|
||||
);
|
||||
expected = "name = ((a >= 1) and (a <= 10))";
|
||||
};
|
||||
"test returns defined function" = {
|
||||
expr = toLua (func "hello" [ "a" "b" ] [
|
||||
(eq (mul (add (var "a") 2) (sub 2 1)) 3)
|
||||
|
|
Loading…
Reference in a new issue