Fix problems caused by b411d20

Also add the test case from #1536 so we can be sure things stay correct.
This commit is contained in:
Tzu-ping Chung
2018-03-04 03:42:42 +08:00
parent f9f59c96fb
commit b70c2275e2
2 changed files with 32 additions and 1 deletions
@@ -76,7 +76,7 @@ class TraversalMixin:
following_comment = self._find_following_comment(index)
following_newline = self._find_following_newline(index)
if following_comment == float('inf'):
if following_comment == float('-inf'):
return following_newline
if following_newline == float('-inf'):
return following_comment
+31
View File
@@ -0,0 +1,31 @@
# Make sure we use the patched packages.
import pipenv # noqa
from prettytoml import lexer
from prettytoml.elements.atomic import AtomicElement
from prettytoml.elements.metadata import (
WhitespaceElement, PunctuationElement, CommentElement,
)
from prettytoml.elements.table import TableElement
def test_table():
initial_toml = """id=42 # My id\nage=14"""
tokens = tuple(lexer.tokenize(initial_toml))
table = TableElement([
AtomicElement(tokens[0:1]),
PunctuationElement(tokens[1:2]),
AtomicElement(tokens[2:3]),
WhitespaceElement(tokens[3:4]),
CommentElement(tokens[4:6]),
AtomicElement(tokens[6:7]),
PunctuationElement(tokens[7:8]),
AtomicElement(tokens[8:9]),
])
assert set(table.items()) == {('id', 42), ('age', 14)}
del table['id']
assert set(table.items()) == {('age', 14)}