public IEnumerator ReadFromAsyncWithCommentHandlingLoadOnJsonWithCommentReadsComment() { yield return(AsyncUtils.Run(TestAsync)); async Task TestAsync() { using (var textReader = new StringReader(k_TestJsonWithComment)) using (var jsonReader = new JsonTextReader(textReader)) { var a = (JArray)await JToken.ReadFromAsync( jsonReader, new JsonLoadSettings { CommentHandling = CommentHandling.Load }); Assert.AreEqual(4, a.Count); Assert.AreEqual(JTokenType.Comment, a[0].Type); Assert.AreEqual(" hi", ((JValue)a[0]).Value); } } }
public IEnumerator ReadFromAsyncWithCommentHandlingLoadOnJsonStartingWithCommentReadsComment() { yield return(AsyncUtils.Run(TestAsync)); async Task TestAsync() { using (var textReader = new StringReader(k_TestJsonStartingWithComment)) using (var jsonReader = new JsonTextReader(textReader)) { var v = (JValue)await JToken.ReadFromAsync( jsonReader, new JsonLoadSettings { CommentHandling = CommentHandling.Load }); Assert.AreEqual(JTokenType.Comment, v.Type); IJsonLineInfo lineInfo = v; Assert.AreEqual(true, lineInfo.HasLineInfo()); Assert.AreEqual(2, lineInfo.LineNumber); Assert.AreEqual(5, lineInfo.LinePosition); } } }
public IEnumerator ReadFromAsyncStartingAtArrayEndThrows() { yield return(AsyncUtils.Run(TestAsync)); async Task TestAsync() { var textReader = new StringReader(@"[]"); var jsonReader = new JsonTextReader(textReader); await jsonReader.ReadAsync(); await jsonReader.ReadAsync(); await AsyncUtils.ThrowsAsync <JsonReaderException>(ReadFromAsync); async Task ReadFromAsync() { using (textReader) using (jsonReader) { await JToken.ReadFromAsync(jsonReader); } } } }
public IEnumerator ReadFromAsyncOnJsonStartingWithCommentIgnoresComment() { yield return(AsyncUtils.Run(TestAsync)); async Task TestAsync() { using (var textReader = new StringReader(k_TestJsonStartingWithComment)) using (var jsonReader = new JsonTextReader(textReader)) { var a = (JArray)await JToken.ReadFromAsync( jsonReader, new JsonLoadSettings { CommentHandling = CommentHandling.Ignore }); Assert.AreEqual(JTokenType.Array, a.Type); IJsonLineInfo lineInfo = a; Assert.AreEqual(true, lineInfo.HasLineInfo()); Assert.AreEqual(3, lineInfo.LineNumber); Assert.AreEqual(1, lineInfo.LinePosition); } } }