Add tests for push priority operators
-let {Assert, ..} = import "testlib.ncl" in
+let {Assert, check, ..} = import "testlib.ncl" in
+[
let block1 = {
foo | default = 1,
bar = 1,
@@ -38,4 +39,36 @@ block1 & block2 & block3
y = 2,
z = 3,
d = 1,
-} | Assert
+ } | 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
