|
| 1 | +package com.regnosys.rosetta.generator.python.expressions; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 4 | + |
| 5 | +import com.regnosys.rosetta.generator.python.PythonGeneratorTestUtils; |
| 6 | +import com.regnosys.rosetta.tests.RosettaInjectorProvider; |
| 7 | +import org.eclipse.xtext.testing.InjectWith; |
| 8 | +import org.eclipse.xtext.testing.extensions.InjectionExtension; |
| 9 | + |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 12 | +import jakarta.inject.Inject; |
| 13 | + |
| 14 | +@ExtendWith(InjectionExtension.class) |
| 15 | +@InjectWith(RosettaInjectorProvider.class) |
| 16 | +public class RosettaExistsExpressionTest { |
| 17 | + |
| 18 | + @Inject |
| 19 | + private PythonGeneratorTestUtils testUtils; |
| 20 | + |
| 21 | + @Test |
| 22 | + public void setUp() { |
| 23 | + String pythonString = testUtils.generatePythonFromString( |
| 24 | + """ |
| 25 | + type Foo: |
| 26 | + bar Bar (0..*) |
| 27 | + baz Baz (0..1) |
| 28 | +
|
| 29 | + type Bar: |
| 30 | + before number (0..1) |
| 31 | + after number (0..1) |
| 32 | + other number (0..1) |
| 33 | + beforeWithScheme number (0..1) |
| 34 | + [metadata scheme] |
| 35 | + afterWithScheme number (0..1) |
| 36 | + [metadata scheme] |
| 37 | + beforeList number (0..*) |
| 38 | + afterList number (0..*) |
| 39 | + beforeListWithScheme number (0..*) |
| 40 | + [metadata scheme] |
| 41 | + afterListWithScheme number (0..*) |
| 42 | + [metadata scheme] |
| 43 | +
|
| 44 | + type Baz: |
| 45 | + bazValue number (0..1) |
| 46 | + other number (0..1) |
| 47 | +
|
| 48 | + func Exists: |
| 49 | + inputs: foo Foo (1..1) |
| 50 | + output: result boolean (1..1) |
| 51 | + set result: |
| 52 | + foo -> bar -> before exists |
| 53 | +
|
| 54 | + func SingleExists: |
| 55 | + inputs: foo Foo (1..1) |
| 56 | + output: result boolean (1..1) |
| 57 | + set result: |
| 58 | + foo -> bar -> before single exists |
| 59 | +
|
| 60 | + func MultipleExists: |
| 61 | + inputs: foo Foo (1..1) |
| 62 | + output: result boolean (1..1) |
| 63 | + set result: |
| 64 | + foo -> bar -> before multiple exists |
| 65 | +
|
| 66 | + func OnlyExists: |
| 67 | + inputs: foo Foo (1..1) |
| 68 | + output: result boolean (1..1) |
| 69 | + set result: |
| 70 | + foo -> bar -> before only exists |
| 71 | +
|
| 72 | + func OnlyExistsMultiplePaths: |
| 73 | + inputs: foo Foo (1..1) |
| 74 | + output: result boolean (1..1) |
| 75 | + set result: |
| 76 | + ( foo -> bar -> before, foo -> bar -> after ) only exists |
| 77 | +
|
| 78 | + func OnlyExistsPathWithScheme: |
| 79 | + inputs: foo Foo (1..1) |
| 80 | + output: result boolean (1..1) |
| 81 | + set result: |
| 82 | + ( foo -> bar -> before, foo -> bar -> afterWithScheme ) only exists |
| 83 | +
|
| 84 | + func OnlyExistsBothPathsWithScheme: |
| 85 | + inputs: foo Foo (1..1) |
| 86 | + output: result boolean (1..1) |
| 87 | + set result: |
| 88 | + ( foo -> bar -> beforeWithScheme, foo -> bar -> afterWithScheme ) only exists |
| 89 | +
|
| 90 | + func OnlyExistsListMultiplePaths: |
| 91 | + inputs: foo Foo (1..1) |
| 92 | + output: result boolean (1..1) |
| 93 | + set result: |
| 94 | + ( foo -> bar -> before, foo -> bar -> afterList ) only exists |
| 95 | +
|
| 96 | + func OnlyExistsListPathWithScheme: |
| 97 | + inputs: foo Foo (1..1) |
| 98 | + output: result boolean (1..1) |
| 99 | + set result: |
| 100 | + ( foo -> bar -> before, foo -> bar -> afterListWithScheme ) only exists |
| 101 | +
|
| 102 | + func OnlyExistsListBothPathsWithScheme: |
| 103 | + inputs: foo Foo (1..1) |
| 104 | + output: result boolean (1..1) |
| 105 | + set result: |
| 106 | + ( foo -> bar -> beforeListWithScheme, foo -> bar -> afterListWithScheme ) only exists |
| 107 | +
|
| 108 | + // TODO tests compilation only, add unit test |
| 109 | + func MultipleSeparateOr_NoAliases_Exists: |
| 110 | + inputs: foo Foo (1..1) |
| 111 | + output: result boolean (1..1) |
| 112 | + set result: |
| 113 | + foo -> bar -> before exists or foo -> bar -> after exists |
| 114 | +
|
| 115 | + // TODO tests compilation only, add unit test |
| 116 | + func MultipleOr_NoAliases_Exists: |
| 117 | + inputs: foo Foo (1..1) |
| 118 | + output: result boolean (1..1) |
| 119 | + set result: |
| 120 | + foo -> bar -> before exists or foo -> bar -> after exists or foo -> baz -> other exists |
| 121 | +
|
| 122 | + // TODO tests compilation only, add unit test |
| 123 | + func MultipleOrBranchNode_NoAliases_Exists: |
| 124 | + inputs: foo Foo (1..1) |
| 125 | + output: result boolean (1..1) |
| 126 | + set result: |
| 127 | + foo -> bar exists or foo -> baz exists |
| 128 | +
|
| 129 | + // TODO tests compilation only, add unit test |
| 130 | + func MultipleAnd_NoAliases_Exists: |
| 131 | + inputs: foo Foo (1..1) |
| 132 | + output: result boolean (1..1) |
| 133 | + set result: |
| 134 | + foo -> bar -> before exists and foo -> bar -> after exists and foo -> baz -> other exists |
| 135 | +
|
| 136 | + // TODO tests compilation only, add unit test |
| 137 | + func MultipleOrAnd_NoAliases_Exists: |
| 138 | + inputs: foo Foo (1..1) |
| 139 | + output: result boolean (1..1) |
| 140 | + set result: |
| 141 | + foo -> bar -> before exists or ( foo -> bar -> after exists and foo -> baz -> other exists ) |
| 142 | +
|
| 143 | + // TODO tests compilation only, add unit test |
| 144 | + func MultipleOrAnd_NoAliases_Exists2: |
| 145 | + inputs: foo Foo (1..1) |
| 146 | + output: result boolean (1..1) |
| 147 | + set result: |
| 148 | + (foo -> bar -> before exists and foo -> bar -> after exists) or foo -> baz -> other exists or foo -> baz -> bazValue exists |
| 149 | +
|
| 150 | + // TODO tests compilation only, add unit test |
| 151 | + func MultipleOrAnd_NoAliases_Exists3: |
| 152 | + inputs: foo Foo (1..1) |
| 153 | + output: result boolean (1..1) |
| 154 | + set result: |
| 155 | + (foo -> bar -> before exists or foo -> bar -> after exists) or (foo -> baz -> other exists and foo -> baz -> bazValue exists) |
| 156 | +
|
| 157 | + // TODO tests compilation only, add unit test |
| 158 | + func MultipleExistsWithOrAnd: |
| 159 | + inputs: foo Foo (1..1) |
| 160 | + output: result boolean (1..1) |
| 161 | + set result: |
| 162 | + foo -> bar -> before exists or ( foo -> baz -> other exists and foo -> bar -> after exists ) or foo -> baz -> bazValue exists |
| 163 | + """) |
| 164 | + .toString(); |
| 165 | + |
| 166 | + assertFalse(pythonString.isEmpty(), "Generated Python string should not be empty"); |
| 167 | + } |
| 168 | +} |
0 commit comments