-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for push priority operators
- Loading branch information
Showing
1 changed file
with
74 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,74 @@ | ||
let {Assert, ..} = import "testlib.ncl" in | ||
|
||
let block1 = { | ||
foo | default = 1, | ||
bar = 1, | ||
baz | force = 1, | ||
x | priority 10 = 1, | ||
y | priority -5 = 1, | ||
z | priority 0 = 1, | ||
d | default = 1, | ||
} in | ||
|
||
let block2 = { | ||
foo | priority -10 = 2, | ||
bar | priority 10 = 2, | ||
baz = 2, | ||
x | priority 11 = 2, | ||
y = 2, | ||
z | priority 10 = 2, | ||
|
||
} in | ||
|
||
let block3 = { | ||
foo | priority -10.1 = 3, | ||
bar | default = 3, | ||
baz | priority 1000 = 3, | ||
x | priority 12 = 3, | ||
y | priority -1 = 3, | ||
z | priority 50 = 3, | ||
} in | ||
|
||
block1 & block2 & block3 | ||
== { | ||
foo = 2, | ||
bar = 2, | ||
baz = 1, | ||
x = 3, | ||
y = 2, | ||
z = 3, | ||
d = 1, | ||
} | Assert | ||
let {Assert, check, ..} = import "testlib.ncl" in | ||
|
||
[ | ||
let block1 = { | ||
foo | default = 1, | ||
bar = 1, | ||
baz | force = 1, | ||
x | priority 10 = 1, | ||
y | priority -5 = 1, | ||
z | priority 0 = 1, | ||
d | default = 1, | ||
} in | ||
|
||
let block2 = { | ||
foo | priority -10 = 2, | ||
bar | priority 10 = 2, | ||
baz = 2, | ||
x | priority 11 = 2, | ||
y = 2, | ||
z | priority 10 = 2, | ||
|
||
} in | ||
|
||
let block3 = { | ||
foo | priority -10.1 = 3, | ||
bar | default = 3, | ||
baz | priority 1000 = 3, | ||
x | priority 12 = 3, | ||
y | priority -1 = 3, | ||
z | priority 50 = 3, | ||
} in | ||
|
||
block1 & block2 & block3 | ||
== { | ||
foo = 2, | ||
bar = 2, | ||
baz = 1, | ||
x = 3, | ||
y = 2, | ||
z = 3, | ||
d = 1, | ||
} | Assert, | ||
|
||
{foo | _push_default = 1} & {foo = 2} == {foo = 2} | Assert, | ||
{foo | _push_force = 1} & {foo = 2} == {foo = 1} | Assert, | ||
({foo = 1} | _push_default) & {foo = 2} == {foo = 2} | Assert, | ||
({foo = 1} | _push_force) & {foo = 2} == {foo = 1} | Assert, | ||
|
||
# Pushed priorities should only modifies fields without explicitly set priorities | ||
({foo | priority -1 = 1} | _push_force) & {foo = 2} == {foo = 2} | Assert, | ||
({foo | default = 1} | _push_force) & {foo = 2} == {foo = 2} | Assert, | ||
({foo | priority 1 = 1} | _push_default) & {foo = 2} == {foo = 1} | Assert, | ||
({foo | force = 1} | _push_default) & {foo = 2} == {foo = 1} | Assert, | ||
|
||
let x = { | ||
foo | force = "old", | ||
bar = { | ||
baz = "old", | ||
baz' = "old" | ||
} |> record.map (fun _name value => value) | ||
} in | ||
(x | _push_default) & {foo = "new", bar.baz = "new"} | ||
== { foo = "old", bar = {baz = "new", baz' = "old"}} | ||
| Assert, | ||
|
||
# Interaction of recursive overriding and push priorities | ||
let context = 1 in | ||
let x = { | ||
foo = context + 2 + bar, | ||
bar | default = 1, | ||
} in | ||
(x | _push_force) & {foo = 0, bar = 10} | ||
== {bar = 10, foo = 1 + 2 + 10} | Assert, | ||
] |> check |