コード例 #1
0
        public IEnumerator ReadFromAsyncOnJsonWithCommentIgnoresComment()
        {
            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);

                        Assert.AreEqual(3, a.Count);
                        Assert.AreEqual(JTokenType.Integer, a[0].Type);
                        Assert.AreEqual(1L, ((JValue)a[0]).Value);
                    }
            }
        }
コード例 #2
0
        public IEnumerator ReadFromAsyncOnJsonStartingUndefinedSucceeds()
        {
            yield return(AsyncUtils.Run(TestAsync));

            async Task TestAsync()
            {
                using (var textReader = new StringReader(k_TestJsonStartingWithUndefined))
                    using (var jsonReader = new JsonTextReader(textReader))
                    {
                        var v = (JValue)await JToken.ReadFromAsync(jsonReader);

                        Assert.AreEqual(JTokenType.Undefined, v.Type);
                        IJsonLineInfo lineInfo = v;
                        Assert.AreEqual(true, lineInfo.HasLineInfo());
                        Assert.AreEqual(2, lineInfo.LineNumber);
                        Assert.AreEqual(9, lineInfo.LinePosition);
                    }
            }
        }
コード例 #3
0
        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);
                    }
            }
        }
コード例 #4
0
        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);
                        }
                }
            }
        }
コード例 #5
0
        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);
                    }
            }
        }
コード例 #6
0
        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);
                    }
            }
        }