tests: initial test suite for IR compiler

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I70cd1dfa45add9df58a44add69fbd30a6a6a6964
This commit is contained in:
raf 2026-02-21 20:48:08 +03:00
commit 49f64c9c98
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
28 changed files with 151 additions and 0 deletions

8
tests/attrset.nix Normal file
View file

@ -0,0 +1,8 @@
# Attrset test
{
name = "test";
value = 123;
nested = {
inner = true;
};
}

BIN
tests/attrset.nixir Normal file

Binary file not shown.

4
tests/attrset_var.nix Normal file
View file

@ -0,0 +1,4 @@
let
x = 10;
in
{ a = x; }

6
tests/comparison.nix Normal file
View file

@ -0,0 +1,6 @@
# Test comparison operators
let
a = 10;
b = 20;
in
if a < b then true else false

BIN
tests/comparison.nixir Normal file

Binary file not shown.

2
tests/if.nix Normal file
View file

@ -0,0 +1,2 @@
# Conditional test
if true then 1 else 2

BIN
tests/if.nixir Normal file

Binary file not shown.

17
tests/inherit.nix Normal file
View file

@ -0,0 +1,17 @@
# Test inherit keyword
let
x = 10;
y = 20;
attrs = { a = 1; b = 2; c = 3; };
in
{
# Basic inherit from outer scope
inherit x y;
# Inherit from expression
inherit (attrs) a b;
# Mixed
z = 30;
inherit (attrs) c;
}

4
tests/inherit_from.nix Normal file
View file

@ -0,0 +1,4 @@
let
attrs = { a = 1; };
in
{ inherit (attrs) a; }

4
tests/inherit_simple.nix Normal file
View file

@ -0,0 +1,4 @@
let
x = 10;
in
{ inherit x; }

36
tests/lambda_pattern.nix Normal file
View file

@ -0,0 +1,36 @@
# Test lambda patterns
let
# Basic destructuring
f1 = { a, b }: a + b;
# With default values
f2 = { a, b ? 10 }: a + b;
# With ellipsis (extra fields allowed)
f3 = { a, ... }: a * 2;
# Named pattern
f4 = arg@{ a, b }: a + b + arg.c;
# Simple lambda (not a pattern)
f5 = x: x + 1;
in
{
# Test basic destructuring
test1 = f1 { a = 3; b = 4; };
# Test with defaults (provide both)
test2a = f2 { a = 5; b = 6; };
# Test with defaults (use default for b)
test2b = f2 { a = 5; };
# Test ellipsis (extra field ignored)
test3 = f3 { a = 7; extra = 999; };
# Test named pattern
test4 = f4 { a = 1; b = 2; c = 3; };
# Test simple lambda
test5 = f5 10;
}

5
tests/let.nix Normal file
View file

@ -0,0 +1,5 @@
# Let binding test
let
x = 10;
y = 20;
in x

BIN
tests/let.nixir Normal file

Binary file not shown.

6
tests/logical.nix Normal file
View file

@ -0,0 +1,6 @@
# Test logical operators
let
x = true;
y = false;
in
if x && y then 1 else if x || y then 2 else 3

BIN
tests/logical.nixir Normal file

Binary file not shown.

6
tests/operators.nix Normal file
View file

@ -0,0 +1,6 @@
# Test arithmetic operators
let
x = 10;
y = 5;
in
(x + y) * 2

BIN
tests/operators.nixir Normal file

Binary file not shown.

8
tests/precedence.nix Normal file
View file

@ -0,0 +1,8 @@
# Test operator precedence
let
a = 1 + 2 * 3; # Should be 1 + (2 * 3) = 7
b = 10 - 5 - 2; # Should be (10 - 5) - 2 = 3
c = true && false || true; # Should be (true && false) || true = true
d = 1 < 2 && 3 > 2; # Should be (1 < 2) && (3 > 2) = true
in
{ a = a; b = b; c = c; d = d; }

BIN
tests/precedence.nixir Normal file

Binary file not shown.

11
tests/shortcircuit.nix Normal file
View file

@ -0,0 +1,11 @@
# Test short-circuit evaluation
let
alwaysFalse = false;
alwaysTrue = true;
x = 10;
in
{
and_false = alwaysFalse && alwaysTrue;
or_true = alwaysTrue || alwaysFalse;
impl_false = alwaysFalse -> alwaysFalse;
}

6
tests/shortcircuit2.nix Normal file
View file

@ -0,0 +1,6 @@
# Test short-circuit evaluation
{
and_false = false && true;
or_true = true || false;
impl_false = false -> false;
}

2
tests/simple.nix Normal file
View file

@ -0,0 +1,2 @@
# Simple constant test
42

BIN
tests/simple.nixir Normal file

Binary file not shown.

1
tests/simple_op.nix Normal file
View file

@ -0,0 +1 @@
1 + 2

BIN
tests/simple_op.nixir Normal file

Binary file not shown.

19
tests/string_interp.nix Normal file
View file

@ -0,0 +1,19 @@
# Test string interpolation
let
name = "world";
x = 42;
bool_val = true;
in
{
# Simple interpolation
greeting = "Hello ${name}!";
# Multiple interpolations
multi = "x is ${x} and name is ${name}";
# Nested expression
nested = "Result: ${if bool_val then "yes" else "no"}";
# Just a string (no interpolation)
plain = "plain text";
}

6
tests/unary.nix Normal file
View file

@ -0,0 +1,6 @@
# Test unary operators
let
x = 10;
y = true;
in
{ neg = -x; not = !y; }

BIN
tests/unary.nixir Normal file

Binary file not shown.