Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
import os
import sys
import math
from decimal import Decimal

from toml.decoder import InlineTableDict
Expand Down Expand Up @@ -103,6 +104,18 @@ class TestDict(dict, InlineTableDict):
assert o == toml.loads(toml.dumps(o, encoder=encoder))


@pytest.mark.parametrize(
'value', ['inf', 'nan', '+inf', '+nan', '-inf', '-nan', '+1']
)
def test_inline_numeric_values_match_regular_table(value):
expected = toml.loads('n = {}'.format(value))['n']
actual = toml.loads('t = {{n = {}}}'.format(value))['t']['n']
if math.isnan(expected):
assert math.isnan(actual)
else:
assert actual == expected


def test_array_sep():
encoder = toml.TomlArraySeparatorEncoder(separator=",\t")
d = {"a": [1, 2, 3]}
Expand Down
3 changes: 2 additions & 1 deletion toml/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@ def load_inline_object(self, line, currentlevel, multikey=False,
raise ValueError("Invalid inline table encountered")
value = value.strip()
if ((value[0] == value[-1] and value[0] in ('"', "'")) or (
value[0] in '-0123456789' or
value[0] in '+-0123456789' or
value.lower() in ('inf', 'nan') or
value in ('true', 'false') or
(value[0] == "[" and value[-1] == "]") or
(value[0] == '{' and value[-1] == '}'))):
Expand Down