Example #1
0
        static void test()
        {
            var testCases = new string[] {
                @"",
                @"{}",
                @"/* hello world*/{}",
                @"// hello world
{}",
                @"{}/* hello world */",
                @"{}// hello world",
                @"{}
// word up!",
                @"/********/",
                @"{""key"": value}",
                @"{""key"": ""value""}",
                @"{""key"": 0.1423}",
                @"{""key"": []}",
                @"{""key"": [{},{}]}",
                @"{""key"": [,]}",      // invalid JSON but passes
                @"[]",
                @"[/* help! */1,2,3/*toomuch*/4]",
                @"""word!""",
                @"@""multiline
test
here""",
                @"true",
                @"false",
                @"null",
                @"1.2",
                @"""abc\""word""",
                @"""a\u01C3bcd""",

                // Failure cases:
                @"/********",
                @"@""",
                @"""",
                @"""\",
                @"""\""",
                @"@""\",
                @"/+",
                @"/*",
                @"a / b"
            };

            for (int i = 0; i < testCases.Length; ++i)
                try
                {
                    using (var hr = new HsonReader(new MemoryStream(Encoding.UTF8.GetBytes(testCases[i]))))
                    {
                        Console.WriteLine("'{0}'", hr.ReadToEnd());
                    }
                }
                catch (HsonParserException hpe)
                {
                    Console.WriteLine(hpe.Message);
                }

            Console.WriteLine();
            using (var hr = new HsonReader(@"config.hson"))
            {
                Console.WriteLine("'{0}'", hr.ReadToEnd());
            }
        }
Example #2
0
        static void test()
        {
            var testCases = new string[] {
                @"",
                @"{}",
                @"/* hello world*/{}",
                @"// hello world
{}",
                @"{}/* hello world */",
                @"{}// hello world",
                @"{}
// word up!",
                @"/********/",
                @"{""key"": value}",
                @"{""key"": ""value""}",
                @"{""key"": 0.1423}",
                @"{""key"": []}",
                @"{""key"": [{},{}]}",
                @"{""key"": [,]}",      // invalid JSON but passes
                @"[]",
                @"[/* help! */1,2,3/*toomuch*/4]",
                @"""word!""",
                @"@""multiline
test
here""",
                @"true",
                @"false",
                @"null",
                @"1.2",
                @"""abc\""word""",
                @"""a\u01C3bcd""",

                // Failure cases:
                @"/********",
                @"@""",
                @"""",
                @"""\",
                @"""\""",
                @"@""\",
                @"/+",
                @"/*",
                @"a / b"
            };

            for (int i = 0; i < testCases.Length; ++i)
            {
                try
                {
                    using (var hr = new HsonReader(new MemoryStream(Encoding.UTF8.GetBytes(testCases[i]))))
                    {
                        Console.WriteLine("'{0}'", hr.ReadToEnd());
                    }
                }
                catch (HsonParserException hpe)
                {
                    Console.WriteLine(hpe.Message);
                }
            }

            Console.WriteLine();
            using (var hr = new HsonReader(@"config.hson"))
            {
                Console.WriteLine("'{0}'", hr.ReadToEnd());
            }
        }