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); }
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); }
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); }
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); }
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); }
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); }
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); }
public void Format_ArrayMultiItem_ReturnsExpectedArray() { var input = new[] { ModelGrammar.TokenArrayBeginUnnamed, ModelGrammar.TokenPrimitive(0), ModelGrammar.TokenNull, ModelGrammar.TokenFalse, ModelGrammar.TokenTrue, ModelGrammar.TokenArrayEnd }; var expected = new[] { MarkupGrammar.TokenElementBegin(new DataName("div")), MarkupGrammar.TokenElementBegin(new DataName("ol")), MarkupGrammar.TokenElementBegin(new DataName("li")), MarkupGrammar.TokenPrimitive(0), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementBegin(new DataName("li")), MarkupGrammar.TokenPrimitive(null), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementBegin(new DataName("li")), MarkupGrammar.TokenPrimitive(false), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementBegin(new DataName("li")), MarkupGrammar.TokenPrimitive(true), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd }; var transformer = new HtmlOutTransformer(); var actual = transformer.Transform(input).ToArray(); Assert.Equal(expected, actual); }