Skip to content

Commit

Permalink
small fix on col attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nfsaavedra committed May 7, 2024
1 parent fd82e6e commit e0d6942
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion puppetparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <nuno.saavedra@tecnico.ulisboa.pt>"]
license = "GPL-3.0"
Expand Down
42 changes: 25 additions & 17 deletions tests/test_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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 = """
Expand Down
4 changes: 2 additions & 2 deletions tests/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down

0 comments on commit e0d6942

Please sign in to comment.