Skip to content

Commit

Permalink
Adjust to adhere to Scala 2.13 + FastParse 2.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyCat committed Mar 1, 2024
1 parent dec22ff commit 1cb8b12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions jvm/src/test/scala/io/kaitai/struct/exprlang/ExpressionsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -395,61 +395,61 @@ class ExpressionsSpec extends AnyFunSpec {

describe("f-strings") {
it("parses f-string with just a string") {
Expressions.parse("f\"abc\"") should be(InterpolatedStr(ArrayBuffer(
Expressions.parse("f\"abc\"") should be(InterpolatedStr(Seq(
Str("abc")
)))
}

it("parses f-string with just one expression") {
Expressions.parse("f\"{123}\"") should be(InterpolatedStr(ArrayBuffer(
Expressions.parse("f\"{123}\"") should be(InterpolatedStr(Seq(
IntNum(123)
)))
}

it("parses f-string with string + expression") {
Expressions.parse("f\"foo={123}\"") should be(InterpolatedStr(ArrayBuffer(
Expressions.parse("f\"foo={123}\"") should be(InterpolatedStr(Seq(
Str("foo="),
IntNum(123)
)))
}

it("parses f-string with expression + string") {
Expressions.parse("f\"{123}=abc\"") should be(InterpolatedStr(ArrayBuffer(
Expressions.parse("f\"{123}=abc\"") should be(InterpolatedStr(Seq(
IntNum(123),
Str("=abc")
)))
}

it("parses f-string with str + expression + str") {
Expressions.parse("f\"abc={123}=def\"") should be(InterpolatedStr(ArrayBuffer(
Expressions.parse("f\"abc={123}=def\"") should be(InterpolatedStr(Seq(
Str("abc="),
IntNum(123),
Str("=def")
)))
}

it("parses f-string string with newline in the middle") {
Expressions.parse("f\"abc\\ndef\"") should be(InterpolatedStr(ArrayBuffer(Str("abc\ndef"))))
Expressions.parse("f\"abc\\ndef\"") should be(InterpolatedStr(Seq(Str("abc\ndef"))))
}

it("parses f-string with double quote in the middle") {
Expressions.parse("f\"this \\\" is a quote\"") should be(InterpolatedStr(ArrayBuffer(
Expressions.parse("f\"this \\\" is a quote\"") should be(InterpolatedStr(Seq(
Str("this \" is a quote")
)))
}

it("parses f-string with string in it") {
Expressions.parse("f\"abc{\"def\"}ghi\"") should be(InterpolatedStr(ArrayBuffer(
Expressions.parse("f\"abc{\"def\"}ghi\"") should be(InterpolatedStr(Seq(
Str("abc"),
Str("def"),
Str("ghi"),
)))
}

it("parses f-string with f-string in it") {
Expressions.parse("f\"abc{f\"def\"}ghi\"") should be(InterpolatedStr(ArrayBuffer(
Expressions.parse("f\"abc{f\"def\"}ghi\"") should be(InterpolatedStr(Seq(
Str("abc"),
InterpolatedStr(ArrayBuffer(Str("def"))),
InterpolatedStr(Seq(Str("def"))),
Str("ghi"),
)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object Expressions {
def fstring[$: P]: P[Ast.expr.InterpolatedStr] = P("f\"" ~/ fstringElement.rep ~ "\"").map(Ast.expr.InterpolatedStr)
def fstringElement[$: P]: P[Ast.expr] = P(
formatExpr |
Lexical.fstringItem.repX(min = 1).
Lexical.fstringItem.repX(1).
map(_.mkString).
map(Ast.expr.Str)
)
Expand Down

0 comments on commit 1cb8b12

Please sign in to comment.