diff --git a/puppetparser/parser.py b/puppetparser/parser.py index 4f197d6..fead0ff 100644 --- a/puppetparser/parser.py +++ b/puppetparser/parser.py @@ -15,7 +15,7 @@ class InvalidPuppetScript(Exception): def find_column(input: str, pos: int) -> int: rfind = input.rfind("\n", 0, pos) if rfind == -1: - return pos + return pos + 1 line_start = rfind + 1 return (pos - line_start) + 1 diff --git a/pyproject.toml b/pyproject.toml index 056e225..faaa310 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "puppetparser" -version = "0.2.4" +version = "0.2.5" description = "A parser from Puppet to an object model" authors = ["Nuno Saavedra "] license = "GPL-3.0" diff --git a/tests/test_assignment.py b/tests/test_assignment.py index dac6fa2..ee45ed2 100644 --- a/tests/test_assignment.py +++ b/tests/test_assignment.py @@ -6,8 +6,8 @@ class TestClass(unittest.TestCase): - def test_assignment(self): - code = """ + def test_assignment_node(self): + code = """$a = 1 node "webserver" { $hello = 123 package { 'apache2': @@ -22,21 +22,29 @@ def test_assignment(self): """ res = parse(code)[0] - self.assertIsInstance(res[0], Node) - self.assertEqual(res[0].name, "webserver") - self.assertEqual(len(res[0].block), 3) - self.assertIsInstance(res[0].block[0], Assignment) - self.assertEqual(res[0].block[0].name, "$hello") - self.assertEqual(res[0].block[0].value.value, 123) - self.assertIsInstance(res[0].block[1], Resource) - self.assertIsInstance(res[0].block[2], Resource) - self.assertEqual(res[0].block[0].line, 3) - self.assertEqual(res[0].block[0].col, 17) - self.assertEqual(res[0].block[0].end_col, 29) - self.assertEqual(res[0].block[1].line, 4) - self.assertEqual(res[0].block[1].col, 17) - self.assertEqual(res[0].block[1].end_line, 6) - self.assertEqual(res[0].block[1].end_col, 18) + + self.assertEqual(res[0].name, "$a") + self.assertEqual(res[0].value.value, 1) + self.assertEqual(res[0].line, 1) + self.assertEqual(res[0].end_line, 1) + self.assertEqual(res[0].col, 1) + self.assertEqual(res[0].end_col, 7) + + self.assertIsInstance(res[1], Node) + self.assertEqual(res[1].name, "webserver") + self.assertEqual(len(res[1].block), 3) + self.assertIsInstance(res[1].block[0], Assignment) + self.assertEqual(res[1].block[0].name, "$hello") + self.assertEqual(res[1].block[0].value.value, 123) + self.assertIsInstance(res[1].block[1], Resource) + self.assertIsInstance(res[1].block[2], Resource) + self.assertEqual(res[1].block[0].line, 3) + self.assertEqual(res[1].block[0].col, 17) + self.assertEqual(res[1].block[0].end_col, 29) + self.assertEqual(res[1].block[1].line, 4) + self.assertEqual(res[1].block[1].col, 17) + self.assertEqual(res[1].block[1].end_line, 6) + self.assertEqual(res[1].block[1].end_col, 18) def test_assignment_array(self): code = """ diff --git a/tests/test_value.py b/tests/test_value.py index fb3b693..8f008dc 100644 --- a/tests/test_value.py +++ b/tests/test_value.py @@ -13,8 +13,8 @@ def test_value_string(self): self.assertEqual(res[0].value, "test") self.assertEqual(res[0].line, 1) self.assertEqual(res[0].end_line, 1) - self.assertEqual(res[0].col, 0) - self.assertEqual(res[0].end_col, 6) + self.assertEqual(res[0].col, 1) + self.assertEqual(res[0].end_col, 7) def test_value_string_multiline(self): code = """