Skip to content

Commit

Permalink
chore: add match and loop tests #57 #51 #45
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Jun 14, 2023
1 parent f47e211 commit 619bce6
Show file tree
Hide file tree
Showing 26 changed files with 411 additions and 98 deletions.
27 changes: 27 additions & 0 deletions tackle/providers/logic/tests/match/block-loop-match-block.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

matcher: blocker

block->:
for: [1,2]
iter->: "{{item}}"
matches:
->: match matcher
case:
blocker->:
foo: bar
rendered->: "{{foo}}"
iter->: "{{item}}"
check->: "{{matches}}"

block_loop->:
for: [1,2]
iter->: "{{item}}"
matches:
->: match matcher
case:
blocker->:
for: [3,4]
foo: bar
rendered->: "{{foo}}"
iter->: "{{item}}"
check->: "{{matches}}"
33 changes: 33 additions & 0 deletions tackle/providers/logic/tests/match/block-match-block.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

matcher: blocker

block->:
stuff: things
render_inner->: "{{stuff}}"
render_outer->: "{{matcher}}"
matches:
->: match matcher
case:
blocker->:
foo: bar
render_inner->: "{{foo}}"
render_outer->: "{{matcher}}"
check->: "{{matches}}"

block_loop->:
foo: foo
matches:
->: match matcher
case:
blocker->:
for: [3,4]
foo: bar
render_inner->: "{{foo}}"
render_outer->: "{{matcher}}"
iter->: "{{item}}"
check->: "{{matches}}"

block_loop_output:
matches:
- foo: bar
# ...
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@

matcher_true: blocker_true
matcher: bock_true

matches_true:
->: match matcher_true
->: match matcher
case:
blocker_true->:
bock_true->:
if: true
value: True
a_dict:
stuff->: "{{cases}}"
stuff: things
dict:
stuff->: "{{stuff}}"
list:
- stuff
- things
hook-expanded:
->: literal expanded
hook-compact->: literal compact

matcher_false: blocker_false

# This should exist in output as empty key
matches_false:
->: match matcher_false
->: match matcher
case:
blocker_false->:
# This key should not exist
bock_true->:
if: false
value: True


expected:
value: True
stuff: things
dict:
stuff: things
list:
Expand All @@ -35,4 +39,4 @@ expected:
hook-expanded: expanded
hook-compact: compact

#assert->: assert "{{matches_true}}" "{{expected}}"
assert->: assert "{{matches_true}}" "{{expected}}"
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ matches:
- stuff
- things
value: True
a_dict:
stuff->: "{{case}}"
dict:
stuff->: "{{item}}"
list:
- stuff
- things
Expand Down
14 changes: 14 additions & 0 deletions tackle/providers/logic/tests/match/case-block-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
matcher: blocker

block:
->: match matcher
case:
blocker->:
merge: true
foo: bar

call:
->: match matcher --merge
case:
blocker->:
bar: bar
30 changes: 30 additions & 0 deletions tackle/providers/logic/tests/match/case-block.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

matcher: blocker

matches:
->: match matcher
case:
blocker->:
value: True
stuff: things
dict:
stuff->: "{{stuff}}"
list:
- stuff
- things
hook-expanded:
->: literal expanded
hook-compact->: literal compact

expected:
value: True
stuff: things
dict:
stuff: things
list:
- stuff
- things
hook-expanded: expanded
hook-compact: compact

assert->: assert "{{matches}}" "{{expected}}"
9 changes: 9 additions & 0 deletions tackle/providers/logic/tests/match/case-dict.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

matcher: blocker

matches:
->: match matcher
case:
blocker:
# Should not render
foo->: "{{bar}}"
4 changes: 2 additions & 2 deletions tackle/providers/logic/tests/match/cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fallback_dict:
hook-expanded:
->: print expanded
hook-compact->: print compact
'^foo': this
'^foo.*': this
'.*': foo

b_dict: foobar
Expand All @@ -17,5 +17,5 @@ matched_dict:
hook-expanded:
->: print expanded
hook-compact->: print compact
'^foo': this
'^foo.*': this
'.*': foo
31 changes: 31 additions & 0 deletions tackle/providers/logic/tests/match/default-hook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
foo: bar

normal_dict:
->: match foo
case:
->:
foo: bar
blah: blah
bar: bar


normal_dict_hook:
->: match foo
case:
->:
foo: bar
stuff:
->: literal things
blah: blah
bar:
foo: foo
stuff:
->: literal stuff


#hook_call:
# ->: match foo
# case:
# ->: literal foo
# foo: blah
# bar: bar
29 changes: 29 additions & 0 deletions tackle/providers/logic/tests/match/default-underscore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
foo: bar

normal_str:
->: match foo
case:
_: foo
blah: blah

normal_dict:
->: match foo
case:
_:
foo: bar
blah: blah

hook_call:
->: match foo
case:
_->: literal foo
blah: blah

normal_dict_hook:
->: match foo
case:
_:
foo: bar
stuff:
->: literal things
blah: blah
14 changes: 14 additions & 0 deletions tackle/providers/logic/tests/match/error-block-loop-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
matcher: blocker

block_loop_merge->:
foo: foo
matches:
->: match matcher
case:
blocker->:
# Should error because the parent is a map
merge: true
try: true
except: foo
for: [3,4]
foo: bar
9 changes: 9 additions & 0 deletions tackle/providers/logic/tests/match/error-malformed-regex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
foo: bar

error:
->: match foo
case:
blah: blah
'*->': var foo
# Should be this
# '.*->': var foo
18 changes: 7 additions & 11 deletions tackle/providers/logic/tests/match/lists.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
region: ams
region: r1

vms:
->: match region
case:
sng:
- ip: 139
r0:
- ip: 123
name: foo
ams:
- ip: 108
r1:
- ip: 456
name: bar
- ip: 209
name: stuff
- ip: 199
name: things
- ip: 95
name: baz

assert->: assert "{{vms[0].ip}}" 456
30 changes: 15 additions & 15 deletions tackle/providers/logic/tests/match/loop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cases:
- hook-dict
- hook-expanded
- hook-compact
# - block
- block

matches:
->: match
Expand All @@ -32,19 +32,19 @@ matches:
hook-expanded:
->: literal expanded
hook-compact->: literal compact
# block->:
# for:
# - stuff
# - things
# value: True
# a_dict:
# stuff->: "{{item}}"
# list:
# - stuff
# - things
# hook-expanded:
# ->: literal expanded
# hook-compact->: literal compact
block->:
for:
- stuff
- things
value: True
a_dict:
stuff->: "{{item}}"
list:
- stuff
- things
hook-expanded:
->: literal expanded
hook-compact->: literal compact


expected:
Expand Down Expand Up @@ -81,4 +81,4 @@ expected:
# hook-expanded: expanded
# hook-compact: compact

assert->: assert "{{matches}}" "{{expected}}"
#assert->: assert "{{matches}}" "{{expected}}"
Loading

0 comments on commit 619bce6

Please sign in to comment.