Skip to content

Commit 55b01a3

Browse files
committed
#762 Make sure the syntax error position matches the one reported in the error message.
1 parent 986055e commit 55b01a3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cobol-parser/src/test/scala/za/co/absa/cobrix/cobol/parser/parse/SyntaxErrorsSpec.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ class SyntaxErrorsSpec extends AnyFunSuite {
4646
assert(syntaxErrorException.msg.contains("The field is a leaf element"))
4747
}
4848

49+
test("Test handle malformed statement") {
50+
val copyBookContents: String =
51+
""" 01 RECORD.
52+
| 07 SUB-FLD1 PIC X(30).
53+
|""".stripMargin
54+
55+
val syntaxErrorException = intercept[SyntaxErrorException] {
56+
CopybookParser.parseTree(copyBookContents)
57+
}
58+
59+
assert(syntaxErrorException.lineNumber == 2)
60+
assert(syntaxErrorException.posOpt.contains(13))
61+
assert(syntaxErrorException.fieldOpt.isEmpty)
62+
assert(syntaxErrorException.msg == "Invalid input 'SUB-FLD1' at position 2:13")
63+
}
64+
4965
test("Test handle malformed redefines") {
5066
val copyBookContents: String =
5167
""" 01 RECORD.

0 commit comments

Comments
 (0)