public void SingleLineComment_ASingleDashShouldBePreserved()
        {
            string sql = "-";   // this test really has to do with our particular state machine implementation

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("-");
        }
        public void SingleLine_SingleDashShouldNotConfuse()
        {
            string sql = "before\n-not a comment";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be(sql);        // should not be changed!
        }
        public void SingleLineComment_ShouldPreserveBeforeAndAfter()
        {
            string sql = "before\n--comment\n after\n";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("before\n\n after\n");
        }
        public void SingleLineComment_ShouldEndAtEOF()
        {
            string sql = "before\n--comment";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("before\n");
        }
        public void SingleLineComment_ShouldBeRemovedLeavingANewLine()
        {
            string sql = "--comment\n";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("\n");
        }
        public void SingleLineComment_ShouldEndAtFirstNewLine()
        {
            string sql = "--comment\n\n";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("\n\n");
        }
        public void MultiLine_ExtraStarsShouldBeIgnored()
        {
            string sql = "/***/";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("");
        }
        public void MultiLine_NestedSingleLineCommentsShouldBeIgnored()
        {
            string sql = "a/*--no\n --problem\n*/b";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("ab");
        }
        public void MultiLine_BeforeAndAfterShouldBePreserved()
        {
            string sql = "before/*comment*/after";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("beforeafter");
        }
        public void MultiLine_ShouldTerminateAtFirstEnd()
        {
            string sql = "/*abc*/def*/";        // this is an SQL error, but fine as far as the comment stripper is concerned

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("def*/");
        }
        public void MultiLine_ShouldBeRemovedAcrossNewLines()
        {
            string sql = "/*line1\nline2*/";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("");
        }
        public void MultiLine_ShouldBeRemoved()
        {
            string sql = "/*comment*/";

            string result = CommentStripper.ProcessSql(sql);

            result.Should().Be("");
        }
        public void SingleLine_NestedSlashStarsShouldBeIgnored()
        {
            string sql = "a--/*...*/ */ /* /* \n b";

            string result = CommentStripper.ProcessSql(sql);

            string expected = "a\n b";

            result.Should().Be(expected);        // should not be changed!
        }
        public void SingleLine_MultipleCommentsAndSingleDashes()
        {
            string sql = "before\n--comment\n a - b; c - d; --comment\n after";

            string result = CommentStripper.ProcessSql(sql);

            string expected = "before\n\n a - b; c - d; \n after";

            result.Should().Be(expected);        // should not be changed!
        }
Beispiel #15
0
    static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            WriteLine("~~~");
            WriteLine($"help: {_expectedArgs}.");
            WriteLine("~~~");
            return;
        }

        if (args.Length > 2)
        {
            throw new ArgumentException($@"error: {_expectedArgs} But instead got the {args.Length} arguments");
        }

        var inputFilePath = args[0];

        if (!File.Exists(inputFilePath))
        {
            throw new ArgumentException($"error: {_expectedArgs} But instead got nonexisting input file '{inputFilePath}'");
        }

        string[] removeLineStartingWith = null;
        if (args.Length == 2)
        {
            var configFilePath = args[1];
            if (!File.Exists(configFilePath))
            {
                throw new ArgumentException($"error: {_expectedArgs} But got the nonexistent config file '{configFilePath}'");
            }
            removeLineStartingWith = File.ReadAllLines(configFilePath);
        }
        else if (File.Exists(_defaultConfigFileName))
        {
            removeLineStartingWith = File.ReadAllLines(_defaultConfigFileName);
        }

        var lines = File.ReadAllLines(inputFilePath);

        var mdStringBuilder = CommentStripper.StripMdComments(lines, removeLineStartingWith);

        var mdFilePath = Path.ChangeExtension(inputFilePath, _outputMarkdownFileExt);

        File.WriteAllText(mdFilePath, mdStringBuilder.ToString());
    }