diff options
author | sterni <sternenseemann@systemli.org> | 2022-11-23T19·48+0100 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2022-12-02T14·06+0000 |
commit | 1ad777e3c76055c88f278d2b1f9a7a8fd905c82b (patch) | |
tree | 9448501e5b6afc70532a3025c10127db2cc7c2c2 | |
parent | 7bab0c26ee8d35488a98ff00474e1447bb14c699 (diff) |
test(tvix/eval): verify pointer equality checks r/5369
Change-Id: I9baf2810fbd5b6ee8bfe10fce5b64801a35c1d67 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7369 Reviewed-by: tazjin <tazjin@tvl.su> Reviewed-by: Adam Joseph <adam@westernsemico.com> Tested-by: BuildkiteCI
Diffstat (limited to '')
-rw-r--r-- | tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.exp | 1 | ||||
-rw-r--r-- | tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.nix | 46 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.exp new file mode 100644 index 000000000000..aec30f297af9 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.exp @@ -0,0 +1 @@ +[ true true true true false false false true true true true true true true true true false false ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.nix new file mode 100644 index 000000000000..206881d7d9c2 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-value-pointer-equality.nix @@ -0,0 +1,46 @@ +# For an explanation of this behavior see //tvix/docs/value-pointer-equality.md +let + # Some incomparable values + f = MC: "Boing"; + t = [ (throw "is a little blue man") ]; + a = { "with" = abort "headphones and a big smile."; }; + + # Aliases + f' = f; + t' = t; + a' = a; + + peq1 = a: b: [ a ] == [ b ]; + peq2 = a: b: { x = a; } == { x = b; }; +in + +[ + # pointer equality of functions + (peq1 f f) + (peq2 f f) + (peq1 f f') + (peq2 f f') + + # encapsulation is necessary for pointer equality + (f == f) + (f == f') + # works with != + ([ f ] != [ f' ]) + + # thunks that fail to evaluated wrapped in sets/lists + (peq1 t t) + (peq2 t t) + (peq1 a a) + (peq2 a a) + (peq1 t t') + (peq2 t t') + (peq1 a' a) + (peq2 a' a) + + # function equality with builtins.elem + (builtins.elem f [ 21 f 42 ]) + + # pointer inequality + (peq1 f (x: x)) + (peq2 (x: x) f) +] \ No newline at end of file |