mirror of
https://github.com/NixOS/nix.git
synced 2025-12-08 18:11:02 +01:00
test: add tests for function equality behavior
Add tests for function equality covering both direct comparisons and comparisons within composite types (lists and attribute sets). Tests verify: - Direct function comparisons always return false - Value identity optimization in composite types allows identical functions to compare as equal when both references point to the same function value
This commit is contained in:
parent
97a60c1fab
commit
6fb5276e7b
12 changed files with 37 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
false
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Distinct but not identical functions in attribute set compare as unequal
|
||||
# See https://nix.dev/manual/nix/latest/language/operators#equality
|
||||
{ a = (x: x); } == { a = (x: x); }
|
||||
|
|
@ -0,0 +1 @@
|
|||
true
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# Function comparison in attribute set uses value identity optimization
|
||||
# See https://nix.dev/manual/nix/latest/language/operators#value-identity-optimization
|
||||
let
|
||||
f = x: x;
|
||||
in
|
||||
{
|
||||
a = f;
|
||||
} == {
|
||||
a = f;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
false
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Direct comparison of distinct but not identical functions returns false
|
||||
# See https://nix.dev/manual/nix/latest/language/operators#equality
|
||||
(x: x) == (x: x)
|
||||
|
|
@ -0,0 +1 @@
|
|||
false
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# Direct comparison of identical function returns false
|
||||
# See https://nix.dev/manual/nix/latest/language/operators#equality
|
||||
let
|
||||
f = x: x;
|
||||
in
|
||||
f == f
|
||||
|
|
@ -0,0 +1 @@
|
|||
false
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Distinct but not identical functions in list compare as unequal
|
||||
# See https://nix.dev/manual/nix/latest/language/operators#equality
|
||||
[ (x: x) ] == [ (x: x) ]
|
||||
|
|
@ -0,0 +1 @@
|
|||
true
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# Function comparison in list uses value identity optimization
|
||||
# See https://nix.dev/manual/nix/latest/language/operators#value-identity-optimization
|
||||
let
|
||||
f = x: x;
|
||||
in
|
||||
[ f ] == [ f ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue