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); }
public static object Deserialize(string input) { var deserializer = new TestDeserializer(); TomlParser.ParseInput(input, deserializer); return(deserializer.value); }
public void DuplicateTables() { var inputString = @"[a] [a]"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
public void KeyNewline() { var inputString = @"a = 1"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
public void FloatNoTrailingDigits() { var inputString = @"answer = 1. neganswer = -1."; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
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); }
public void DuplicateKeys() { var inputString = @"dupe = false dupe = true"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
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); }
public void FloatNoLeadingZero() { var inputString = @"answer = .12345 neganswer = -.12345"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
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); }
public void TableNestedBracketsOpen() { var inputString = @"[a[b] zyx = 42"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
public void TableArrayMalformedEmpty() { var inputString = @"[[]] name = ""Born to Run"""; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
public void TableWithPound() { var inputString = @"[key#group] answer = 42"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
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); }
public void KeyStartBracket() { var inputString = @"[a] [xyz = 5 [b]"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
public void TextAfterArrayEntries() { var inputString = @"array = [ ""Is there life after an array separator?"", No ""Entry"" ]"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
public void TextBeforeArraySeparator() { var inputString = @"array = [ ""Is there life before an array separator?"" No, ""Entry"" ]"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
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); }
public void DuplicateKeyTable() { var inputString = @"[fruit] type = ""apple"" [fruit.type] apple = ""yes"""; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
public void TextInArray() { var inputString = @"array = [ ""Entry 1"", I don't belong, ""Entry 2"", ]"; AssertHelpers.ThrowsDerived <ParseException>(() => TestDeserializer.Deserialize(inputString)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public static object Deserialize(string input) { var deserializer = new TestDeserializer(); TomlParser.ParseInput(input, deserializer); return deserializer.value; }