public void ShouldParseFullBlockMixedWithGlobalAssignments()
        {
            var input = @"gProp =1;block {prop = 1;prop2 = ""string"";}gProp2 = 5;";

            var syntaxAnalzer = new UdmfSyntaxAnalyzer();
            var result        = syntaxAnalzer.Analyze(new UdmfLexer(new StringReader(input)));

            Assert.That(result.Blocks, Has.Count.EqualTo(1), "Did not parse out a block");

            var block = result.Blocks.First();

            Assert.That(block.Name, Is.EqualTo(new Identifier("block")), "Did not get correct name.");
            Assert.That(block.ToArray(), Is.EqualTo(new[]
            {
                new Assignment(new Identifier("prop"), Token.Integer(1)),
                new Assignment(new Identifier("prop2"), Token.String("string"))
            }), "Did not parse assignments.");

            Assert.That(
                result.GetGlobalAssignments().ToArray(),
                Is.EqualTo(new[]
            {
                new Assignment(new Identifier("gProp"), Token.Integer(1)),
                new Assignment(new Identifier("gProp2"), Token.Integer(5))
            }),
                "Did not parse the assignments.");
        }
 public void ShouldParseOldDemoMap()
 {
     using (var stream = File.OpenRead(Path.Combine(TestContext.CurrentContext.TestDirectory, "PigletVersion", "TEXTMAP.txt")))
         using (var textReader = new StreamReader(stream, Encoding.ASCII))
         {
             var sa  = new UdmfSyntaxAnalyzer();
             var map = UdmfParser.Parse(sa.Analyze(new UdmfLexer(textReader)));
         }
 }
        public void ShouldParseGlobalAssignment()
        {
            var input = @"prop = 1;";

            var syntaxAnalzer = new UdmfSyntaxAnalyzer();
            var result        = syntaxAnalzer.Analyze(new UdmfLexer(new StringReader(input)));

            Assert.That(
                result.GetGlobalAssignments().ToArray(),
                Is.EqualTo(new[] { new Assignment(new Identifier("prop"), Token.Integer(1)) }),
                "Did not parse the assignment.");
        }
        public void ShouldParseEmptyBlock()
        {
            var input = @"block {}";

            var syntaxAnalzer = new UdmfSyntaxAnalyzer();
            var result        = syntaxAnalzer.Analyze(new UdmfLexer(new StringReader(input)));

            Assert.That(result.Blocks, Has.Count.EqualTo(1), "Did not parse out a block");

            var block = result.Blocks.First();

            Assert.That(block.Name, Is.EqualTo(new Identifier("block")), "Did not get correct name.");
        }
        public void ShouldParseArrayBlockWitMultipleTuples()
        {
            var input = @"block {{1,2,3},{4,5,6},{7,8,9,10}}";

            var syntaxAnalzer = new UdmfSyntaxAnalyzer();
            var result        = syntaxAnalzer.Analyze(new UdmfLexer(new StringReader(input)));

            Assert.That(result.ArrayBlocks, Has.Count.EqualTo(1), "Did not parse out a block");

            var block = result.ArrayBlocks.First();

            Assert.That(block.Name, Is.EqualTo(new Identifier("block")), "Did not get correct name.");
            Assert.That(block[0], Is.EqualTo(new[] { 1, 2, 3 }));
            Assert.That(block[1], Is.EqualTo(new[] { 4, 5, 6 }));
            Assert.That(block[2], Is.EqualTo(new[] { 7, 8, 9, 10 }));
        }
        public void ShouldRoundTripDemoMap()
        {
            var map = DemoMap.Create();

            using (var stream = new MemoryStream())
            {
                map.WriteTo(stream);

                stream.Position = 0;

                using (var textReader = new StreamReader(stream, Encoding.ASCII))
                {
                    var sa           = new UdmfSyntaxAnalyzer();
                    var roundTripped = UdmfParser.Parse(sa.Analyze(new UdmfLexer(textReader)));

                    Assert.That(roundTripped, Is.DeepEqualTo(map));
                }
            }
        }