Beispiel #1
0
        public void Format_ArrayOneItem_ReturnsExpectedArray()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("array")),
                MarkupGrammar.TokenElementVoid(new DataName("item")),
                MarkupGrammar.TokenElementEnd
            };
            var expected = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenNull,
                ModelGrammar.TokenArrayEnd
            };

            var transformer = new XmlReader.XmlInTransformer(new DataReaderSettings());
            var actual      = transformer.Transform(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #2
0
        public void Read_ObjectExtraValueAfterClose_ThrowsDeserializationException()
        {
            // input from fail10.json in test suite at http://www.json.org/JSON_checker/
            var input = @"{""Extra value after close"": true} ""misplaced quoted value""";

            var reader = new JsonReader(new DataReaderSettings {
                AllowTrailingContent = false
            });

            DeserializationException ex = Assert.Throws <DeserializationException>(
                delegate
            {
                var actual = reader.Read(input);
            });

            // verify exception is coming from expected position
            // note the reader doesn't see the 2nd object until it is read
            // so the index is after the trailing value
            Assert.Equal(57L, ex.Index);
        }
Beispiel #3
0
        public void Analyze_ObjectOneProperty_ReturnsSimpleObject()
        {
            var input = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("key"),
                ModelGrammar.TokenPrimitive("value"),
                ModelGrammar.TokenObjectEnd
            };

            var expected = new Dictionary <string, object>
            {
                { "key", "value" }
            };

            var analyzer = new ModelAnalyzer(new DataReaderSettings());
            var actual   = analyzer.Analyze(input).Cast <IDictionary <string, object> >().Single();

            Assert.Equal(expected, actual, false);
        }
Beispiel #4
0
        public void Analyze_ArrayUnclosed_ThrowsAnalyzerException()
        {
            // input from fail2.json in test suite at http://www.json.org/JSON_checker/
            var input = new []
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenPrimitive("Unclosed array")
            };

            var analyzer = new ModelAnalyzer(new DataReaderSettings());

            TokenException <ModelTokenType> ex = Assert.Throws <TokenException <ModelTokenType> >(
                delegate
            {
                var actual = analyzer.Analyze <object>(input).Single();
            });

            // verify exception is coming from expected token
            Assert.Equal(ModelGrammar.TokenNone, ex.Token);
        }
Beispiel #5
0
        public void GetTokens_HelloWorld_ReturnsDocument()
        {
            // input from example at http://bsonspec.org/#/specification
            var input = Encoding.UTF8.GetBytes(
                "\x16\x00\x00\x00\x02hello\x00" +
                "\x06\x00\x00\x00world\x00\x00");

            var expected = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("hello"),
                ModelGrammar.TokenPrimitive("world"),
                ModelGrammar.TokenObjectEnd
            };

            var tokenizer = new BsonReader.BsonTokenizer();
            var actual    = tokenizer.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
        public void Format_HelloWorld_ReturnsDocument()
        {
            // input from example at http://bsonspec.org/#/specification
            var input = new[]
            {
                ModelGrammar.TokenObjectBegin("Object"),
                ModelGrammar.TokenProperty("hello"),
                ModelGrammar.TokenPrimitive("world"),
                ModelGrammar.TokenObjectEnd
            };

            var expected = Encoding.UTF8.GetBytes(
                "\x16\x00\x00\x00\x02hello\x00" +
                "\x06\x00\x00\x00world\x00\x00");

            var formatter = new BsonWriter.BsonFormatter();
            var actual    = formatter.Format(input);

            Assert.Equal(expected, actual);
        }
