Ejemplo n.º 1
0
        public void Format_ArrayOneItem_ReturnsExpectedArray()
        {
            var input = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenNull,
                ModelGrammar.TokenArrayEnd
            };

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

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

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        public void Format_NamespacedObjectOneProperty_CorrectlyEmitsNamespace()
        {
            var input = new[]
            {
                ModelGrammar.TokenObjectBegin("foo"),
                ModelGrammar.TokenProperty(new DataName("key", String.Empty, "http://json.org")),
                ModelGrammar.TokenPrimitive("value"),
                ModelGrammar.TokenObjectEnd
            };

            var expected = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("div")),
                MarkupGrammar.TokenElementBegin(new DataName("dl")),
                MarkupGrammar.TokenAttribute(new DataName("title")),
                MarkupGrammar.TokenPrimitive(new DataName("foo")),
                MarkupGrammar.TokenElementBegin(new DataName("dt")),
                MarkupGrammar.TokenPrimitive(new DataName("key", String.Empty, "http://json.org")),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementBegin(new DataName("dd")),
                MarkupGrammar.TokenPrimitive("value"),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd
            };

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

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

            var expected = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("div")),
                MarkupGrammar.TokenElementBegin(new DataName("dl")),
                MarkupGrammar.TokenAttribute(new DataName("title")),
                MarkupGrammar.TokenPrimitive(new DataName("Yada")),
                MarkupGrammar.TokenElementBegin(new DataName("dt")),
                MarkupGrammar.TokenPrimitive(new DataName("key")),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementBegin(new DataName("dd")),
                MarkupGrammar.TokenPrimitive("value"),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd
            };

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

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 4
0
        public void Format_EmptyInput_RendersEmptyString()
        {
            var input = Enumerable.Empty <Token <ModelTokenType> >();

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

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

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

            var transformer = new HtmlOutTransformer();

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

            // verify exception is coming from expected param
            Assert.Equal("input", ex.ParamName);
        }
Ejemplo n.º 6
0
        public void Format_ObjectNested_RendersNestedObject()
        {
            // input from pass3.json in test suite at http://www.json.org/JSON_checker/
            var input = 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 expected = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("div")),
                MarkupGrammar.TokenElementBegin(new DataName("dl")),
                MarkupGrammar.TokenElementBegin(new DataName("dt")),
                MarkupGrammar.TokenPrimitive(new DataName("JSON Test Pattern pass3")),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementBegin(new DataName("dd")),
                MarkupGrammar.TokenElementBegin(new DataName("dl")),
                MarkupGrammar.TokenElementBegin(new DataName("dt")),
                MarkupGrammar.TokenPrimitive(new DataName("The outermost value")),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementBegin(new DataName("dd")),
                MarkupGrammar.TokenPrimitive("must be an object or array."),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementBegin(new DataName("dt")),
                MarkupGrammar.TokenPrimitive(new DataName("In this test")),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementBegin(new DataName("dd")),
                MarkupGrammar.TokenPrimitive("It is an object."),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd
            };

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

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 7
0
        public void Format_ObjectEmpty_RendersEmptyObject()
        {
            var input = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenObjectEnd
            };

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

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

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 8
0
        public void Format_ArrayNestedDeeply_ReturnsExpectedArray()
        {
            // input from pass2.json in test suite at http://www.json.org/JSON_checker/
            var input = new[]
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenArrayBeginUnnamed,
                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 expected = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("div")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                MarkupGrammar.TokenElementBegin(new DataName("ol")),
                MarkupGrammar.TokenElementBegin(new DataName("li")),
                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,
                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 transformer = new HtmlOutTransformer();
            var actual      = transformer.Transform(input).ToArray();

            Assert.Equal(expected, actual);
        }