diff --git a/tests/test_api.py b/tests/test_api.py index 9aecf38..6902b1a 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -3,6 +3,7 @@ import pytest import os import sys +import math from decimal import Decimal from toml.decoder import InlineTableDict @@ -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]} diff --git a/toml/decoder.py b/toml/decoder.py index cc59b8a..b6a6f9a 100644 --- a/toml/decoder.py +++ b/toml/decoder.py @@ -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] == '}'))):