From 7d6c1d1b848904c8abab24bbdc5919baf8cd968c Mon Sep 17 00:00:00 2001 From: Yann Hamdaoui Date: Tue, 4 Oct 2022 16:57:19 +0200 Subject: [PATCH] Add tests for push priority operators --- tests/pass/priorities.ncl | 115 ++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 41 deletions(-) diff --git a/tests/pass/priorities.ncl b/tests/pass/priorities.ncl index 81c7084973..e1eaa9babe 100644 --- a/tests/pass/priorities.ncl +++ b/tests/pass/priorities.ncl @@ -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