Ejemplo n.º 1
0
        public void Process_Include_BatchSeparatorAfterInclusionBoundary(string eol, string eof)
        {
            using var file = new TemporaryFile();

            file.Write(
                Lines(eol, eof,
                      "GO",
                      "included"
                      )
                );

            var preprocessor = new SqlCmdPreprocessor {
            };

            var batches = preprocessor.Process(
                Lines(eol, eof,
                      $":r {file.Path}",
                      "GO",
                      "main"
                      )
                );

            batches.Should().Equal(
                Batch("included", eof),
                Batch("main", eof)
                );
        }
Ejemplo n.º 2
0
        public void Process_Include_Nested(string eol, string eof)
        {
            using var file0 = new TemporaryFile();
            using var file1 = new TemporaryFile();

            file0.Write(Lines(eol, eof,
                              "b",
                              $":r {file1.Path}",
                              "c"
                              ));

            file1.Write(Lines(eol, eof,
                              "included"
                              ));

            var preprocessor = new SqlCmdPreprocessor {
            };

            var batches = preprocessor.Process(
                Lines(eol, eof, "a", $":r {file0.Path}", "d")
                );

            batches.Should().Equal(
                Batch(
                    "a", eol,
                    "b", eol,
                    "included", eof,
                    "c", eof,
                    "d", eof
                    )
                );
        }
Ejemplo n.º 3
0
        public void Process_SetVariable_Unquoted(string eol, string eof)
        {
            // NOTE: This test contains German, Japanese, and Russian characters.

            var preprocessor = new SqlCmdPreprocessor
            {
                Variables = { ["f0ö_Бар-baß"] = "original value" }
            };

            var batches = preprocessor.Process(
                Lines(eol, eof,
                      @"a",
                      @":setvar f0ö_Бар-baß qux~`!@#$%^&*()-_=+[{]}\|;:',<.>/?ほげ",
                      @"b $(F0ö_Бар-baß) c"
                      )
                );

            batches.Should().Equal(
                Batch(
                    @"a", eol,
                    @"b qux~`!@#$%^&*()-_=+[{]}\|;:',<.>/?ほげ c", eof
                    )
                );

            preprocessor.Variables["f0ö_Бар-baß"].Should().Be(
                @"qux~`!@#$%^&*()-_=+[{]}\|;:',<.>/?ほげ"
                );
        }
Ejemplo n.º 4
0
        public void Process_EmptyText()
        {
            var preprocessor = new SqlCmdPreprocessor();

            var batches = preprocessor.Process("");

            batches.Should().BeEmpty();
        }
Ejemplo n.º 5
0
        public void Process_BlockComment_Unterminated(string eol, string eof)
        {
            var preprocessor = new SqlCmdPreprocessor();

            var text = Lines(eol, eof, "a /* foo");

            var batches = preprocessor.Process(text);

            batches.Should().Equal(text);
        }
Ejemplo n.º 6
0
        public void Process_LineComment(string eol, string eof)
        {
            var preprocessor = new SqlCmdPreprocessor();

            var text = Lines(eol, eof, "a", "b -- foo", "c");

            var batches = preprocessor.Process(text);

            batches.Should().Equal(text);
        }
Ejemplo n.º 7
0
        public void Process_TokenlessText()
        {
            var preprocessor = new SqlCmdPreprocessor();

            var text = "no tokens here";

            var batches = preprocessor.Process(text);

            batches.Should().Equal(text);
        }
Ejemplo n.º 8
0
        public void Process_BracketQuotedIdentifier_Unterminated(string eol, string eof)
        {
            var preprocessor = new SqlCmdPreprocessor();

            var text = Lines(eol, eof, "a [foo]]bar");

            var batches = preprocessor.Process(text);

            batches.Should().Equal(text);
        }
Ejemplo n.º 9
0
        public void Process_SingleQuotedString_Unterminated(string eol, string eof)
        {
            var preprocessor = new SqlCmdPreprocessor();

            var text = Lines(eol, eof, "a 'foo''bar");

            var batches = preprocessor.Process(text);

            batches.Should().Equal(text);
        }
