|
| 1 | +package app.mendix.microflows.nested_if_statements_test |
| 2 | + |
| 3 | +import data.app.mendix.microflows.nested_if_statements |
| 4 | +import rego.v1 |
| 5 | + |
| 6 | +# Test data |
| 7 | +one_exclusive_split_with_no_nested_ifs := {"ObjectCollection": { |
| 8 | + "$Type": "Microflows$MicroflowObjectCollection", |
| 9 | + "Objects": [{ |
| 10 | + "$Type": "Microflows$ExpressionSplitCondition", |
| 11 | + "Caption": "no nested ifs", |
| 12 | + "SplitCondition": {"Expression": "if $Variable then a else b"}, |
| 13 | + }], |
| 14 | +}} |
| 15 | + |
| 16 | +multiple_exclusive_splits_with_no_nested_ifs := {"ObjectCollection": { |
| 17 | + "$Type": "Microflows$MicroflowObjectCollection", |
| 18 | + "Objects": [ |
| 19 | + { |
| 20 | + "$Type": "Microflows$ExpressionSplitCondition", |
| 21 | + "Caption": "ex spit 1 with no nested ifs", |
| 22 | + "SplitCondition": {"Expression": "if $Variable then a else b"}, |
| 23 | + }, |
| 24 | + { |
| 25 | + "$Type": "Microflows$ExpressionSplitCondition", |
| 26 | + "Caption": "ex split 2 with no nested ifs", |
| 27 | + "SplitCondition": {"Expression": "if $Variable then c else d"}, |
| 28 | + }, |
| 29 | + ], |
| 30 | +}} |
| 31 | + |
| 32 | +one_exclusive_split_with_else_if := {"ObjectCollection": { |
| 33 | + "$Type": "Microflows$MicroflowObjectCollection", |
| 34 | + "Objects": [{ |
| 35 | + "$Type": "Microflows$ExclusiveSplit", |
| 36 | + "Caption": "ex split with else-if", |
| 37 | + "SplitCondition": {"Expression": "if true then\n\tfalse\nelse if false then\n\ttrue\nelse false"}, |
| 38 | + }], |
| 39 | +}} |
| 40 | + |
| 41 | +one_exclusive_split_with_then_if := {"ObjectCollection": { |
| 42 | + "$Type": "Microflows$MicroflowObjectCollection", |
| 43 | + "Objects": [{ |
| 44 | + "$Type": "Microflows$ExclusiveSplit", |
| 45 | + "Caption": "ex split with then-if", |
| 46 | + "SplitCondition": {"Expression": "if a then if b then c else d else e"}, |
| 47 | + }], |
| 48 | +}} |
| 49 | + |
| 50 | +multiple_exclusive_splits_with_one_nested_if := {"ObjectCollection": { |
| 51 | + "$Type": "Microflows$MicroflowObjectCollection", |
| 52 | + "Objects": [ |
| 53 | + { |
| 54 | + "$Type": "Microflows$ExclusiveSplit", |
| 55 | + "Caption": "no nested ifs", |
| 56 | + "SplitCondition": {"Expression": "if $Variable then a else b"}, |
| 57 | + }, |
| 58 | + { |
| 59 | + "$Type": "Microflows$ExclusiveSplit", |
| 60 | + "Caption": "ex split with then-if", |
| 61 | + "SplitCondition": {"Expression": "if a then b else if c then d else e"}, |
| 62 | + }, |
| 63 | + ], |
| 64 | +}} |
| 65 | + |
| 66 | +# Test cases |
| 67 | +test_should_allow_when_no_exclusive_splits_with_nested_ifs if { |
| 68 | + nested_if_statements.allow with input as one_exclusive_split_with_no_nested_ifs |
| 69 | + nested_if_statements.allow with input as multiple_exclusive_splits_with_no_nested_ifs |
| 70 | +} |
| 71 | + |
| 72 | +test_should_deny_when_exclusive_splits_with_nested_ifs if { |
| 73 | + not nested_if_statements.allow with input as one_exclusive_split_with_else_if |
| 74 | + not nested_if_statements.allow with input as one_exclusive_split_with_then_if |
| 75 | + not nested_if_statements.allow with input as multiple_exclusive_splits_with_one_nested_if |
| 76 | +} |
0 commit comments