add nix-unit tests

This commit is contained in:
Emile Clark-Boman 2026-01-27 17:48:26 +10:00
parent e31dc6dea8
commit 14f30ce5d7
2 changed files with 129 additions and 0 deletions

47
tests/default.nix Normal file
View file

@ -0,0 +1,47 @@
let
bootstrap = import ../nt/primitives/bootstrap;
nt = import ../nt {
mix = import ../nt/mix {
this = bootstrap;
};
# flake.nix passes `flake = inputs.self`
flake = builtins.getFlake ../.;
};
dummyTest = {
expr = 1;
expected = 1;
};
in {
testPass = dummyTest;
testMaybe = let
maybe-mod = import ./maybe.nix {this = bootstrap;};
inherit
(maybe-mod)
Maybe
Some
None
;
in {
expr = Some true;
expected = {
_''traps''_ = {
_'nt = {
derive = ["nt::&Maybe"];
instance = true;
ops = {
"nt::&Maybe" = {
unwrap = f: self: f self.${bootstrap.ntDynamicTrapdoorKey}.value;
};
};
req = {};
sig = "nt::Some";
};
_'ntDyn = {value = true;};
};
};
};
}

82
tests/maybe.nix Normal file
View file

@ -0,0 +1,82 @@
{this, ...}: let
inherit
(this)
ntTrapdoorKey
ntDynamicTrapdoorKey
;
inherit
(this.std)
enfImpls
;
inherit
(this.trapdoor)
mkTrapdoorFn
mkTrapdoorSet
openTrapdoor
;
in {
# NOTE: Maybe is used to simplify parsing Type/Class declarations
# NOTE: and therefore must be implemented manually
Maybe = let
meta = instance: {
sig = "nt::&Maybe";
derive = [];
ops = {};
req = {"nt::&Maybe" = ["unwrap"];};
};
in
mkTrapdoorFn {
default = {
unwrap = T:
assert enfImpls "nt::&Maybe" T "nt::&Maybe.unwrap";
(T |> openTrapdoor ntTrapdoorKey).ops."nt::&Maybe".unwrap;
};
unlock.${ntTrapdoorKey} = meta false;
};
Some = let
meta = instance: {
inherit instance;
sig = "nt::Some";
derive = ["nt::&Maybe"];
ops = {
"nt::&Maybe".unwrap = f: self: f self.${ntDynamicTrapdoorKey}.value;
};
req = {};
};
in
mkTrapdoorFn {
default = value:
mkTrapdoorSet {
default = {};
unlock = {
${ntTrapdoorKey} = meta true;
${ntDynamicTrapdoorKey} = {
inherit value;
};
};
};
unlock.${ntTrapdoorKey} = meta false;
};
None = let
meta = instance: {
inherit instance;
sig = "nt::None";
derive = ["nt::&Maybe"];
ops = {
"nt::&Maybe".map = f: self: self;
};
req = {};
};
in
mkTrapdoorFn {
default = mkTrapdoorSet ntTrapdoorKey {
default = {};
unlock = meta true;
};
unlock.${ntTrapdoorKey} = meta false;
};
}