Skip to content

Commit

Permalink
test: verify new behaviour of special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpuppa committed Nov 14, 2023
1 parent ccd4e02 commit ebdb110
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/main/scala/org/camunda/feel/impl/parser/FeelParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -689,16 +689,17 @@ object FeelParser {
}.getOrElse(ConstNull)
}

// replace escaped character with the provided replacement
private def translateEscapes(input: String): String = {
val escapeMap = Map(
"\\b" -> "\b", // backspace
"\\t" -> "\t", // tab
"\\n" -> "\n", // newline
"\\f" -> "\f", // form feed
"\\r" -> "\r", // carriage return
"\\\"" -> "\"", // double quote
"\\'" -> "'", // single quote
"\\s" -> " " // Space character
"\\b" -> "\b",
"\\t" -> "\t",
"\\n" -> "\n",
"\\f" -> "\f",
"\\r" -> "\r",
"\"" -> "\"",
"\\'" -> "'",
"\\s" -> " "
// Add more escape sequences as needed
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import org.camunda.feel.syntaxtree._
import org.scalatest.matchers.should.Matchers
import org.scalatest.flatspec.AnyFlatSpec

import scala.collection.immutable.Map

/** @author
* Philipp Ossler
*/
Expand Down Expand Up @@ -78,10 +80,38 @@ class InterpreterStringExpressionTest
evaluateExpression(""" "a" != null """) should returnResult(true)
}

it should "return escaped characters" in {
it should "return not escaped characters" in {

evaluateExpression(""" "Hello\nWorld" """) should returnResult("Hello\nWorld")
evaluateExpression(" x ", Map("x" -> "Hello\nWorld")) should returnResult("Hello\nWorld")

evaluateExpression(""" "Hello\rWorld" """) should returnResult("Hello\rWorld")
evaluateExpression(" x ", Map("x" -> "Hello\rWorld")) should returnResult("Hello\rWorld")

evaluateExpression(""" "Hello\'World" """) should returnResult("Hello\'World")
evaluateExpression(" x ", Map("x" -> "Hello\'World")) should returnResult("Hello\'World")

evaluateExpression(""" "Hello\tWorld" """) should returnResult("Hello\tWorld")
evaluateExpression(" x ", Map("x" -> "Hello\tWorld")) should returnResult("Hello\tWorld")
}

List(
" \' ",
" \\\" ",
" \\ ",
" \n ",
" \r ",
" \t ",
""" \u269D """,
""" \U101EF """
)
.foreach { notEscapeChar =>
it should s"contains a not escape sequence ($notEscapeChar)" in {

evaluateExpression(s""" "a $notEscapeChar b" """) should returnResult(
s"""a $notEscapeChar b"""
)
}
}

}

0 comments on commit ebdb110

Please sign in to comment.