Ejemplo n.º 10
0
        public void Process_BatchSeparator_AllEmptyBatches(string eol, string eof)
        {
            var preprocessor = new SqlCmdPreprocessor();

            foreach (var separator in BatchSeparators)
            {
                var text = Lines(eol, eof, separator, separator);

                var batches = preprocessor.Process(text);

                batches.Should().BeEmpty();
            }
        }
Ejemplo n.º 11
0
        public void Process_BatchSeparator_EmptyBatchAtEnd(string eol, string eof)
        {
            var preprocessor = new SqlCmdPreprocessor();

            foreach (var separator in BatchSeparators)
            {
                var text = Lines(eol, eof, "a", separator);

                var batches = preprocessor.Process(text);

                batches.Should().Equal("a" + eol);
            }
        }
Ejemplo n.º 12
0
        public void Process_VariableReplacement_InBracketQuotedIdentifier(string eol, string eof)
        {
            var preprocessor = new SqlCmdPreprocessor
            {
                Variables = { ["foo"] = "bar" }
            };

            var batches = preprocessor.Process(
                Lines(eol, eof, "a [b ]] $(fOo) c] d")
                );

            batches.Should().Equal(
                Lines(eol, eof, "a [b ]] bar c] d")
                );
        }
Ejemplo n.º 13
0
        public void Process_VariableReplacement_InSingleQuotedString(string eol, string eof)
        {
            var preprocessor = new SqlCmdPreprocessor
            {
                Variables = { ["foo"] = "bar" }
            };

            var batches = preprocessor.Process(
                Lines(eol, eof, "a 'b '' $(fOO) c' d")
                );

            batches.Should().Equal(
                Lines(eol, eof, "a 'b '' bar c' d")
                );
        }
Ejemplo n.º 14
0
        public void Process_VariableReplacement_Normal(string eol, string eof)
        {
            var preprocessor = new SqlCmdPreprocessor
            {
                Variables = { ["foo"] = "bar" }
            };

            var batches = preprocessor.Process(
                Lines(eol, eof, "a $(FOO) b")
                );

            batches.Should().Equal(
                Lines(eol, eof, "a bar b")
                );
        }
Ejemplo n.º 15
0
        public void Process_Include_CrossInclusionBatches(string eol, string eof)
        {
            using var file0 = new TemporaryFile();
            using var file1 = new TemporaryFile();

            file0.Write(Lines(eol, eof,
                              "file0.a",
                              "GO",
                              "file0.b"
                              ));

            file1.Write(Lines(eol, eof,
                              "file1.a",
                              "GO",
                              "file1.b"
                              ));

            var preprocessor = new SqlCmdPreprocessor {
            };

            var batches = preprocessor.Process(Lines(eol, eof,
                                                     "beg",
                                                     $":r {file0.Path}",
                                                     "mid",
                                                     $":r {file1.Path}",
                                                     "end"
                                                     ));

            batches.Should().Equal(
                // Batch begins in top level and ends in included
                Batch(
                    "beg", eol,
                    "file0.a", eol
                    ),
                // Batch begins in included, continues to top level, and ends in another included
                Batch(
                    "file0.b", eof,
                    "mid", eol,
                    "file1.a", eol
                    ),
                // Batch begins in included and ends in top level
                Batch(
                    "file1.b", eof,
                    "end", eof
                    )
                );
        }
Ejemplo n.º 16
0
        public void Process_Include_BatchInsideInclude(string eol, string eof)
        {
            using var file = new TemporaryFile();

            file.Write(Lines(eol, eof,
                             "file.a",
                             "GO",
                             "file.b",
                             "GO",
                             "file.c"
                             ));

            var preprocessor = new SqlCmdPreprocessor {
            };

            var batches = preprocessor.Process(Lines(eol, eof,
                                                     "beg",
                                                     $":r {file.Path}",
                                                     "end"
                                                     ));

            batches.Should().Equal(
                // Batch begins in top level and ends in included
                Batch(
                    "beg", eol,
                    "file.a", eol
                    ),
                // Batch begins in included and ends in same included
                Batch(
                    "file.b", eol
                    ),
                // Batch begins in included and ends in top level
                Batch(
                    "file.c", eof,
                    "end", eof
                    )
                );
        }