Exemplo n.º 1
0
        public void Format_NestedObjectsAlternatingNamespaces_CorrectlyEmitsNamespaces()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("foo1", String.Empty, "http://json.org")),
                MarkupGrammar.TokenElementBegin(new DataName("key1", String.Empty, "http://jsonfx.net")),
                MarkupGrammar.TokenElementBegin(new DataName("key2", String.Empty, "http://json.org")),
                MarkupGrammar.TokenPrimitive("value"),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
            };
            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin(new DataName("foo1", String.Empty, "http://json.org")),
                ModelGrammar.TokenProperty(new DataName("key1", String.Empty, "http://jsonfx.net")),

                ModelGrammar.TokenObjectBegin(new DataName("key2", String.Empty, "http://json.org")),
                ModelGrammar.TokenProperty(new DataName("key2", String.Empty, "http://json.org")),
                ModelGrammar.TokenPrimitive("value"),
                ModelGrammar.TokenObjectEnd,

                ModelGrammar.TokenObjectEnd
            };

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

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        public void Format_ObjectNested_RendersNestedObject()
        {
            // input from pass3.json in test suite at http://www.json.org/JSON_checker/
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("object")),
                MarkupGrammar.TokenElementBegin(new DataName("JSON_x0020_Test_x0020_Pattern_x0020_pass3")),
                MarkupGrammar.TokenElementBegin(new DataName("The_x0020_outermost_x0020_value")),
                MarkupGrammar.TokenPrimitive("must be an object or array."),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementBegin(new DataName("In_x0020_this_x0020_test")),
                MarkupGrammar.TokenPrimitive("It is an object."),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
            };
            var expected = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("JSON Test Pattern pass3"),
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("The outermost value"),
                ModelGrammar.TokenPrimitive("must be an object or array."),
                ModelGrammar.TokenProperty("In this test"),
                ModelGrammar.TokenPrimitive("It is an object."),
                ModelGrammar.TokenObjectEnd,
                ModelGrammar.TokenObjectEnd
            };

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

            Assert.Equal(expected, actual);
        }
Exemplo n.º 3
0
        public void Format_ArrayMultiItem_ReturnsExpectedArray()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("array")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenPrimitive(0),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementVoid(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenPrimitive(false),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenPrimitive(true),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
            };
            var expected = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenPrimitive(0),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenFalse,
                ModelGrammar.TokenTrue,
                ModelGrammar.TokenArrayEnd
            };

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

            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
        public void Ctor_NullSettings_ThrowsArgumentNullException()
        {
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate
            {
                var transformer = new XmlReader.XmlInTransformer(null);
            });

            // verify exception is coming from expected param
            Assert.Equal("settings", ex.ParamName);
        }
Exemplo n.º 5
0
        public void Format_EmptyInput_RendersEmptyString()
        {
            var expected = Enumerable.Empty <Token <ModelTokenType> >();

            var input = Enumerable.Empty <Token <MarkupTokenType> >();

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

            Assert.Equal(expected, actual);
        }
Exemplo n.º 6
0
        public void Format_NullInput_ThrowsArgumentNullException()
        {
            var input = (IEnumerable <Token <MarkupTokenType> >)null;

            var transformer = new XmlReader.XmlInTransformer(new DataReaderSettings());

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate
            {
                var actual = transformer.Transform(input).ToArray();
            });

            // verify exception is coming from expected param
            Assert.Equal("input", ex.ParamName);
        }
Exemplo n.º 7
0
        public void Format_ArrayEmpty_ReturnsEmptyArray()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("array")),
                MarkupGrammar.TokenElementEnd
            };
            var expected = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayEnd
            };

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

            Assert.Equal(expected, actual);
        }
Exemplo n.º 8
0
        public void Format_ObjectAndAttributeShareNamespace_CorrectlyEmitsNamespace()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("foo", String.Empty, "http://json.org")),
                MarkupGrammar.TokenAttribute(new DataName("key", String.Empty, "http://json.org", 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://json.org", true)),
                ModelGrammar.TokenPrimitive("value"),
                ModelGrammar.TokenObjectEnd
            };

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

            Assert.Equal(expected, actual);
        }
Exemplo n.º 9
0
        public void Format_NamedObjectOneProperty_RendersSimpleObject()
        {
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("Yada")),
                MarkupGrammar.TokenElementBegin(new DataName("key")),
                MarkupGrammar.TokenPrimitive("value"),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
            };
            var expected = new[]
            {
                ModelGrammar.TokenObjectBegin("Yada"),
                ModelGrammar.TokenProperty("key"),
                ModelGrammar.TokenPrimitive("value"),
                ModelGrammar.TokenObjectEnd
            };

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

            Assert.Equal(expected, actual);
        }
Exemplo n.º 10
0
        public void Format_ArrayNestedDeeply_ReturnsExpectedArray()
        {
            // input from pass2.json in test suite at http://www.json.org/JSON_checker/
            var input = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("array")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenElementBegin(new DataName("item")),
                MarkupGrammar.TokenPrimitive("Not too deep"),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd
            };
            var expected = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenArrayBegin(new DataName("item")),
                ModelGrammar.TokenPrimitive("Not too deep"),
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd,
                ModelGrammar.TokenArrayEnd
            };

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

            Assert.Equal(expected, actual);
        }