|
16 | 16 | */ |
17 | 17 | package org.camunda.feel.impl.interpreter |
18 | 18 |
|
19 | | -import org.camunda.feel.impl.FeelIntegrationTest |
| 19 | +import org.camunda.feel.impl.{EvaluationResultMatchers, FeelEngineTest, FeelIntegrationTest} |
20 | 20 | import org.camunda.feel.syntaxtree._ |
21 | 21 | import org.scalatest.matchers.should.Matchers |
22 | 22 | import org.scalatest.flatspec.AnyFlatSpec |
| 23 | +import org.scalatest.prop.TableDrivenPropertyChecks |
| 24 | + |
| 25 | +import scala.collection.immutable.Map |
23 | 26 |
|
24 | 27 | /** @author |
25 | 28 | * Philipp Ossler |
26 | 29 | */ |
27 | | -class InterpreterStringExpressionTest extends AnyFlatSpec with Matchers with FeelIntegrationTest { |
| 30 | +class InterpreterStringExpressionTest |
| 31 | + extends AnyFlatSpec |
| 32 | + with Matchers |
| 33 | + with FeelEngineTest |
| 34 | + with EvaluationResultMatchers |
| 35 | + with TableDrivenPropertyChecks { |
28 | 36 |
|
29 | 37 | "A string" should "concatenates to another String" in { |
30 | 38 |
|
31 | | - eval(""" "a" + "b" """) should be(ValString("ab")) |
| 39 | + evaluateExpression(""" "a" + "b" """) should returnResult("ab") |
32 | 40 | } |
33 | 41 |
|
34 | 42 | it should "compare with '='" in { |
35 | 43 |
|
36 | | - eval(""" "a" = "a" """) should be(ValBoolean(true)) |
37 | | - eval(""" "a" = "b" """) should be(ValBoolean(false)) |
| 44 | + evaluateExpression(""" "a" = "a" """) should returnResult(true) |
| 45 | + evaluateExpression(""" "a" = "b" """) should returnResult(false) |
38 | 46 | } |
39 | 47 |
|
40 | 48 | it should "compare with '!='" in { |
41 | 49 |
|
42 | | - eval(""" "a" != "a" """) should be(ValBoolean(false)) |
43 | | - eval(""" "a" != "b" """) should be(ValBoolean(true)) |
| 50 | + evaluateExpression(""" "a" != "a" """) should returnResult(false) |
| 51 | + evaluateExpression(""" "a" != "b" """) should returnResult(true) |
44 | 52 | } |
45 | 53 |
|
46 | 54 | it should "compare with '<'" in { |
47 | 55 |
|
48 | | - eval(""" "a" < "b" """) should be(ValBoolean(true)) |
49 | | - eval(""" "b" < "a" """) should be(ValBoolean(false)) |
| 56 | + evaluateExpression(""" "a" < "b" """) should returnResult(true) |
| 57 | + evaluateExpression(""" "b" < "a" """) should returnResult(false) |
50 | 58 | } |
51 | 59 |
|
52 | 60 | it should "compare with '<='" in { |
53 | 61 |
|
54 | | - eval(""" "a" <= "a" """) should be(ValBoolean(true)) |
55 | | - eval(""" "b" <= "a" """) should be(ValBoolean(false)) |
| 62 | + evaluateExpression(""" "a" <= "a" """) should returnResult(true) |
| 63 | + evaluateExpression(""" "b" <= "a" """) should returnResult(false) |
56 | 64 | } |
57 | 65 |
|
58 | 66 | it should "compare with '>'" in { |
59 | 67 |
|
60 | | - eval(""" "b" > "a" """) should be(ValBoolean(true)) |
61 | | - eval(""" "a" > "b" """) should be(ValBoolean(false)) |
| 68 | + evaluateExpression(""" "b" > "a" """) should returnResult(true) |
| 69 | + evaluateExpression(""" "a" > "b" """) should returnResult(false) |
62 | 70 | } |
63 | 71 |
|
64 | 72 | it should "compare with '>='" in { |
65 | 73 |
|
66 | | - eval(""" "b" >= "b" """) should be(ValBoolean(true)) |
67 | | - eval(""" "a" >= "b" """) should be(ValBoolean(false)) |
| 74 | + evaluateExpression(""" "b" >= "b" """) should returnResult(true) |
| 75 | + evaluateExpression(""" "a" >= "b" """) should returnResult(false) |
68 | 76 | } |
69 | 77 |
|
70 | 78 | it should "compare with null" in { |
71 | 79 |
|
72 | | - eval(""" "a" = null """) should be(ValBoolean(false)) |
73 | | - eval(""" null = "a" """) should be(ValBoolean(false)) |
74 | | - eval(""" "a" != null """) should be(ValBoolean(true)) |
| 80 | + evaluateExpression(""" "a" = null """) should returnResult(false) |
| 81 | + evaluateExpression(""" null = "a" """) should returnResult(false) |
| 82 | + evaluateExpression(""" "a" != null """) should returnResult(true) |
75 | 83 | } |
76 | 84 |
|
77 | | - it should "return not escaped characters" in { |
78 | | - |
79 | | - eval(""" "Hello\nWorld" """) should be(ValString("Hello\nWorld")) |
80 | | - eval(" x ", Map("x" -> "Hello\nWorld")) should be(ValString("Hello\nWorld")) |
| 85 | + private val escapeSequences = Table( |
| 86 | + ("Character", "Expected", "Display name"), |
| 87 | + ('\n', '\n', "new line"), |
| 88 | + ('\r', '\r', "carriage return"), |
| 89 | + ('\t', '\t', "tab"), |
| 90 | + ('\b', '\b', "backspace"), |
| 91 | + ('\f', '\f', "form feed"), |
| 92 | + ('\'', '\'', "single quote"), |
| 93 | + ("\\\"", '"', "double quote"), |
| 94 | + ("\\\\", '\\', "backslash") |
| 95 | + ) |
81 | 96 |
|
82 | | - eval(""" "Hello\rWorld" """) should be(ValString("Hello\rWorld")) |
83 | | - eval(" x ", Map("x" -> "Hello\rWorld")) should be(ValString("Hello\rWorld")) |
| 97 | + it should "contains an escape sequence" in { |
| 98 | + forEvery(escapeSequences) { (character, expected, _) => |
| 99 | + val expectedString = s"a $expected b" |
84 | 100 |
|
85 | | - eval(""" "Hello\'World" """) should be(ValString("Hello\'World")) |
86 | | - eval(" x ", Map("x" -> "Hello\'World")) should be(ValString("Hello\'World")) |
| 101 | + evaluateExpression(s" \"a $character b\" ") should returnResult(expectedString) |
| 102 | + evaluateExpression("char", Map("char" -> expectedString)) should returnResult(expectedString) |
| 103 | + } |
| 104 | + } |
87 | 105 |
|
88 | | - eval(""" "Hello\tWorld" """) should be(ValString("Hello\tWorld")) |
89 | | - eval(" x ", Map("x" -> "Hello\tWorld")) should be(ValString("Hello\tWorld")) |
| 106 | + private val unicodeCharacters = Table( |
| 107 | + ("Character", "Display name"), |
| 108 | + ('\u269D', "\\u269D"), |
| 109 | + ("\\U101EF", "\\U101EF") |
| 110 | + ) |
90 | 111 |
|
91 | | - eval(""" "Hello\"World" """) should be(ValString("Hello\"World")) |
92 | | - eval(" x ", Map("x" -> "Hello\"World")) should be(ValString("Hello\"World")) |
| 112 | + it should "contains unicode characters" in { |
| 113 | + forEvery(unicodeCharacters) { (character, _) => |
| 114 | + evaluateExpression(s" \"a $character b\" ") should returnResult(s"a $character b") |
| 115 | + } |
93 | 116 | } |
94 | 117 |
|
95 | | - List( |
96 | | - " \' ", |
97 | | - " \\ ", |
98 | | - " \n ", |
99 | | - " \r ", |
100 | | - " \t ", |
101 | | - """ \u269D """, |
102 | | - """ \U101EF """ |
| 118 | + private val regexCharacters = Table( |
| 119 | + ("Character", "Display name"), |
| 120 | + ("\\s", "\\s"), |
| 121 | + ("\\S", "\\S"), |
| 122 | + ("\\d", "\\d"), |
| 123 | + ("\\w", "\\w"), |
| 124 | + ("\\R", "\\R"), |
| 125 | + ("\\h", "\\h"), |
| 126 | + ("\\v", "\\v"), |
| 127 | + ("\\\n", "\\n"), |
| 128 | + ("\\\r", "\\r") |
103 | 129 | ) |
104 | | - .foreach { notEscapeChar => |
105 | | - it should s"contains a not escape sequence ($notEscapeChar)" in { |
106 | | - |
107 | | - eval(s""" "a $notEscapeChar b" """) should be( |
108 | | - ValString( |
109 | | - s"""a $notEscapeChar b""" |
110 | | - ) |
111 | | - ) |
112 | | - } |
| 130 | + |
| 131 | + it should "contains a regex character" in { |
| 132 | + forEvery(regexCharacters) { (character, _) => |
| 133 | + val expectedString = s"a $character b" |
| 134 | + |
| 135 | + evaluateExpression(s" \"a $character b\" ") should returnResult(expectedString) |
| 136 | + evaluateExpression("char", Map("char" -> expectedString)) should returnResult(expectedString) |
113 | 137 | } |
| 138 | + } |
114 | 139 |
|
115 | 140 | } |
0 commit comments