diff options
author | Matt Carmody <33763384+mattcarmody@users.noreply.github.com> | 2020-05-31 17:23:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-31 12:23:13 -0500 |
commit | 2952e92bcc4990580dee6f1d83b591700bc1fdc3 (patch) | |
tree | a2279840f4714f5048b4ae2b7fb3c7c3b5ad1fc5 | |
parent | 6f1b33cc7b9719c28178acf749f791d987484fe6 (diff) | |
download | pyparsing-git-2952e92bcc4990580dee6f1d83b591700bc1fdc3.tar.gz |
Add GoToColumn test (#217)
* Add GoToColumn test
* Update GoToColumn test with ptmcg's feedback
-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): |