Exemplo n.º 1
0
    public void TestStripComments()
    {
        // Use a delegate just so things fit on one line.
        var strip = new StripComments(StoredProcedure.StripComments);

        WVPASSEQ(strip("Hi"), "Hi");
        WVPASSEQ(strip("--foo"), "");
        WVPASSEQ(strip("--foo\nHi"), "\nHi");
        WVPASSEQ(strip("Hi\n--foo"), "Hi\n");
        WVPASSEQ(strip("Hi\n--foo\nThere"), "Hi\n\nThere");
        WVPASSEQ(strip("--foo"), "");
        WVPASSEQ(strip("/*foo*/"), "");
        WVPASSEQ(strip("/*foo\nbar*/"), "");
        WVPASSEQ(strip("Hi/*foo*/"), "Hi");
        WVPASSEQ(strip("Hi/*foo\nbar*/There"), "HiThere");
        WVPASSEQ(strip("Hi\n/* foo\nbar */\nThere"), "Hi\n\nThere");
        WVPASSEQ(strip("Hi--asdf/*\nThere/*foo*/"), "Hi\nThere");
        // Note: this is a bit fishy, but it's how the Perl version worked.
        WVPASSEQ(strip("Hi/*foo\n--asdf*/There"), "Hi/*foo\n");
    }
Exemplo n.º 2
0
        public void StripCppComments()
        {
            const string str_in =
                "123// comment         \n" +
                "456/* block */789     \n" +
                "// many               \n" +
                "// lines              \n" +
                "// \"string\"         \n" +
                "/* \"string\" */      \n" +
                "\"string \\\" /*a*/ //b\"  \n" +
                "/not a comment\n" +
                "/*\n" +
                "  more lines\n" +
                "*/\n" +
                "/*back to*//*back*/ comment\n";
            const string str_out =
                "123\n" +
                "456789     \n" +
                "\n" +
                "\n" +
                "\n" +
                "      \n" +
                "\"string \\\" /*a*/ //b\"  \n" +
                "/not a comment\n" +
                "\n" +
                " comment\n";

            var src   = new StringSrc(str_in);
            var strip = new StripComments(src);

            for (int i = 0; i != str_out.Length; ++i, strip.Next())
            {
                if (str_out[i] == strip.Peek)
                {
                    continue;
                }
                Assert.Equal(str_out[i], strip.Peek);
            }
            Assert.Equal('\0', strip.Peek);
        }
Exemplo n.º 3
0
        public void StripAsmComments()
        {
            const string str_in =
                "; asm comments start with a ; character\r\n" +
                "mov 43 2\r\n" +
                "ldr $a 2 ; imaginary asm";
            const string str_out =
                "\r\n" +
                "mov 43 2\r\n" +
                "ldr $a 2 ";

            var src   = new StringSrc(str_in);
            var strip = new StripComments(src, comment_patterns: new InComment.Patterns(";", "\r\n", "", ""));

            for (int i = 0; i != str_out.Length; ++i, strip.Next())
            {
                if (str_out[i] == strip.Peek)
                {
                    continue;
                }
                Assert.Equal(str_out[i], strip.Peek);
            }
            Assert.Equal('\0', strip.Peek);
        }