public void Format_NestedObjectsAlternatingNamespaces_CorrectlyEmitsNamespaces() { var input = 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("foo2", String.Empty, "http://jsonfx.net")), ModelGrammar.TokenProperty(new DataName("key2", String.Empty, "http://json.org")), ModelGrammar.TokenPrimitive("value"), ModelGrammar.TokenObjectEnd, ModelGrammar.TokenObjectEnd }; var expected = 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 transformer = new XmlWriter.XmlOutTransformer(new DataWriterSettings()); 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("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 transformer = new XmlWriter.XmlOutTransformer(new DataWriterSettings()); 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("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 transformer = new XmlWriter.XmlOutTransformer(new DataWriterSettings()); var actual = transformer.Transform(input).ToArray(); Assert.Equal(expected, actual); }
public void Ctor_NullSettings_ThrowsArgumentNullException() { ArgumentNullException ex = Assert.Throws <ArgumentNullException>( delegate { var transformer = new XmlWriter.XmlOutTransformer(null); }); // verify exception is coming from expected param Assert.Equal("settings", ex.ParamName); }
public void Format_EmptyInput_RendersEmptyString() { var input = Enumerable.Empty <Token <ModelTokenType> >(); var expected = Enumerable.Empty <Token <MarkupTokenType> >(); var transformer = new XmlWriter.XmlOutTransformer(new DataWriterSettings()); var actual = transformer.Transform(input).ToArray(); Assert.Equal(expected, actual); }
public void Format_NullInput_ThrowsArgumentNullException() { var input = (IEnumerable <Token <ModelTokenType> >)null; var transformer = new XmlWriter.XmlOutTransformer(new DataWriterSettings()); 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_ArrayEmpty_ReturnsEmptyArray() { var input = new[] { ModelGrammar.TokenArrayBeginUnnamed, ModelGrammar.TokenArrayEnd }; var expected = new[] { MarkupGrammar.TokenElementBegin(new DataName("array")), MarkupGrammar.TokenElementEnd }; var transformer = new XmlWriter.XmlOutTransformer(new DataWriterSettings()); var actual = transformer.Transform(input).ToArray(); Assert.Equal(expected, actual); }
public void Format_ObjectAndAttributeShareNamespace_CorrectlyEmitsNamespace() { var input = 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 expected = 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 transformer = new XmlWriter.XmlOutTransformer(new DataWriterSettings()); 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("Yada")), MarkupGrammar.TokenElementBegin(new DataName("key")), MarkupGrammar.TokenPrimitive("value"), MarkupGrammar.TokenElementEnd, MarkupGrammar.TokenElementEnd, }; var transformer = new XmlWriter.XmlOutTransformer(new DataWriterSettings()); 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("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 transformer = new XmlWriter.XmlOutTransformer(new DataWriterSettings()); var actual = transformer.Transform(input).ToArray(); Assert.Equal(expected, actual); }