diff options
-rw-r--r-- | tests/test_unit.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_unit.py b/tests/test_unit.py index 05ff858..b16da18 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -7542,6 +7542,44 @@ class Test2_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase): result, expected, msg="issue with OnlyOnce after reset" ) + def testGoToColumn(self): + """tests for GoToColumn class""" + + dateExpr = pp.Regex(r"\d\d(\.\d\d){2}")("date") + numExpr = ppc.number("num") + + sample = """\ + date Not Important value NotImportant2 + 11.11.13 | useless . useless,21 useless 2 | 14.21 | asmdakldm + 21.12.12 | fmpaosmfpoamsp 4 | 41 | ajfa9si90""".splitlines() + + # Column number finds match + patt = dateExpr + pp.GoToColumn(70).ignore("|") + numExpr + pp.restOfLine + + infile = iter(sample) + next(infile) + + expecteds = [["11.11.13", 14.21], ["21.12.12", 41]] + for line, expected in zip(infile, expecteds): + result = patt.parseString(line) + print(result) + + self.assertEqual( + [result.date, result.num], expected, msg="issue with GoToColumn" + ) + + # Column number does NOT match + patt = dateExpr("date") + pp.GoToColumn(30) + numExpr + pp.restOfLine + + infile = iter(sample) + next(infile) + + for line in infile: + with self.assertRaisesParseException( + msg="issue with GoToColumn not finding match" + ): + result = patt.parseString(line) + class Test3_EnablePackratParsing(TestCase): def runTest(self): |