Skip to content

Commit

Permalink
Add tests for push priority operators
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham committed Oct 5, 2022
1 parent 50a1420 commit 7d6c1d1
Showing 1 changed file with 74 additions and 41 deletions.
115 changes: 74 additions & 41 deletions tests/pass/priorities.ncl
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

0 comments on commit 7d6c1d1

Please sign in to comment.