コード例 #1
0
        public void MultilineString()
        {
            var inputString          = @"multiline_empty_one = """"""""""""
multiline_empty_two = """"""
""""""
multiline_empty_three = """"""\
    """"""
multiline_empty_four = """"""\
   \
   \
   """"""

equivalent_one = ""The quick brown fox jumps over the lazy dog.""
equivalent_two = """"""
The quick brown \


  fox jumps over \
    the lazy dog.""""""

equivalent_three = """"""\
       The quick brown \
       fox jumps over \
       the lazy dog.\
       """"""";
            var expectedOutputString = @"{
    ""multiline_empty_one"": {
        ""type"": ""string"",
        ""value"": """"
    },
    ""multiline_empty_two"": {
        ""type"": ""string"",
        ""value"": """"
    },
    ""multiline_empty_three"": {
        ""type"": ""string"",
        ""value"": """"
    },
    ""multiline_empty_four"": {
        ""type"": ""string"",
        ""value"": """"
    },
    ""equivalent_one"": {
        ""type"": ""string"",
        ""value"": ""The quick brown fox jumps over the lazy dog.""
    },
    ""equivalent_two"": {
        ""type"": ""string"",
        ""value"": ""The quick brown fox jumps over the lazy dog.""
    },
    ""equivalent_three"": {
        ""type"": ""string"",
        ""value"": ""The quick brown fox jumps over the lazy dog.""
    }
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #2
0
        public static object Deserialize(string input)
        {
            var deserializer = new TestDeserializer();

            TomlParser.ParseInput(input, deserializer);
            return(deserializer.value);
        }
コード例 #3
0
        public void DuplicateTables()
        {
            var inputString = @"[a]
[a]";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #4
0
        public void KeyNewline()
        {
            var inputString = @"a
= 1";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #5
0
        public void FloatNoTrailingDigits()
        {
            var inputString = @"answer = 1.
neganswer = -1.";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #6
0
        public void ArraysHetergeneous()
        {
            var inputString          = @"mixed = [[1, 2], [""a"", ""b""], [1.1, 2.1]]";
            var expectedOutputString = @"{
    ""mixed"": {
        ""type"": ""array"",
        ""value"": [
            {""type"": ""array"", ""value"": [
                {""type"": ""integer"", ""value"": ""1""},
                {""type"": ""integer"", ""value"": ""2""}
            ]},
            {""type"": ""array"", ""value"": [
                {""type"": ""string"", ""value"": ""a""},
                {""type"": ""string"", ""value"": ""b""}
            ]},
            {""type"": ""array"", ""value"": [
                {""type"": ""float"", ""value"": ""1.1""},
                {""type"": ""float"", ""value"": ""2.1""}
            ]}
        ]
    }
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #7
0
        public void DuplicateKeys()
        {
            var inputString = @"dupe = false
dupe = true";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #8
0
        public void TableArrayMany()
        {
            var inputString          = @"[[people]]
first_name = ""Bruce""
last_name = ""Springsteen""

[[people]]
first_name = ""Eric""
last_name = ""Clapton""

[[people]]
first_name = ""Bob""
last_name = ""Seger""";
            var expectedOutputString = @"{
    ""people"": [
        {
            ""first_name"": {""type"": ""string"", ""value"": ""Bruce""},
            ""last_name"": {""type"": ""string"", ""value"": ""Springsteen""}
        },
        {
            ""first_name"": {""type"": ""string"", ""value"": ""Eric""},
            ""last_name"": {""type"": ""string"", ""value"": ""Clapton""}
        },
        {
            ""first_name"": {""type"": ""string"", ""value"": ""Bob""},
            ""last_name"": {""type"": ""string"", ""value"": ""Seger""}
        }
    ]
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #9
0
        public void FloatNoLeadingZero()
        {
            var inputString = @"answer = .12345
neganswer = -.12345";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #10
0
        public void RawMultilineString()
        {
            var inputString          = @"oneline = '''This string has a ' quote character.'''
firstnl = '''
This string has a ' quote character.'''
multiline = '''
This string
has ' a quote character
and more than
one newline
in it.'''";
            var expectedOutputString = @"{
    ""oneline"": {
        ""type"": ""string"",
        ""value"": ""This string has a ' quote character.""
    },
    ""firstnl"": {
        ""type"": ""string"",
        ""value"": ""This string has a ' quote character.""
    },
    ""multiline"": {
        ""type"": ""string"",
        ""value"": ""This string\nhas ' a quote character\nand more than\none newline\nin it.""
    }
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #11
0
        public void TableNestedBracketsOpen()
        {
            var inputString = @"[a[b]
zyx = 42";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #12
0
        public void TableArrayMalformedEmpty()
        {
            var inputString = @"[[]]
name = ""Born to Run""";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #13
0
        public void TableWithPound()
        {
            var inputString = @"[key#group]
answer = 42";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #14
0
        public void Example()
        {
            var inputString          = @"best-day-ever = 1987-07-05T17:45:00Z

[numtheory]
boring = false
perfection = [6, 28, 496]";
            var expectedOutputString = @"{
  ""best-day-ever"": {""type"": ""datetime"", ""value"": ""1987-07-05T17:45:00Z""},
  ""numtheory"": {
    ""boring"": {""type"": ""bool"", ""value"": ""false""},
    ""perfection"": {
      ""type"": ""array"",
      ""value"": [
        {""type"": ""integer"", ""value"": ""6""},
        {""type"": ""integer"", ""value"": ""28""},
        {""type"": ""integer"", ""value"": ""496""}
      ]
    }
  }
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #15
0
        public void KeyStartBracket()
        {
            var inputString = @"[a]
[xyz = 5
[b]";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #16
0
        public void TextAfterArrayEntries()
        {
            var inputString = @"array = [
  ""Is there life after an array separator?"", No
  ""Entry""
]";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #17
0
        public void TextBeforeArraySeparator()
        {
            var inputString = @"array = [
  ""Is there life before an array separator?"" No,
  ""Entry""
]";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #18
0
        public void Empty()
        {
            var inputString          = @"";
            var expectedOutputString = @"{}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #19
0
        public void DuplicateKeyTable()
        {
            var inputString = @"[fruit]
type = ""apple""

[fruit.type]
apple = ""yes""";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #20
0
        public void TextInArray()
        {
            var inputString = @"array = [
  ""Entry 1"",
  I don't belong,
  ""Entry 2"",
]";

            AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString));
        }
コード例 #21
0
        public void TableWhitespace()
        {
            var inputString          = @"[""valid key""]";
            var expectedOutputString = @"{
    ""valid key"": {}
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #22
0
        public void Datetime()
        {
            var inputString          = @"bestdayever = 1987-07-05T17:45:00Z";
            var expectedOutputString = @"{
    ""bestdayever"": {""type"": ""datetime"", ""value"": ""1987-07-05T17:45:00Z""}
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #23
0
        public void KeySpace()
        {
            var inputString          = @"""a b"" = 1";
            var expectedOutputString = @"{
    ""a b"": {""type"": ""integer"", ""value"": ""1""}
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #24
0
        public void UnicodeLiteral()
        {
            var inputString          = @"answer = ""δ""";
            var expectedOutputString = @"{
    ""answer"": {""type"": ""string"", ""value"": ""δ""}
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #25
0
        public void TableSubEmpty()
        {
            var inputString          = @"[a]
[a.b]";
            var expectedOutputString = @"{
    ""a"": { ""b"": {} }
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #26
0
        public void Integer()
        {
            var inputString          = @"answer = 42
neganswer = -42";
            var expectedOutputString = @"{
    ""answer"": {""type"": ""integer"", ""value"": ""42""},
    ""neganswer"": {""type"": ""integer"", ""value"": ""-42""}
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #27
0
        public void KeySpecialChars()
        {
            var inputString          = @"""~!@$^&*()_+-`1234567890[]|/?><.,;:'"" = 1";
            var expectedOutputString = @"{
    ""~!@$^&*()_+-`1234567890[]|/?><.,;:'"": {
        ""type"": ""integer"", ""value"": ""1""
    }
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #28
0
        public void LongFloat()
        {
            var inputString          = @"longpi = 3.141592653589793
neglongpi = -3.141592653589793";
            var expectedOutputString = @"{
    ""longpi"": {""type"": ""float"", ""value"": ""3.141592653589793""},
    ""neglongpi"": {""type"": ""float"", ""value"": ""-3.141592653589793""}
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #29
0
        public void LongInteger()
        {
            var inputString          = @"answer = 9223372036854775807
neganswer = -9223372036854775808";
            var expectedOutputString = @"{
    ""answer"": {""type"": ""integer"", ""value"": ""9223372036854775807""},
    ""neganswer"": {""type"": ""integer"", ""value"": ""-9223372036854775808""}
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #30
0
        public void UnicodeEscape()
        {
            var inputString          = @"answer4 = ""\u03B4""
answer8 = ""\U000003B4""";
            var expectedOutputString = @"{
    ""answer4"": {""type"": ""string"", ""value"": ""\u03B4""},
    ""answer8"": {""type"": ""string"", ""value"": ""\u03B4""}
}";
            var output         = (Dictionary <string, object>)TestDeserializer.Deserialize(inputString);
            var expectedOutput = (Dictionary <string, object>)JsonHelper.Deserialize(expectedOutputString);

            AssertHelpers.ObjectsEqual(expectedOutput, output);
        }
コード例 #31
0
ファイル: Deserializer.cs プロジェクト: modulexcite/NToml
 public static object Deserialize(string input)
 {
     var deserializer = new TestDeserializer();
     TomlParser.ParseInput(input, deserializer);
     return deserializer.value;
 }