brewery
notashelf /
5e41a7cb370f9334859d7e2ebd56507b751f6a13

nixir

public

Import-resolving Nix IR plugin

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/nixir.git

Commit 5e41a7cb370f

tarball

NotAShelf <raf@notashelf.dev> · 2026-04-24 20:12 UTC

unverified6 files changed+156-7
tests: add tests for lookup paths and imports

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I7e54691aa3e81efcb495124d13e8c24a6a6a6964
diff --git a/tests/import_lookup.nix b/tests/import_lookup.nixnew file mode 100644index 0000000..448b1ea--- /dev/null+++ b/tests/import_lookup.nix@@ -0,0 +1,3 @@+# Test import with lookup path+# Common pattern: import <nixpkgs> { }+import <nixpkgs>diff --git a/tests/import_simple.nix b/tests/import_simple.nixnew file mode 100644index 0000000..023b49d--- /dev/null+++ b/tests/import_simple.nix@@ -0,0 +1,11 @@+# Test import expression+# Import evaluates the file and returns its value++# Import a file that returns a simple value (42)+import ./simple.nix++# Can also import lookup paths:+# import <nixpkgs> { }++# Import with path expressions:+# import (./dir + "/file.nix")diff --git a/tests/lookup_path.nix b/tests/lookup_path.nixnew file mode 100644index 0000000..e8bb4ca--- /dev/null+++ b/tests/lookup_path.nix@@ -0,0 +1,9 @@+# Test lookup path syntax+# Lookup paths resolve via NIX_PATH environment variable+# Example: <nixpkgs> -> /nix/var/nix/profiles/per-user/root/channels/nixpkgs++# Simple lookup path+<nixpkgs>++# Nested lookup path (common pattern)+# <nixpkgs/lib>diff --git a/tests/lookup_path_nested.nix b/tests/lookup_path_nested.nixnew file mode 100644index 0000000..0478b00--- /dev/null+++ b/tests/lookup_path_nested.nix@@ -0,0 +1,3 @@+# Test nested lookup path+# Common pattern in Nix: <nixpkgs/lib> or <nixpkgs/pkgs/stdenv>+<nixpkgs/lib>diff --git a/tests/regression_test.cpp b/tests/regression_test.cppindex 10123a0..1b4c4ce 100644--- a/tests/regression_test.cpp+++ b/tests/regression_test.cpp@@ -157,6 +157,116 @@ void test_parser_expect_in_speculative_parsing() {             << std::endl; } +void test_lookup_path_node() {+  std::cout << "> Lookup path serialization..." << std::endl;++  auto lookup = std::make_shared<Node>(ConstLookupPathNode("nixpkgs"));+  IRModule module;+  module.entry = lookup;++  Serializer ser;+  auto bytes = ser.serialize_to_bytes(module);++  Deserializer deser;+  auto loaded = deser.deserialize(bytes);++  auto *loaded_lookup = loaded.entry->get_if<ConstLookupPathNode>();+  TEST_CHECK(loaded_lookup != nullptr, "Deserialized node is ConstLookupPathNode");+  TEST_CHECK(loaded_lookup && loaded_lookup->value == "nixpkgs",+             "Lookup path value is 'nixpkgs'");+}++void test_import_node() {+  std::cout << "> Import node serialization..." << std::endl;++  auto path = std::make_shared<Node>(ConstPathNode("./test.nix"));+  auto import_node = std::make_shared<Node>(ImportNode(path));+  IRModule module;+  module.entry = import_node;++  Serializer ser;+  auto bytes = ser.serialize_to_bytes(module);++  Deserializer deser;+  auto loaded = deser.deserialize(bytes);++  auto *loaded_import = loaded.entry->get_if<ImportNode>();+  TEST_CHECK(loaded_import != nullptr, "Deserialized node is ImportNode");+  TEST_CHECK(loaded_import && loaded_import->path != nullptr,+             "Import node has path");++  if (loaded_import && loaded_import->path) {+    auto *path_node = loaded_import->path->get_if<ConstPathNode>();+    TEST_CHECK(path_node != nullptr, "Import path is ConstPathNode");+    TEST_CHECK(path_node && path_node->value == "./test.nix",+               "Import path value is './test.nix'");+  }+}++void test_import_with_lookup_path() {+  std::cout << "> Import with lookup path..." << std::endl;++  auto lookup = std::make_shared<Node>(ConstLookupPathNode("nixpkgs"));+  auto import_node = std::make_shared<Node>(ImportNode(lookup));+  IRModule module;+  module.entry = import_node;++  Serializer ser;+  auto bytes = ser.serialize_to_bytes(module);++  Deserializer deser;+  auto loaded = deser.deserialize(bytes);++  auto *loaded_import = loaded.entry->get_if<ImportNode>();+  TEST_CHECK(loaded_import != nullptr, "Deserialized node is ImportNode");++  if (loaded_import && loaded_import->path) {+    auto *lookup_node = loaded_import->path->get_if<ConstLookupPathNode>();+    TEST_CHECK(lookup_node != nullptr, "Import path is ConstLookupPathNode");+    TEST_CHECK(lookup_node && lookup_node->value == "nixpkgs",+               "Lookup path value is 'nixpkgs'");+  }+}++void test_uri_node() {+  std::cout << "> URI node serialization..." << std::endl;++  auto uri = std::make_shared<Node>(ConstURINode("https://example.com"));+  IRModule module;+  module.entry = uri;++  Serializer ser;+  auto bytes = ser.serialize_to_bytes(module);++  Deserializer deser;+  auto loaded = deser.deserialize(bytes);++  auto *loaded_uri = loaded.entry->get_if<ConstURINode>();+  TEST_CHECK(loaded_uri != nullptr, "Deserialized node is ConstURINode");+  TEST_CHECK(loaded_uri && loaded_uri->value == "https://example.com",+             "URI value is 'https://example.com'");+}++void test_float_node() {+  std::cout << "> Float node serialization..." << std::endl;++  auto float_val = std::make_shared<Node>(ConstFloatNode(3.14159));+  IRModule module;+  module.entry = float_val;++  Serializer ser;+  auto bytes = ser.serialize_to_bytes(module);++  Deserializer deser;+  auto loaded = deser.deserialize(bytes);++  auto *loaded_float = loaded.entry->get_if<ConstFloatNode>();+  TEST_CHECK(loaded_float != nullptr, "Deserialized node is ConstFloatNode");+  TEST_CHECK(loaded_float && loaded_float->value > 3.14 &&+                 loaded_float->value < 3.15,+             "Float value is approximately 3.14159");+}+ int main() {   std::cout << "=== Regression Tests for Nixir ===" << std::endl << std::endl; @@ -178,6 +288,21 @@ int main() {   test_parser_expect_in_speculative_parsing();   std::cout << std::endl; +  test_lookup_path_node();+  std::cout << std::endl;++  test_import_node();+  std::cout << std::endl;++  test_import_with_lookup_path();+  std::cout << std::endl;++  test_uri_node();+  std::cout << std::endl;++  test_float_node();+  std::cout << std::endl;+   std::cout << "=== Tests Complete ===" << std::endl;   std::cout << "Failures: " << failures << std::endl;   return failures > 0 ? 1 : 0;diff --git a/tests/string_interp.nix b/tests/string_interp.nixindex af7b42d..9edc11b 100644--- a/tests/string_interp.nix+++ b/tests/string_interp.nix@@ -10,13 +10,11 @@ in {   # Multiple interpolations   multi = "x is ${x} and name is ${name}"; -  # Nested expression-  nested = "Result: ${-    if bool_val-    then "yes"-    else "no"-  }";+  # Expression evaluation in interpolation+  computed = "x + 10 = ${x + 10}"; -  # Just a string (no interpolation)+  bool_check = "${bool_val} is true!";++  # Just a string, no interpolation   plain = "plain text"; }