Пример #1
0
            public void ReturnsValidDirectivesWithDeclarations()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                string        configScript = @"#valid a
A=
=B
#invalid b
C
---
E-
#valid c
-F";

                // When
                ConfigParserResult result = ConfigParser.Parse(configScript, preprocessor);

                // Then
                Assert.AreEqual(@"#line 1
//#valid a
A=
=B
#invalid b
C", result.Declarations);
                Assert.AreEqual(@"#line 7
E-
//#valid c
-F", result.Body);
                CollectionAssert.AreEqual(new[]
                {
                    Tuple.Create((int?)1, "valid", "a"),
                    Tuple.Create((int?)8, "valid", "c")
                }, result.DirectiveValues.Select(x => Tuple.Create(x.Line, x.Name, x.Value)));
            }
Пример #2
0
            public void ReturnsDeclarationsWithDelimiterWithLeadingSpaces()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                string        configScript = @"A=
=B
    ===
=C
D
    ---
-E
F";

                // When
                ConfigParserResult result = ConfigParser.Parse(configScript, preprocessor);

                // Then
                Assert.IsNull(result.Declarations);
                Assert.AreEqual(@"#line 1
A=
=B
    ===
=C
D
    ---
-E
F", result.Body);
            }
Пример #3
0
            public void ReturnsValidDirectives()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                string        configScript = @"#valid a b c
#invalid a b c
#validx y z
A=
=B
#valid   x y z  
C";

                // When
                ConfigParserResult result = ConfigParser.Parse(configScript, preprocessor);

                // Then
                Assert.IsNull(result.Declarations);
                Assert.AreEqual(@"#line 1
//#valid a b c
#invalid a b c
#validx y z
A=
=B
//#valid   x y z  
C", result.Body);
                CollectionAssert.AreEqual(new []
                {
                    Tuple.Create((int?)1, "valid", "a b c"),
                    Tuple.Create((int?)6, "valid", "x y z")
                }, result.DirectiveValues.Select(x => Tuple.Create(x.Line, x.Name, x.Value)));
            }
Пример #4
0
            public void ReturnsDeclarationsWithDelimiterWithExtraLines()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                string        configScript = @"A-
=B
-C
D

---

E-
-F";

                // When
                ConfigParserResult result = ConfigParser.Parse(configScript, preprocessor);

                // Then
                Assert.AreEqual(@"#line 1
A-
=B
-C
D
", result.Declarations);
                Assert.AreEqual(@"#line 7

E-
-F", result.Body);
            }
Пример #5
0
            public void DoesNotProcessDirectivesWithSpaceAfterHash()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                string        configScript = @"# valid a b c
A";

                // When
                ConfigParserResult result = ConfigParser.Parse(configScript, preprocessor);

                // Then
                Assert.IsNull(result.Declarations);
                Assert.AreEqual(@"#line 1
# valid a b c
A", result.Body);
                CollectionAssert.IsEmpty(result.DirectiveValues);
            }
Пример #6
0
            public void ReturnsConfigWithoutDelimiter()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                string        configScript = @"A=
=B
C";

                // When
                ConfigParserResult result = ConfigParser.Parse(configScript, preprocessor);

                // Then
                Assert.IsNull(result.Declarations);
                Assert.AreEqual(@"#line 1
A=
=B
C", result.Body);
            }
Пример #7
0
            public void ReturnsDeclarations()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                string        configScript = @"A=
=B
C
---
E-
-F";

                // When
                ConfigParserResult result = ConfigParser.Parse(configScript, preprocessor);

                // Then
                Assert.AreEqual(@"#line 1
A=
=B
C", result.Declarations);
                Assert.AreEqual(@"#line 5
E-
-F", result.Body);
            }