Exemple #1
0
        public void RoundtripSample()
        {
            var original = new YamlStream();

            original.Load(YamlFile("sample.yaml"));
            original.Accept(new TracingVisitor());
        }
Exemple #2
0
        private void RoundtripTest(string yamlFileName)
        {
            var original = new YamlStream();

            original.Load(Yaml.ReaderFrom(yamlFileName));

            var buffer = new StringBuilder();

            original.Save(new StringWriter(buffer));

            var final = new YamlStream();

            final.Load(new StringReader(buffer.ToString()));

            var originalBuilder = new YamlDocumentStructureBuilder();

            original.Accept(originalBuilder);

            var finalBuilder = new YamlDocumentStructureBuilder();

            final.Accept(finalBuilder);

            Assert.Equal(originalBuilder.Events.Count, finalBuilder.Events.Count);

            for (var i = 0; i < originalBuilder.Events.Count; ++i)
            {
                var originalEvent = originalBuilder.Events[i];
                var finalEvent    = finalBuilder.Events[i];

                Assert.Equal(originalEvent.Type, finalEvent.Type);
                Assert.Equal(originalEvent.Value, finalEvent.Value);
            }
        }
        public void Run(string[] args)
        {
            var original = new YamlStream();

            original.Load(new StringReader(Sample));
            original.Accept(new TracingVisitor());
        }
Exemple #4
0
 private static NamedModel ParseModel(string input)
 {
     if (input == null) throw new ArgumentNullException("input");
     using (var yamlSource = File.OpenText(input))
     {
         var stream = new YamlStream();
         stream.Load(yamlSource);
         var visitor = new ComposeNamedModelVisitor();
         stream.Accept(visitor);
         return visitor.Model;
     }
 }
        public void AllAliasesMustBeResolved()
        {
            YamlStream original = new YamlStream();
            original.Load(YamlFile("invalid-reference.yaml"));

            var visitor = new AliasFindingVisitor();

            try
            {
                original.Accept(visitor);
            }
            catch (NotSupportedException)
            {
                foreach (var node in visitor.CurrentPath)
                {
                    TestContext.WriteLine(node.ToString());
                }

                Assert.Fail();
            }
        }
Exemple #6
0
        private void RoundtripTest(string yamlFileName)
        {
            YamlStream original = new YamlStream();

            original.Load(YamlFile(yamlFileName));

            StringBuilder buffer = new StringBuilder();

            original.Save(new StringWriter(buffer));

            Console.WriteLine(buffer.ToString());

            YamlStream final = new YamlStream();

            final.Load(new StringReader(buffer.ToString()));

            YamlDocumentStructureBuilder originalBuilder = new YamlDocumentStructureBuilder();

            original.Accept(originalBuilder);

            YamlDocumentStructureBuilder finalBuilder = new YamlDocumentStructureBuilder();

            final.Accept(finalBuilder);

            Console.WriteLine("The original document produced {0} events.", originalBuilder.Events.Count);
            Console.WriteLine("The final document produced {0} events.", finalBuilder.Events.Count);
            Assert.Equal(originalBuilder.Events.Count, finalBuilder.Events.Count);

            for (int i = 0; i < originalBuilder.Events.Count; ++i)
            {
                YamlNodeEvent originalEvent = originalBuilder.Events[i];
                YamlNodeEvent finalEvent    = finalBuilder.Events[i];

                Assert.Equal(originalEvent.Type, finalEvent.Type);
                //Assert.Equal(originalEvent.Tag, finalEvent.Tag);
                //Assert.Equal(originalEvent.Anchor, finalEvent.Anchor);
                Assert.Equal(originalEvent.Value, finalEvent.Value);
            }
        }
Exemple #7
0
        public void AllAliasesMustBeResolved()
        {
            YamlStream original = new YamlStream();

            original.Load(YamlFile("invalid-reference.yaml"));

            var visitor = new AliasFindingVisitor();

            try
            {
                original.Accept(visitor);
            }
            catch (NotSupportedException)
            {
                foreach (var node in visitor.CurrentPath)
                {
                    TestContext.WriteLine(node.ToString());
                }

                Assert.Fail();
            }
        }
        public IDictionary<string, string> Parse(Stream input)
        {
            IDictionary<string, string> data = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            var visitor = new ContextAwareVisitor();

            var yamlStream = new YamlStream();

            using (var reader = new StreamReader(input))
            {
                yamlStream.Load(reader);

            }

            if (!yamlStream.Documents.Any())
            {
                return data;
            }

            yamlStream.Accept(visitor);

            foreach (var item in visitor.Items)
            {
                var key = item.Key;

                if (!string.IsNullOrEmpty(this.root))
                {
                    key = ConfigurationPath.Combine(this.root, key);
                }

                if (data.ContainsKey(key))
                {
                    throw new FormatException(string.Format("The key '{0}' is duplicated.", key));
                }
                data[key] = item.Value;
            }

            return data;
        }
