aglinxinyuan commented on code in PR #6136:
URL: https://github.com/apache/texera/pull/6136#discussion_r3524376785
##########
common/pybuilder/src/test/scala/org/apache/texera/amber/pybuilder/PythonLexerUtilsSpec.scala:
##########
@@ -131,6 +131,25 @@ class PythonLexerUtilsSpec extends AnyFunSuite {
assert(state.isEmpty)
}
+ test(
+ "updateTripleQuotedStringState: an escaped quote inside an ordinary string
is not a boundary"
+ ) {
+ // Python: x = "a\"b" — the escaped " must not close the double-quoted
string
+ assert(PythonLexerUtils.updateTripleQuotedStringState("x = \"a\\\"b\"",
None).isEmpty)
+ // Python: y = 'a\'b' — same for a single-quoted string
+ assert(PythonLexerUtils.updateTripleQuotedStringState("y = 'a\\'b'",
None).isEmpty)
+ }
+
+ test("updateTripleQuotedStringState: a lone single-quoted string toggles
single-quote mode") {
+ // Python: name = 'abc' — opens then closes single-quote mode, leaving
no active delimiter
+ assert(PythonLexerUtils.updateTripleQuotedStringState("name = 'abc'",
None).isEmpty)
+ }
Review Comment:
Good point — strengthened it so single-quote handling actually affects the
result: `updateTripleQuotedStringState("a = '#' '''", None)` must now return
`Some("'''")`; if single-quote mode failed to toggle on, the `#` would
early-return as a comment and give `None` (a839175). Applied the same
trailing-delimiter technique to the escaped-quote test.
##########
common/pybuilder/src/test/scala/org/apache/texera/amber/pybuilder/PythonLexerUtilsSpec.scala:
##########
@@ -131,6 +131,25 @@ class PythonLexerUtilsSpec extends AnyFunSuite {
assert(state.isEmpty)
}
+ test(
+ "updateTripleQuotedStringState: an escaped quote inside an ordinary string
is not a boundary"
+ ) {
+ // Python: x = "a\"b" — the escaped " must not close the double-quoted
string
+ assert(PythonLexerUtils.updateTripleQuotedStringState("x = \"a\\\"b\"",
None).isEmpty)
+ // Python: y = 'a\'b' — same for a single-quoted string
+ assert(PythonLexerUtils.updateTripleQuotedStringState("y = 'a\\'b'",
None).isEmpty)
+ }
+
+ test("updateTripleQuotedStringState: a lone single-quoted string toggles
single-quote mode") {
+ // Python: name = 'abc' — opens then closes single-quote mode, leaving
no active delimiter
+ assert(PythonLexerUtils.updateTripleQuotedStringState("name = 'abc'",
None).isEmpty)
+ }
+
+ test("updateTripleQuotedStringState: a hash inside a double-quoted string is
not a comment") {
+ // Python: s = "a # b" + c — the # is inside the string, so scanning
must not early-return
+ assert(PythonLexerUtils.updateTripleQuotedStringState("s = \"a # b\" + c",
None).isEmpty)
+ }
Review Comment:
Same fix — the test now appends a triple-double so a wrong `#`-as-comment
early-return would flip the result: `updateTripleQuotedStringState("s = \"a #
b\" \"\"\"", None)` must return `Some("\"\"\"")` (a839175).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]