public BlockNode ParseControl()
        {
            var p       = _yaml.ReadNext();
            var control = ParseNestedControl(p);

            if (_yaml._commentStrippedWarning.HasValue)
            {
                this._errorContainer.YamlWontRoundTrip(_yaml._commentStrippedWarning.Value, "Yaml comments don't roundtrip.");
            }

            return(control);
        }
Beispiel #2
0
        public void NewLinesRoundtrip(string value)
        {
            var sw = new StringWriter();
            var yw = new YamlWriter(sw);

            yw.WriteProperty("Foo", value);

            var text = sw.ToString();

            var normalizedValue = NormNewlines(value);

            // Validate it passes YamlDotNet
            var valueFromYaml = ParseSinglePropertyViaYamlDotNot(text);

            Assert.AreEqual(normalizedValue, NormNewlines(valueFromYaml));

            // Validate it passes our subset.
            var sr = new StringReader(text);
            var y  = new YamlLexer(sr);
            var p  = y.ReadNext();

            Assert.AreEqual(YamlTokenKind.Property, p.Kind);
            Assert.AreEqual("Foo", p.Property);

            Assert.AreEqual(normalizedValue, NormNewlines(p.Value));
        }
Beispiel #3
0
        static void AssertLex(string expected, YamlLexer y, string sourceSpan)
        {
            var p = y.ReadNext();

            Assert.AreEqual(expected, p.ToString());
            Assert.AreEqual(sourceSpan, p.Span.ToString());
        }
        public void NewLinesRoundtrip(string value)
        {
            var sw = new StringWriter();
            var yw = new YamlWriter(sw);

            yw.WriteProperty("Foo", value);

            var text = sw.ToString();

            // Validate it passes YamlDotNet
            var valueFromYaml = ParseSinglePropertyViaYamlDotNot(text);
            var valueWithoutR = value.Replace("\r", ""); // yamlDotNet doesn't do \R

            Assert.AreEqual(valueWithoutR, valueFromYaml);

            // Validate it passes our subset.
            var sr = new StringReader(text);
            var y  = new YamlLexer(sr);
            var p  = y.ReadNext();

            Assert.AreEqual(YamlTokenKind.Property, p.Kind);
            Assert.AreEqual("Foo", p.Property);

            Assert.AreEqual(value, p.Value);
        }
Beispiel #5
0
        public static Dictionary <string, string> Read(TextReader reader, string filenameHint = null)
        {
            var properties = new Dictionary <string, string>(StringComparer.Ordinal);

            var yaml = new YamlLexer(reader, filenameHint);

            while (true)
            {
                var t = yaml.ReadNext();
                if (t.Kind == YamlTokenKind.EndOfFile)
                {
                    break;
                }

                if (t.Kind != YamlTokenKind.Property)
                {
                    // $$$ error
                    t = YamlToken.NewError(t.Span, "Only properties are supported in this context");
                }
                if (t.Kind == YamlTokenKind.Error)
                {
                    // ToString will include source span  and message.
                    throw new InvalidOperationException(t.ToString());
                }

                properties[t.Property] = t.Value;
            }
            return(properties);
        }
Beispiel #6
0
        [DataRow("Foo:\r\n  val\r\n")] // Must have escape if there's a newline
        public void ExpectedError2(string expr)
        {
            var sr = new StringReader(expr);
            var y  = new YamlLexer(sr);

            var tokenOk = y.ReadNext();

            Assert.AreNotEqual(YamlTokenKind.Error, tokenOk.Kind);

            AssertLexError(y);
        }
Beispiel #7
0
        private static YamlToken[] ReadAllTokens(string text)
        {
            var sr = new StringReader(text);
            var y  = new YamlLexer(sr);

            List <YamlToken> tokens = new List <YamlToken>();
            YamlToken        token;

            do
            {
                token = y.ReadNext();
                tokens.Add(token);
                Assert.AreNotEqual(YamlTokenKind.Error, token.Kind);

                // Fragments are small. If we don't terminate, there's a parser bug.
                Assert.IsTrue(tokens.Count < 100, "fragment failed to parse to EOF");
            } while (token.Kind != YamlTokenKind.EndOfFile);
            return(tokens.ToArray());
        }
Beispiel #8
0
        static void AssertLex(string expected, YamlLexer y)
        {
            var p = y.ReadNext();

            Assert.AreEqual(expected, p.ToString());
        }
Beispiel #9
0
        static void AssertLexError(YamlLexer y)
        {
            var p = y.ReadNext();

            Assert.AreEqual(YamlTokenKind.Error, p.Kind);
        }
Beispiel #10
0
        public BlockNode ParseControl()
        {
            var p = _yaml.ReadNext();

            return(ParseNestedControl(p));
        }