示例#1
0
 public void LockStatementTest()
 {
     ParseUtilCSharp.ParseStatement <LockStatement>("lock (myObj) {}");
     // TODO : Extend test.
 }
示例#2
0
        void CheckIdentifier(string sourceCode, string identifier)
        {
            IdentifierExpression ident = ParseUtilCSharp.ParseExpression <IdentifierExpression>(sourceCode);

            Assert.AreEqual(identifier, ident.Identifier);
        }
示例#3
0
 public void EmptyStatementTest()
 {
     ParseUtilCSharp.ParseStatement <EmptyStatement>(";");
 }
        public void ExternDestructorDeclarationTest()
        {
            DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember <DestructorDeclaration>("extern ~MyClass();");

            Assert.AreEqual(Modifiers.Extern, dd.Modifiers);
        }
示例#5
0
        public void CheckedStatementTest()
        {
            CheckedStatement checkedStatement = ParseUtilCSharp.ParseStatement <CheckedStatement>("checked { }");

            Assert.IsFalse(checkedStatement.Body.IsNull);
        }
        public void ThrowStatementTest()
        {
            ThrowStatement throwStmt = ParseUtilCSharp.ParseStatement <ThrowStatement>("throw new Exception();");

            Assert.IsTrue(throwStmt.Expression is ObjectCreateExpression);
        }
        public void ConstructorDeclarationTest1()
        {
            ConstructorDeclaration cd = ParseUtilCSharp.ParseTypeMember <ConstructorDeclaration>("MyClass() {}");

            Assert.IsTrue(cd.Initializer.IsNull);
        }
 public void InvalidOperatorTrueDeclaration()
 {
     ParseUtilCSharp.ParseTypeMember <OperatorDeclaration>("public static implicit operator true(MyBool b) {}", expectErrors: true);
 }
示例#9
0
        public void BlockStatementTest()
        {
            BlockStatement blockStmt = ParseUtilCSharp.ParseStatement <BlockStatement>("{}");

            Assert.AreEqual(0, blockStmt.Statements.Count());
        }
示例#10
0
        public void StatementExpressionTest()
        {
            ExpressionStatement stmtExprStmt = ParseUtilCSharp.ParseStatement <ExpressionStatement>("a = my.Obj.PropCall;");

            Assert.IsTrue(stmtExprStmt.Expression is AssignmentExpression);
        }
示例#11
0
        public void StatementExpressionTest1()
        {
            ExpressionStatement stmtExprStmt = ParseUtilCSharp.ParseStatement <ExpressionStatement>("yield.yield();");

            Assert.IsTrue(stmtExprStmt.Expression is InvocationExpression);
        }
示例#12
0
        public void UnboundTypeOfExpressionTest()
        {
            TypeOfExpression toe = ParseUtilCSharp.ParseExpression <TypeOfExpression>("typeof(MyType<,>)");

            throw new NotImplementedException("How do we represent unbound types in the AST?");
        }
        public void DoCloneDetection(string codefile, MethodsOnASingleClassCloneFinder cloneFinder)
        {
            string codeText = File.ReadAllText(codefile);

            TestLog.EmbedPlainText("The Code", codeText);

//            System.Diagnostics.Debugger.Break();

            IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(codeText));

            parser.Parse();

            if (parser.Errors.Count > 0)
            {
                throw new ApplicationException(string.Format("Expected no errors in the input code. Code was: {0} ErrorOutput: {1}", codeText,
                                                             parser.Errors.ErrorOutput));
            }

            var comments = parser.Lexer.SpecialTracker.RetrieveSpecials().OfType <Comment>();

            if (comments.Any(x => x.CommentText.TrimStart().StartsWith("Ignore")))
            {
                throw new ApplicationException("Ignored.");
            }

            var begin_comment = comments.FirstOrDefault(x => x.CommentText.Contains("BEGIN"));
            var end_comment   = comments.FirstOrDefault(x => x.CommentText.Contains("END"));

            if (begin_comment == null)
            {
                throw new ApplicationException("There was no comment containing the BEGIN keyword.");
            }
            if (end_comment == null)
            {
                throw new ApplicationException("There was no comment containing the END keyword.");
            }

            CloneDesc largest = null;

            cloneFinder.OnExtractedCandidate += (finder, args) =>
            {
                if (largest == null)
                {
                    largest = args.Candidate;
                }
                else if (args.Candidate.ReplacementInvocationInfo.ReplacementSectionStartLine >= begin_comment.StartPosition.Line &&
                         args.Candidate.ReplacementInvocationInfo.ReplacementSectionEndLine <= end_comment.EndPosition.Line &&
                         args.Candidate.PermutatedMethod.CountNodes() > largest.PermutatedMethod.CountNodes())
                {
                    largest = args.Candidate;
                }
            };


            var replacements = cloneFinder.GetCloneReplacements(parser.CompilationUnit);

            int clone_count = replacements.Clones.Count;

            TestLog.EmbedPlainText(clone_count + " clones found.");
            for (int i = 0; i < replacements.Clones.Count; i++)
            {
                TestLog.EmbedPlainText("   ***** Clone #" + i + " *****", replacements.Clones[i].ToString());
            }

            TestLog.EmbedPlainText("The largest permutation found within the markers was:", largest.PermutatedMethod.Print());

            var quickFixInfos = replacements.Clones.Where(Predicate(begin_comment, end_comment));

            Assert.IsTrue(quickFixInfos.Count() > 0, "None of the clones found (there were " + clone_count + ") fell inbetween the BEGIN/END markers.");

            var expected_call_snippet = begin_comment.CommentText.Substring(begin_comment.CommentText.IndexOf("BEGIN") + 5).Trim();

            if (!string.IsNullOrEmpty(expected_call_snippet))
            {
                var expected_call = ParseUtilCSharp.ParseStatement <Statement>(expected_call_snippet);
                var actual_cal    = ParseUtilCSharp.ParseStatement <Statement>(quickFixInfos.First().TextForACallToJanga);
                Assert.IsTrue(expected_call.MatchesPrint(actual_cal), "The expected call did not match the actual call.  \n\tExpected Call: " + expected_call.Print() + "\n\t" + "Actual Call: " + actual_cal.Print());
            }
        }
 public void TestMethod()
 {
     ParseUtilCSharp.ParseExpression <ThisReferenceExpression>("this");
 }
 AnonymousMethodExpression Parse(string expression)
 {
     return(ParseUtilCSharp.ParseExpression <AnonymousMethodExpression>(expression));
 }
