public void CannotInitializeWithReaderOnArray() { JsonReader reader = JsonText.CreateReader("[]"); reader.MoveToContent(); new FreeJsonMemberReadingHelper(reader); }
public void InitializeWithReaderOnObjectStart() { JsonReader reader = JsonText.CreateReader("{}"); reader.MoveToContent(); new FreeJsonMemberReadingHelper(reader); }
/// <summary> /// Make an JSON external form string of this JsonArray. For /// compactness, no unnecessary whitespace is added. /// </summary> /// <remarks> /// This method assumes that the data structure is acyclical. /// </remarks> public override string ToString() { StringWriter writer = new StringWriter(); Export(JsonText.CreateWriter(writer)); return(writer.ToString()); }
public void CannotInitializeWithReaderOnEnd() { JsonReader reader = JsonText.CreateReader("42"); reader.ReadNumber(); new FreeJsonMemberReadingHelper(reader); }
public void CannotInitializeWithReaderOnString() { var reader = JsonText.CreateReader("foobar"); reader.MoveToContent(); new FreeJsonMemberReadingHelper(reader); }
public void CannotInitializeWithReaderOnBoolean() { var reader = JsonText.CreateReader("true"); reader.MoveToContent(); new FreeJsonMemberReadingHelper(reader); }
public void BaseReaderInitialization() { JsonReader reader = JsonText.CreateReader("[]"); FreeJsonMemberReadingHelper helper = new FreeJsonMemberReadingHelper(reader); Assert.AreSame(reader, helper.BaseReader); }
public void InitializeWithReaderOnMember() { JsonReader reader = JsonText.CreateReader("{foo:bar}"); reader.MoveToContent(); reader.ReadToken(JsonTokenClass.Object); new FreeJsonMemberReadingHelper(reader); }
public void CreateObject() { ObjectSurrogateConstructor ctor = new ObjectSurrogateConstructor(typeof(Surrogate)); ImportContext context = new ImportContext(); ObjectConstructionResult result = ctor.CreateObject(context, JsonText.CreateReader("{y:2000,m:12,d:4}")); Assert.IsNotNull(result); Assert.AreEqual(new DateTime(2000, 12, 4), result.Object); }
public void BufferValueOnBOF() { var writer = new JsonBufferWriter(); writer.WriteFromReader(JsonText.CreateReader("[]")); var buffer = writer.GetBuffer().CreateReader().BufferValue(); Assert.AreEqual(2, buffer.Length); Assert.AreEqual(JsonToken.Array(), buffer[0]); Assert.AreEqual(JsonToken.EndArray(), buffer[1]); }
public void BufferValueOnMember() { var writer = new JsonBufferWriter(); writer.WriteFromReader(JsonText.CreateReader("{foo:bar}")); var reader = writer.GetBuffer().CreateReader(); reader.Read(); // object start reader.Read(); // foo Assert.AreEqual(JsonToken.String("bar"), reader.BufferValue().CreateReader().Token); }
public void BufferValueOnEOF() { var writer = new JsonBufferWriter(); writer.WriteFromReader(JsonText.CreateReader("[]")); var reader = writer.GetBuffer().CreateReader(); reader.Read(); // array start reader.Read(); // array end Assert.IsTrue(reader.BufferValue().IsEmpty); }
public void BufferValueOnObjectEnd() { var writer = new JsonBufferWriter(); writer.WriteFromReader(JsonText.CreateReader("[{},foo]")); var reader = writer.GetBuffer().CreateReader(); reader.Read(); // outer object start reader.Read(); // inner object start reader.Read(); // inner object end Assert.AreEqual(JsonToken.String("foo"), reader.BufferValue()[0]); }
public void BufferValueOnArrayEnd() { JsonBufferWriter writer = new JsonBufferWriter(); writer.WriteFromReader(JsonText.CreateReader("[[],foo]")); JsonBufferReader reader = writer.GetBuffer().CreateReader(); reader.Read(); // outer array start reader.Read(); // inner array start reader.Read(); // inner array end Assert.AreEqual(JsonToken.String("foo"), reader.BufferValue()[0]); }
public void ImportNonObjectMember() { var surrogate = new Surrogate(new object()); var context = new ImportContext(); surrogate.Import(context, "foo", JsonText.CreateReader("bar")); var tail = surrogate.CreateObject(context).TailReader; tail.ReadToken(JsonTokenClass.Object); Assert.AreEqual("foo", tail.ReadMember()); Assert.AreEqual("bar", tail.ReadString()); tail.ReadToken(JsonTokenClass.EndObject); }
/// <summary> /// Returns the content of the buffer formatted as JSON text. /// </summary> public override string ToString() { if (IsEmpty) { return(string.Empty); } if (IsNull) { return(JsonNull.Text); } if (FirstToken.Class == JsonTokenClass.String) { return(JsonString.Enquote(FirstToken.Text)); } if (IsScalar) { return(FirstToken.Text); } StringBuilder sb = new StringBuilder(); JsonText.CreateWriter(sb).WriteFromReader(CreateReader()); return(sb.ToString()); }
public static JsonBuffer From(string json) { return(From(JsonText.CreateReader(json))); }
private static FreeJsonMemberReadingHelper CreateHelper(string json) { return(new FreeJsonMemberReadingHelper(JsonText.CreateReader(json))); }