Beispiel #7
0
        public void GetTokens_MultipleAttributes_ReturnsSequence()
        {
            const string input    = @"<root no-value="""" whitespace="" this contains whitespace "" anyQuotedText=""" + "/\\\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\n\r\t`1~!@#$%^&amp;*()_+-=[]{}|;:',./&lt;&gt;?" + @"""></root>";
            var          expected = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("root")),
                MarkupGrammar.TokenAttribute(new DataName("anyQuotedText")),
                MarkupGrammar.TokenPrimitive("/\\\uCAFE\uBABE\uAB98\uFCDE\uBCDA\uEF4A   `1~!@#$%^&*()_+-=[]{}|;:',./<>?"),
                MarkupGrammar.TokenAttribute(new DataName("no-value")),
                MarkupGrammar.TokenPrimitive(String.Empty),
                MarkupGrammar.TokenAttribute(new DataName("whitespace")),
                MarkupGrammar.TokenPrimitive(" this contains whitespace "),
                MarkupGrammar.TokenElementEnd
            };

            var tokenizer = new XmlReader.XmlTokenizer();
            var actual    = tokenizer.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #8
0
        public void GetTokens_ObjectAnonymous_ReturnsObjectTokens()
        {
            var input = new
            {
                One   = 1,
                Two   = 2,
                Three = 3,
                Four  = new
                {
                    A = 'a',
                    B = 'b',
                    C = 'c'
                }
            };

            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenProperty("One"),
                ModelGrammar.TokenPrimitive(1),
                ModelGrammar.TokenProperty("Two"),
                ModelGrammar.TokenPrimitive(2),
                ModelGrammar.TokenProperty("Three"),
                ModelGrammar.TokenPrimitive(3),
                ModelGrammar.TokenProperty("Four"),
                ModelGrammar.TokenObjectBegin("object"),
                ModelGrammar.TokenProperty("A"),
                ModelGrammar.TokenPrimitive('a'),
                ModelGrammar.TokenProperty("B"),
                ModelGrammar.TokenPrimitive('b'),
                ModelGrammar.TokenProperty("C"),
                ModelGrammar.TokenPrimitive('c'),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenObjectEnd
            };

            var walker = new ModelWalker(new DataWriterSettings());
            var actual = walker.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #9
0
        public void GetTokens_OverlappingNamespacedTagsErrorRecovery_ReturnsSequenceAsIs()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("odd", "a", "http://example.com/odd/a")),
                MarkupGrammar.TokenElementBegin(new DataName("auto-closed", "b", "http://example.com/auto-closed/b")),
                MarkupGrammar.TokenElementBegin(new DataName("even", "c", "http://example.com/even/c")),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd
            };
            var expected = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenPrimitive("a:odd"),
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("xmlns:a"),
                ModelGrammar.TokenPrimitive("http://example.com/odd/a"),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenPrimitive("b:auto-closed"),
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("xmlns:b"),
                ModelGrammar.TokenPrimitive("http://example.com/auto-closed/b"),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenPrimitive("c:even"),
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("xmlns:c"),
                ModelGrammar.TokenPrimitive("http://example.com/even/c"),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
            };

            var converter = new JsonMLReader.JsonMLInTransformer();
            var actual    = converter.Transform(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #10
0
        public void GetTokens_ArrayAsProperty_ReturnsDocument()
        {
            // input from example at http://bsonspec.org/#/specification

            // Encoding doesn't seem to like control chars
            //var input = Encoding.UTF8.GetBytes(
            //    "1\x00\x00\x00\x04BSON\x00&\x00"+
            //    "\x00\x00\x020\x00\x08\x00\x00"+
            //    "\x00awesome\x00\x011\x00333333"+
            //    "\x14@\x102\x00\xc2\x07\x00\x00"+
            //    "\x00\x00");

            var input = new byte[]
            {
                0x31, 0x00, 0x00, 0x00,
                0x04, (byte)'B', (byte)'S', (byte)'O', (byte)'N', 0x00,
                0x26, 0x00, 0x00, 0x00,
                0x02, (byte)'0', 0, 0x08, 0x00, 0x00, 0x00, (byte)'a', (byte)'w', (byte)'e', (byte)'s', (byte)'o', (byte)'m', (byte)'e', 0x00,
                0x01, (byte)'1', 0, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x14, 0x40,
                0x10, (byte)'2', 0, 0xC2, 0x07, 0x00, 0x00,
                0x00,
                0x00
            };

            var expected = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("BSON"),
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenPrimitive("awesome"),
                ModelGrammar.TokenPrimitive(5.05),
                ModelGrammar.TokenPrimitive(1986),
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenObjectEnd
            };

            var tokenizer = new BsonReader.BsonTokenizer();
            var actual    = tokenizer.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #11
0
        public void TryWrite_DateTimeMaxValueEcmaScriptPrecision_DirectlyWritesAsUnspecified()
        {
            var input = DateTime.MaxValue;

            var expected = new[]
            {
                ModelGrammar.TokenPrimitive("9999-12-31T23:59:59.9999999")
            };

            IEnumerable <Token <ModelTokenType> > actual;

            Assert.True(new Iso8601DateFilter {
                Format = Iso8601DateFilter.Precision.Ticks
            }
                        .TryWrite(new DataWriterSettings(), input, out actual));

            Assert.NotNull(actual);
            Assert.Equal(expected.Count(), actual.Count());
            Assert.Equal(expected[0].TokenType, actual.First().TokenType);
            Assert.Equal(expected[0].Value, actual.First().Value);
        }
Beispiel #12
0
        public void ArrayItems_MixedPrimitivesFilterAll_ReturnsSplitSequences()
        {
            var input = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenFalse,
                ModelGrammar.TokenTrue,
                ModelGrammar.TokenNull,
                ModelGrammar.TokenPrimitive("Hello!"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenPrimitive(42),
                ModelGrammar.TokenArrayEnd
            };

            var expected = new IEnumerable <Token <ModelTokenType> > [0];

            // select no items
            var actual = input.ArrayItems(index => false).ToArray();

            Assert.Equal(expected, actual, false);
        }
Beispiel #13
0
        public void Format_ArrayOneItemPrettyPrint_ReturnsExpectedPrettyPrintedArray()
        {
            var input = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenNull,
                ModelGrammar.TokenArrayEnd
            };

            const string expected =
                @"[
	null
]";

            var formatter = new JsonWriter.JsonFormatter(new DataWriterSettings {
                PrettyPrint = true
            });
            var actual = formatter.Format(input);

            Assert.Equal(expected, actual);
        }
Beispiel #14
0
        public void GetTokens_BooleanValue_ReturnsDocument()
        {
            // input from example at http://codebetter.com/blogs/karlseguin/archive/2010/03/05/bson-serialization.aspx
            var input = new byte[]
            {
                13, 0, 0, 0, 8, 118, 97, 108, 105, 100, 0, 1, 0
            };

            var expected = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("valid"),
                ModelGrammar.TokenTrue,
                ModelGrammar.TokenObjectEnd
            };

            var tokenizer = new BsonReader.BsonTokenizer();
            var actual    = tokenizer.GetTokens(input).ToArray();

            Assert.Equal(expected, actual);
        }
        public void Format_BooleanValue_ReturnsDocument()
        {
            // input from example at http://codebetter.com/blogs/karlseguin/archive/2010/03/05/bson-serialization.aspx
            var input = new[]
            {
                ModelGrammar.TokenObjectBegin("Object"),
                ModelGrammar.TokenProperty("valid"),
                ModelGrammar.TokenTrue,
                ModelGrammar.TokenObjectEnd
            };

            var expected = new byte[]
            {
                13, 0, 0, 0, 8, 118, 97, 108, 105, 100, 0, 1, 0
            };

            var formatter = new BsonWriter.BsonFormatter();
            var actual    = formatter.Format(input);

            Assert.Equal(expected, actual);
        }
Beispiel #16
0
        public void Analyze_ObjectUnterminated_ThrowsAnalyzerException()
        {
            // input from fail32.json in test suite at http://www.json.org/JSON_checker/
            var input = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("Comma instead if closing brace"),
                ModelGrammar.TokenTrue
            };

            var analyzer = new ModelAnalyzer(new DataReaderSettings());

            TokenException <ModelTokenType> ex = Assert.Throws <TokenException <ModelTokenType> >(
                delegate
            {
                var actual = analyzer.Analyze <object>(input).Single();
            });

            // verify exception is coming from expected token
            Assert.Equal(ModelGrammar.TokenNone, ex.Token);
        }
Beispiel #17
0
        public void TryWrite_DateTimeMinValueShortPrecision_DirectlyWritesAsUnspecified()
        {
            var input = DateTime.MinValue;

            var expected = new[]
            {
                ModelGrammar.TokenPrimitive("0001-01-01T00:00:00")
            };

            IEnumerable <Token <ModelTokenType> > actual;

            Assert.True(new Iso8601DateFilter {
                Format = Iso8601DateFilter.Precision.Seconds
            }
                        .TryWrite(new DataWriterSettings(), input, out actual));

            Assert.NotNull(actual);
            Assert.Equal(expected.Count(), actual.Count());
            Assert.Equal(expected[0].TokenType, actual.First().TokenType);
            Assert.Equal(expected[0].Value, actual.First().Value);
        }
Beispiel #18
0
        public void Format_ArrayEmpty_ReturnsEmptyArray()
        {
            var input = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayEnd
            };

            var expected = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("div")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd
            };

            var transformer = new HtmlOutTransformer();
            var actual      = transformer.Transform(input).ToArray();

            Assert.Equal(expected, actual);
        }
        //[Fact(Skip="Embedded DOCTYPE not supported")]
        public void Format_XmlDocTypeLocal_ReturnsUnparsed()
        {
            var input = new[]
            {
                MarkupGrammar.TokenUnparsed("!", "",
                                            @"DOCTYPE doc [
	<!ATTLIST normId id ID #IMPLIED>
	<!ATTLIST normNames attr NMTOKENS #IMPLIED>
]")
            };
            const string expected =
                @"<!DOCTYPE doc [
	<!ATTLIST normId id ID #IMPLIED>
	<!ATTLIST normNames attr NMTOKENS #IMPLIED>
]>";

            var formatter = new HtmlFormatter(new DataWriterSettings());
            var actual    = formatter.Format(input);

            Assert.Equal(expected, actual);
        }
Beispiel #20
0
        public void Analyze_AnonymousObject_ReturnsAnonymousObject()
        {
            // NOTE: order is important to ensure type equivalence

            var input = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("AString"),
                ModelGrammar.TokenPrimitive("Hello world!"),
                ModelGrammar.TokenProperty("AnInt32"),
                ModelGrammar.TokenPrimitive(42),
                ModelGrammar.TokenProperty("AnAnonymous"),
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("AnotherString"),
                ModelGrammar.TokenPrimitive("Foo."),
                ModelGrammar.TokenProperty("AnInt64"),
                ModelGrammar.TokenPrimitive(((long)Int32.MaxValue) * 2L),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenProperty("ADouble"),
                ModelGrammar.TokenPrimitive(Math.PI),
                ModelGrammar.TokenObjectEnd
            };

            var expected = new
            {
                AString     = "Hello world!",
                AnInt32     = 42,
                AnAnonymous = new
                {
                    AnotherString = "Foo.",
                    AnInt64       = ((long)Int32.MaxValue) * 2L
                },
                ADouble = Math.PI
            };

            var analyzer = new ModelAnalyzer(new DataReaderSettings());
            var actual   = analyzer.Analyze(input, expected).Single();

            Assert.Equal(expected, actual, false);
        }
Beispiel #21
0
        public void Query_PropertyNoMatchFirstOrDefault_ReturnsNull()
        {
            var input = @"
[
	{
		""key"": ""value""
	},
	{
		""key"": ""other-value""
	}
]";

            var expected = (object)null;

            var source = new JsonReader().Query(input, new { key = String.Empty });

            var query = source.Where(obj => obj.key == "not-a-key");

            var actual = query.FirstOrDefault();

            Assert.Equal(expected, actual, false);
        }
        public void Format_DifferentPrefixSameNamespace_ReturnsMarkup()
        {
            // Not sure if this is correct: http://stackoverflow.com/questions/3312390
            // "The namespace name for an unprefixed attribute name always has no value"
            // "The attribute value in a default namespace declaration MAY be empty.
            // This has the same effect, within the scope of the declaration, of there being no default namespace."
            // http://www.w3.org/TR/xml-names/#defaulting

            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("foo", String.Empty, "http://example.org")),
                MarkupGrammar.TokenAttribute(new DataName("key", "blah", "http://example.org")),
                MarkupGrammar.TokenPrimitive("value"),
                MarkupGrammar.TokenElementEnd,
            };
            const string expected = @"<foo xmlns=""http://example.org"" key=""value""></foo>";

            var formatter = new HtmlFormatter(new DataWriterSettings());
            var actual    = formatter.Format(input);

            Assert.Equal(expected, actual);
        }
Beispiel #23
0
        public void Analyze_ValueInsteadOfProperty_ThrowsAnalyzerException()
        {
            // input from fail21.json in test suite at http://www.json.org/JSON_checker/
            var input = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenPrimitive("Comma instead of colon"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenObjectEnd
            };

            var analyzer = new ModelAnalyzer(new DataReaderSettings());

            TokenException <ModelTokenType> ex = Assert.Throws <TokenException <ModelTokenType> >(
                delegate
            {
                var actual = analyzer.Analyze <object>(input).Single();
            });

            // verify exception is coming from expected token
            Assert.Equal(ModelGrammar.TokenPrimitive("Comma instead of colon"), ex.Token);
        }
Beispiel #24
0
        public void Format_ObjectAndAttributeDifferentNamespaces_CorrectlyEmitsNamespaces()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("foo", String.Empty, "http://json.org")),
                MarkupGrammar.TokenAttribute(new DataName("key", String.Empty, "http://jsonfx.net", true)),
                MarkupGrammar.TokenPrimitive("value"),
                MarkupGrammar.TokenElementEnd,
            };
            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin(new DataName("foo", String.Empty, "http://json.org")),
                ModelGrammar.TokenProperty(new DataName("key", String.Empty, "http://jsonfx.net", true)),
                ModelGrammar.TokenPrimitive("value"),
                ModelGrammar.TokenObjectEnd
            };

            var transformer = new XmlReader.XmlInTransformer(new DataReaderSettings());
            var actual      = transformer.Transform(input).ToArray();

            Assert.Equal(expected, actual);
        }
Beispiel #25
0
        public void Format_ObjectOnePropertyPrettyPrint_ReturnsPrettyPrintedSimpleObject()
        {
            var input = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("key"),
                ModelGrammar.TokenPrimitive("value"),
                ModelGrammar.TokenObjectEnd
            };

            const string expected =
                @"{
	""key"" : ""value""
}";

            var formatter = new JsonWriter.JsonFormatter(new DataWriterSettings {
                PrettyPrint = true
            });
            var actual = formatter.Format(input);

            Assert.Equal(expected, actual);
        }
        public void Format_NestedDefaultNamespaces_ReturnsMarkup()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("outer", String.Empty, "http://example.org/outer")),
                MarkupGrammar.TokenElementBegin(new DataName("middle-1", String.Empty, "http://example.org/inner")),
                MarkupGrammar.TokenElementBegin(new DataName("inner", String.Empty, "http://example.org/inner")),
                MarkupGrammar.TokenPrimitive("this should be inner"),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementBegin(new DataName("middle-2", String.Empty, "http://example.org/outer")),
                MarkupGrammar.TokenPrimitive("this should be outer"),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
            };
            const string expected = @"<outer xmlns=""http://example.org/outer""><middle-1 xmlns=""http://example.org/inner""><inner>this should be inner</inner></middle-1><middle-2>this should be outer</middle-2></outer>";

            var formatter = new HtmlFormatter(new DataWriterSettings());
            var actual    = formatter.Format(input);

            Assert.Equal(expected, actual);
        }
Beispiel #27
0
        public void GetTokens_XmlDocTypeExternal_ReturnsUnparsed()
        {
            var input = new[]
            {
                ModelGrammar.TokenPrimitive(new UnparsedBlock("!", "",
                                                              @"DOCTYPE html PUBLIC
	""-//W3C//DTD XHTML 1.1//EN""
	""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"""    ))
            };
            var expected = new[]
            {
                MarkupGrammar.TokenUnparsed("!", "",
                                            @"DOCTYPE html PUBLIC
	""-//W3C//DTD XHTML 1.1//EN""
	""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"""    )
            };

            var converter = new JsonMLWriter.JsonMLOutTransformer();
            var actual    = converter.Transform(input).ToArray();

            Assert.Equal(expected, actual);
        }
        public void Format_MultipleAttributesCanonicalForm_ReturnsCanonicalMarkup()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementVoid(new DataName("root")),
                MarkupGrammar.TokenAttribute(new DataName("whitespace")),
                MarkupGrammar.TokenPrimitive(" this contains whitespace "),
                MarkupGrammar.TokenAttribute(new DataName("no-value")),
                MarkupGrammar.TokenPrimitive(String.Empty),
                MarkupGrammar.TokenAttribute(new DataName("anyQuotedText")),
                MarkupGrammar.TokenPrimitive("/\\\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?")
            };
            const string expected = @"<root anyQuotedText=""/\" + "\uCAFE\uBABE\uAB98\uFCDE\uBCDA\uEF4A" + @"&#x8;&#xC;&#xA;&#xD;&#x9;`1~!@#$%^&amp;*()_+-=[]{}|;:&apos;,./&lt;>?"" no-value whitespace="" this contains whitespace ""></root>";

            var formatter = new HtmlFormatter(new DataWriterSettings())
            {
                CanonicalForm = true
            };
            var actual = formatter.Format(input);

            Assert.Equal(expected, actual);
        }
Beispiel #29
0
        public void Read_AllowTrailingContent_IgnoresTrailingContent()
        {
            var input    = new StringReader(@"[""Content embedded inside other structure"", true,null, 42]</xml>");
            var expected = new object[]
            {
                "Content embedded inside other structure",
                true,
                null,
                42
            };

            var reader = new JsonReader(new DataReaderSettings {
                AllowTrailingContent = true
            });

            var actual = reader.Read(input);

            Assert.Equal(expected, actual);

            // Didn't consume remaining content
            Assert.Equal("</xml>", input.ReadToEnd());
        }
Beispiel #30
0
        public void GetTokens_MixedEntities_ReturnsSequence()
        {
            var input = new[]
            {
                MarkupGrammar.TokenPrimitive(@"there should "),
                MarkupGrammar.TokenPrimitive(@"<"),
                MarkupGrammar.TokenPrimitive(@"b"),
                MarkupGrammar.TokenPrimitive(@">"),
                MarkupGrammar.TokenPrimitive(@"e decoded chars "),
                MarkupGrammar.TokenPrimitive(@"&"),
                MarkupGrammar.TokenPrimitive(@" inside this text")
            };
            var expected = new[]
            {
                ModelGrammar.TokenPrimitive(@"there should <b>e decoded chars & inside this text")
            };

            var converter = new JsonMLReader.JsonMLInTransformer();
            var actual    = converter.Transform(input).ToArray();

            Assert.Equal(expected, actual);
        }