示例#16
0
        public void NullableVariableDeclarationStatementTest1()
        {
            VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement <VariableDeclarationStatement>("int? a;");

            Assert.IsTrue(new VariableDeclarationStatement(new PrimitiveType("int").MakeNullableType(), "a").IsMatch(lvd));
        }
        public void EmptyThrowStatementTest()
        {
            ThrowStatement throwStmt = ParseUtilCSharp.ParseStatement <ThrowStatement>("throw;");

            Assert.IsTrue(throwStmt.Expression.IsNull);
        }
示例#18
0
        public void NestedArray()
        {
            VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement <VariableDeclarationStatement>("DateTime[,][] a;");

            Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("DateTime").MakeArrayType(1).MakeArrayType(2), "a").IsMatch(lvd));
        }
 public void Bool_TrueString()
 {
     ParseUtilCSharp.AssertExpression("bool.TrueString", new PrimitiveType("bool").Member("TrueString"));
 }
示例#20
0
        public void NestedPointers()
        {
            VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement <VariableDeclarationStatement>("DateTime*** a;");

            Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("DateTime").MakePointerType().MakePointerType().MakePointerType(), "a").IsMatch(lvd));
        }
 public void DestructorDeclarationTest()
 {
     ParseUtilCSharp.ParseTypeMember <DestructorDeclaration>("~MyClass() {}");
 }
示例#22
0
        public void ArrayOfNullables()
        {
            VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement <VariableDeclarationStatement>("DateTime?[] a;");

            Assert.IsTrue(new VariableDeclarationStatement(new SimpleType("DateTime").MakeNullableType().MakeArrayType(), "a").IsMatch(lvd));
        }
        public void UnsafeDestructorDeclarationTest()
        {
            DestructorDeclaration dd = ParseUtilCSharp.ParseTypeMember <DestructorDeclaration>("unsafe ~MyClass() {}");

            Assert.AreEqual(Modifiers.Unsafe, dd.Modifiers);
        }
示例#24
0
        public void VoidPointerVariableDeclarationTest()
        {
            VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement <VariableDeclarationStatement>("void *a;");

            Assert.IsTrue(new VariableDeclarationStatement(new PrimitiveType("void").MakePointerType(), "a").IsMatch(lvd));
        }
示例#25
0
        public void UncheckedStatementTest()
        {
            UncheckedStatement uncheckedStatement = ParseUtilCSharp.ParseStatement <UncheckedStatement>("unchecked { }");

            Assert.IsFalse(uncheckedStatement.Body.IsNull);
        }
示例#26
0
 public void IntMinValueTest()
 {
     ParseUtilCSharp.AssertExpression(
         "-2147483648",
         new UnaryOperatorExpression(UnaryOperatorType.Minus, new PrimitiveExpression(2147483648)));
 }
示例#27
0
        public void SizeOfExpressionTest()
        {
            SizeOfExpression soe = ParseUtilCSharp.ParseExpression <SizeOfExpression>("sizeof(MyType)");

            Assert.AreEqual("MyType", ((SimpleType)soe.Type).Identifier);
        }
示例#28
0
 public void LongMinValueTest()
 {
     ParseUtilCSharp.AssertExpression(
         "-9223372036854775808",
         new UnaryOperatorExpression(UnaryOperatorType.Minus, new PrimitiveExpression(9223372036854775808)));
 }
示例#29
0
		public void VoidTypeOfExpressionTest()
		{
			TypeOfExpression toe = ParseUtilCSharp.ParseExpression<TypeOfExpression>("typeof(void)");
			Assert.AreEqual("void", ((PrimitiveType)toe.Type).Keyword);
		}
示例#30
0
        public void UncheckedExpressionTest()
        {
            UncheckedExpression ce = ParseUtilCSharp.ParseExpression <UncheckedExpression>("unchecked(a)");

            Assert.IsTrue(ce.Expression is IdentifierExpression);
        }