Exemple #9
0
        public IDictionary <string, string> Parse(Stream input)
        {
            IDictionary <string, string> data = new SortedDictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            var visitor = new ContextAwareVisitor();

            var yamlStream = new YamlStream();

            using (var reader = new StreamReader(input))
            {
                yamlStream.Load(reader);
            }

            if (!yamlStream.Documents.Any())
            {
                return(data);
            }

            yamlStream.Accept(visitor);

            foreach (var item in visitor.Items)
            {
                var key = item.Key;

                if (!string.IsNullOrEmpty(this.root))
                {
                    key = ConfigurationPath.Combine(this.root, key);
                }

                if (data.ContainsKey(key))
                {
                    throw new FormatException(string.Format("The key '{0}' is duplicated.", key));
                }
                data[key] = item.Value;
            }

            return(data);
        }
		public void RoundtripSample()
		{
			var original = new YamlStream();
			original.Load(YamlFile("sample.yaml"));
			original.Accept(new TracingVisitor());
		}
		private void RoundtripTest(string yamlFileName)
		{
			var original = new YamlStream();
			original.Load(YamlFile(yamlFileName));

			var buffer = new StringBuilder();
			original.Save(new StringWriter(buffer));

			Dump.WriteLine(buffer);

			var final = new YamlStream();
			final.Load(new StringReader(buffer.ToString()));

			var originalBuilder = new YamlDocumentStructureBuilder();
			original.Accept(originalBuilder);

			var finalBuilder = new YamlDocumentStructureBuilder();
			final.Accept(finalBuilder);

			Dump.WriteLine("The original document produced {0} events.", originalBuilder.Events.Count);
			Dump.WriteLine("The final document produced {0} events.", finalBuilder.Events.Count);
			Assert.AreEqual(originalBuilder.Events.Count, finalBuilder.Events.Count);

			for (var i = 0; i < originalBuilder.Events.Count; ++i)
			{
				var originalEvent = originalBuilder.Events[i];
				var finalEvent = finalBuilder.Events[i];

				Assert.AreEqual(originalEvent.Type, finalEvent.Type);
				Assert.AreEqual(originalEvent.Value, finalEvent.Value);
			}
		}
		public void Run(string[] args)
		{
			var original = new YamlStream();
			original.Load(new StringReader(Sample));
			original.Accept(new TracingVisitor());
		}
Exemple #13
0
        private void RoundtripTest(string yamlFileName)
        {
            YamlStream original = new YamlStream();
            original.Load(YamlFile(yamlFileName));

            StringBuilder buffer = new StringBuilder();
            original.Save(new StringWriter(buffer));

            Console.WriteLine(buffer.ToString());

            YamlStream final = new YamlStream();
            final.Load(new StringReader(buffer.ToString()));

            YamlDocumentStructureBuilder originalBuilder = new YamlDocumentStructureBuilder();
            original.Accept(originalBuilder);

            YamlDocumentStructureBuilder finalBuilder = new YamlDocumentStructureBuilder();
            final.Accept(finalBuilder);

            Console.WriteLine("The original document produced {0} events.", originalBuilder.Events.Count);
            Console.WriteLine("The final document produced {0} events.", finalBuilder.Events.Count);
            Assert.Equal(originalBuilder.Events.Count, finalBuilder.Events.Count);

            for (int i = 0; i < originalBuilder.Events.Count; ++i)
            {
                YamlNodeEvent originalEvent = originalBuilder.Events[i];
                YamlNodeEvent finalEvent = finalBuilder.Events[i];

                Assert.Equal(originalEvent.Type, finalEvent.Type);
                //Assert.Equal(originalEvent.Tag, finalEvent.Tag);
                //Assert.Equal(originalEvent.Anchor, finalEvent.Anchor);
                Assert.Equal(originalEvent.Value, finalEvent.Value);
            }
        }