예제 #1
0
            public void ReturnsAndCommentsValidDirectives()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"#valid a b c
#invalid a b c
#validx y z
A=
=B
#valid   x y z  
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                Assert.AreEqual(@"//#valid a b c
#invalid a b c
#validx y z
A=
=B
//#valid   x y z  
C", directiveParser.Code);
                CollectionAssert.AreEqual(new[]
                {
                    Tuple.Create((int?)1, "valid", "a b c"),
                    Tuple.Create((int?)6, "valid", "x y z")
                }, directiveParser.DirectiveValues.Select(x => Tuple.Create(x.Line, x.Name, x.Value)));
            }
예제 #2
0
            public void ReturnsAndCommentsValidDirectives()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string configScript = @"#valid a b c
#invalid a b c
#validx y z
A=
=B
#valid   x y z  
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                Assert.AreEqual(@"//#valid a b c
#invalid a b c
#validx y z
A=
=B
//#valid   x y z  
C", directiveParser.Code);
                CollectionAssert.AreEqual(new[]
                {
                    Tuple.Create((int?)1, "valid", "a b c"),
                    Tuple.Create((int?)6, "valid", "x y z")
                }, directiveParser.DirectiveValues.Select(x => Tuple.Create(x.Line, x.Name, x.Value)));
            }
            public void ReturnsAndCommentsValidDirectives()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                const string    configScript    = @"#valid a b c
#invalid a b c
#validx y z
A=
=B
#valid   x y z  
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                directiveParser.Code.ShouldBe(
                    @"//#valid a b c
#invalid a b c
#validx y z
A=
=B
//#valid   x y z  
C", StringCompareShould.IgnoreLineEndings);

                directiveParser.DirectiveValues
                .Select(x => Tuple.Create(x.Line, x.Name, x.Value))
                .ShouldBe(
                    new[]
                {
                    Tuple.Create((int?)1, "valid", "a b c"),
                    Tuple.Create((int?)6, "valid", "x y z")
                });
            }
예제 #4
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)));
            }
예제 #5
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);
            }
예제 #6
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)));
            }
예제 #7
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);
            }
예제 #8
0
            public void DoesNotProcessDirectivesWithSpaceAfterHash()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string configScript = @"# valid a b c
            A";

                // When
                directiveParser.Parse(configScript);

                // Then
                Assert.AreEqual(@"# valid a b c
            A", directiveParser.Code);
                CollectionAssert.IsEmpty(directiveParser.DirectiveValues);
            }
예제 #9
0
            public void DoesNotProcessDirectivesWithSpaceAfterHash()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"# valid a b c
            A";

                // When
                directiveParser.Parse(configScript);

                // Then
                Assert.AreEqual(@"# valid a b c
            A", directiveParser.Code);
                CollectionAssert.IsEmpty(directiveParser.DirectiveValues);
            }
예제 #10
0
            public void DoesNotProcessDirectivesWithSpaceAfterHash()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"# valid a b c
            A";

                // When
                directiveParser.Parse(configScript);

                // Then
                directiveParser.Code.ShouldBe(@"# valid a b c
            A", StringCompareShould.IgnoreLineEndings);
                directiveParser.DirectiveValues.ShouldBeEmpty();
            }
예제 #11
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);
            }
예제 #12
0
            public void ReturnsSameCode()
            {
                // Given
                IPreprocessor preprocessor = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string configScript = @"A
B
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                CollectionAssert.IsEmpty(directiveParser.DirectiveValues);
                Assert.AreEqual(@"A
B
C", directiveParser.Code);
            }
예제 #13
0
            public void ReturnsSameCode()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"A
B
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                CollectionAssert.IsEmpty(directiveParser.DirectiveValues);
                Assert.AreEqual(@"A
B
C", directiveParser.Code);
            }
예제 #14
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);
            }
예제 #15
0
            public void ReturnsSameCode()
            {
                // Given
                IPreprocessor   preprocessor    = new TestPreprocessor();
                DirectiveParser directiveParser = new DirectiveParser(preprocessor);
                string          configScript    = @"A
B
C";

                // When
                directiveParser.Parse(configScript);

                // Then
                directiveParser.DirectiveValues.ShouldBeEmpty();
                directiveParser.Code.ShouldBe(@"A
B
C", StringCompareShould.IgnoreLineEndings);
            }
예제 #16
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);
            }