Esempio n. 1
0
        static void Main(string[] args)
        {
            string code            = "//line comment*/ \nint x = 0;/* //line comment*/";
            string commentsRemoved = JavaCommentsRemover.RemoveComments(code);

            System.Console.WriteLine(commentsRemoved);
            int count = JavaLinesCounter.Count(code);

            System.Console.WriteLine(count);
        }
Esempio n. 2
0
    public void RemoveComments_EmptyInput_ReturnEmptyString()
    {
        // arrange

        // act
        string result = JavaCommentsRemover.RemoveComments("");

        // assert
        Assert.AreEqual("", result);
    }
Esempio n. 3
0
    public static int Count(string code)
    {
        string codeWithoutComments = JavaCommentsRemover.RemoveComments(code);

        //string codeWithoutComments = JavaNoRegexCommentsRemover.RemoveComments(code); // uncomment this line to use the other CommentsRemover
        string[] split = codeWithoutComments.Split('\n');
        int      loc   = split.Count(line => line.Trim() != "");

        return(loc);
    }
Esempio n. 4
0
    public void RemoveComments_MultiLineBlockComments_AreRemoved()
    {
        // arrange
        string input = "/*this\ncomment\nhas\nmultiple\nlines*/\nint x;";

        // act
        string result = JavaCommentsRemover.RemoveComments(input);

        // assert
        Assert.AreEqual("\n\n\n\n\nint x;", result);
    }
Esempio n. 5
0
    public void RemoveComments_CodeBetweenOneLineBlockComment_IsNotRemoved()
    {
        // arrange
        string input = "/*comment*/int x;/*block comment*/";

        // act
        string result = JavaCommentsRemover.RemoveComments(input);

        // assert
        Assert.AreEqual("int x;", result);
    }
Esempio n. 6
0
    public void RemoveComments_LineCommentWhichIsALineCommentAndTheSameIsNestedInABlockComment_IsHandledCorrectly()
    {
        // arrange
        string code = "//line comment*/\nint x = 0;/* //line comment*/";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        Assert.AreEqual("\nint x = 0;", result);
    }
Esempio n. 7
0
    public void RemoveComments_ForwardSlashAndAsteriksInALineCommnet_IsNotABlockComment()
    {
        // arrange
        string code = "//line comment/* \nint x = 0;//line comment*/";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        Assert.AreEqual("\nint x = 0;", result);
    }
Esempio n. 8
0
    public void RemoveComments_BlockCommentWithTwoForwardSlashes_IsRemoved()
    {
        // arrange
        string code = "/* block comment \n // block comment closing */";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        Assert.AreEqual("\n", result);
    }
Esempio n. 9
0
    public void RemoveComments_LineComment_IsRemoved()
    {
        // arrange
        string input = "int x;// comment";

        // act
        string result = JavaCommentsRemover.RemoveComments(input);

        // assert
        Assert.AreEqual("int x;", result);
    }
Esempio n. 10
0
    public void RemoveComments_QuotesInStrings_AreHandledCorrectly()
    {
        // arrange
        string code = "String x = \"some words \\\" more\";";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        Assert.AreEqual(code, result);
    }
Esempio n. 11
0
    public void RemoveComments_StringLookingAsBlockComments_AreNotRemoved()
    {
        // arrange
        string code = "String x = \"/*\" \n String y = \"*/\";";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        Assert.AreEqual("String x = \"/*\" \n String y = \"*/\";", result);
    }
Esempio n. 12
0
    public void RemoveComments_MultipleLineComments_AreRemoved()
    {
        // arrange
        string code = "int x; //comment \n int y; //comment \n int x; //another one";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        Assert.AreEqual("int x; \n int y; \n int x; ", result);
    }
Esempio n. 13
0
    public void RemoveComments_MultiLineBlockComment_RemovesCommentButNewLinesStay()
    {
        // arrange
        string code = "int x; /* comment \n comment */ int y;";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        Assert.AreEqual("int x; \n int y;", result);
    }
Esempio n. 14
0
    public void RemoveComments_LineCommentInString_IsNotRemoved()
    {
        // arrange
        string code = "String s = \"this is a string // still a string \";";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        string expected = "String s = \"this is a string // still a string \";";

        Assert.AreEqual(expected, result);
    }
Esempio n. 15
0
    public void RemoveComments_LineCommentAfterStringWithTwoForwadSlashes_IsRemoved()
    {
        // arrange
        string code = "String s = \"this is a string // still a string \"; // to be removed";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        string expected = "String s = \"this is a string // still a string \"; ";

        Assert.AreEqual(expected, result);
    }
Esempio n. 16
0
    public void RemoveComments_LineCommentBetweenCode_IsRemoved()
    {
        // arrange
        string code = "" +
                      " int x;     \n" +
                      " // comment \n" +
                      " int y;     \n";

        // act
        string result = JavaCommentsRemover.RemoveComments(code);

        // assert
        string expected = "" +
                          " int x;     \n" +
                          " \n" +
                          " int y;     \n";

        Assert.AreEqual(expected, result);
    }