示例#1
0
        public void TestReverse_Equality()
        {
            var node1 = SyntaxFactory.ReturnStatement();

            EqualityTesting.AssertEqual(
                default(SyntaxTokenList).Reverse(),
                default(SyntaxTokenList).Reverse()
                );

            EqualityTesting.AssertEqual(
                new SyntaxTokenList(node1, node1.ReturnKeyword.Node, 0, 0).Reverse(),
                new SyntaxTokenList(node1, node1.ReturnKeyword.Node, 0, 0).Reverse()
                );

            // index is considered
            EqualityTesting.AssertNotEqual(
                new SyntaxTokenList(node1, node1.ReturnKeyword.Node, 0, 1).Reverse(),
                new SyntaxTokenList(node1, node1.ReturnKeyword.Node, 0, 0).Reverse()
                );

            // position not considered:
            EqualityTesting.AssertEqual(
                new SyntaxTokenList(node1, node1.ReturnKeyword.Node, 1, 0).Reverse(),
                new SyntaxTokenList(node1, node1.ReturnKeyword.Node, 0, 0).Reverse()
                );
        }
示例#2
0
        public void Equality()
        {
            var c           = CreateCompilation("");
            var obj         = c.GetSpecialType(SpecialType.System_Object);
            var int32       = c.GetSpecialType(SpecialType.System_Int32);
            var notNullable = new NullabilityInfo(CodeAnalysis.NullableAnnotation.NotAnnotated, CodeAnalysis.NullableFlowState.NotNull);
            var nullable    = new NullabilityInfo(CodeAnalysis.NullableAnnotation.Annotated, CodeAnalysis.NullableFlowState.MaybeNull);

            EqualityTesting.AssertEqual(default(TypeInfo), default(TypeInfo));

            EqualityTesting.AssertEqual(new TypeInfo(obj, int32, nullable, notNullable),
                                        new TypeInfo(obj, int32, nullable, notNullable));

#pragma warning disable IDE0055 // Fix formatting: spacing is intentional to allow for visual field comparison
            EqualityTesting.AssertNotEqual(new TypeInfo(obj, obj, nullable, nullable),
                                           new TypeInfo(obj, int32, nullable, nullable));

            EqualityTesting.AssertNotEqual(new TypeInfo(int32, obj, nullable, nullable),
                                           new TypeInfo(obj, obj, nullable, nullable));

            EqualityTesting.AssertNotEqual(new TypeInfo(obj, int32, nullable, nullable),
                                           new TypeInfo(obj, int32, notNullable, nullable));

            EqualityTesting.AssertNotEqual(new TypeInfo(obj, int32, nullable, nullable),
                                           new TypeInfo(obj, int32, nullable, notNullable));
#pragma warning restore IDE0055 // Fix formatting

            EqualityTesting.AssertEqual(new TypeInfo(int32, int32, default, default),
示例#3
0
        public void Equality()
        {
            EqualityTesting.AssertEqual(default(TypedConstant), default(TypedConstant));

            EqualityTesting.AssertEqual(
                new TypedConstant(_intType, TypedConstantKind.Primitive, 1),
                new TypedConstant(_intType, TypedConstantKind.Primitive, 1));

            var s1 = "goo";
            var s2 = String.Format("{0}{1}{1}", "g", "o");

            EqualityTesting.AssertEqual(
                new TypedConstant(_stringType, TypedConstantKind.Primitive, s1),
                new TypedConstant(_stringType, TypedConstantKind.Primitive, s2));

            EqualityTesting.AssertEqual(
                new TypedConstant(_stringType, TypedConstantKind.Primitive, null),
                new TypedConstant(_stringType, TypedConstantKind.Primitive, null));

            EqualityTesting.AssertEqual(
                new TypedConstant(_enumString1, TypedConstantKind.Primitive, null),
                new TypedConstant(_enumString2, TypedConstantKind.Primitive, null));

            EqualityTesting.AssertNotEqual(
                new TypedConstant(_stringType, TypedConstantKind.Primitive, null),
                new TypedConstant(_stringType, TypedConstantKind.Error, null));

            EqualityTesting.AssertNotEqual(
                new TypedConstant(_stringType, TypedConstantKind.Primitive, null),
                new TypedConstant(_enumString1, TypedConstantKind.Primitive, null));
        }
示例#4
0
        public void Equality()
        {
            var c           = CreateCompilation("");
            var obj         = c.GetSpecialType(SpecialType.System_Object).GetPublicSymbol();
            var int32       = c.GetSpecialType(SpecialType.System_Int32).GetPublicSymbol();
            var notNullable = new NullabilityInfo(CodeAnalysis.NullableAnnotation.NotAnnotated, CodeAnalysis.NullableFlowState.NotNull);
            var nullable    = new NullabilityInfo(CodeAnalysis.NullableAnnotation.Annotated, CodeAnalysis.NullableFlowState.MaybeNull);

            EqualityTesting.AssertEqual(default(TypeInfo), default(TypeInfo));

            EqualityTesting.AssertEqual(new TypeInfo(obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), int32, nullable, notNullable),
                                        new TypeInfo(obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), int32, nullable, notNullable));

            EqualityTesting.AssertNotEqual(new TypeInfo(obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), nullable, nullable),
                                           new TypeInfo(obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), int32.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), nullable, nullable));

            EqualityTesting.AssertNotEqual(new TypeInfo(int32.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), nullable, nullable),
                                           new TypeInfo(obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), nullable, nullable));

            EqualityTesting.AssertNotEqual(new TypeInfo(obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), int32.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), nullable, nullable),
                                           new TypeInfo(obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.NotAnnotated), int32.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), notNullable, nullable));

            EqualityTesting.AssertNotEqual(new TypeInfo(obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), int32.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), nullable, nullable),
                                           new TypeInfo(obj.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.Annotated), int32, nullable, notNullable));

            EqualityTesting.AssertEqual(new TypeInfo(int32.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.None), int32.WithNullableAnnotation(CodeAnalysis.NullableAnnotation.None), default, default),
示例#5
0
        public void Equality()
        {
            var node1 = SyntaxFactory.Parameter(SyntaxFactory.Identifier("a"));
            var node2 = SyntaxFactory.Parameter(SyntaxFactory.Identifier("b"));

            EqualityTesting.AssertEqual(
                default(SeparatedSyntaxList <CSharpSyntaxNode>),
                default(SeparatedSyntaxList <CSharpSyntaxNode>)
                );

            EqualityTesting.AssertEqual(
                new SeparatedSyntaxList <CSharpSyntaxNode>(new SyntaxNodeOrTokenList(node1, 0)),
                new SeparatedSyntaxList <CSharpSyntaxNode>(new SyntaxNodeOrTokenList(node1, 0))
                );

            EqualityTesting.AssertEqual(
                new SeparatedSyntaxList <CSharpSyntaxNode>(new SyntaxNodeOrTokenList(node1, 0)),
                new SeparatedSyntaxList <CSharpSyntaxNode>(new SyntaxNodeOrTokenList(node1, 1))
                );

            EqualityTesting.AssertNotEqual(
                new SeparatedSyntaxList <CSharpSyntaxNode>(new SyntaxNodeOrTokenList(node1, 0)),
                new SeparatedSyntaxList <CSharpSyntaxNode>(new SyntaxNodeOrTokenList(node2, 0))
                );
        }
示例#6
0
        public void Reverse_Equality()
        {
            var node1 = SyntaxFactory.Token(SyntaxKind.AbstractKeyword);
            var node2 = SyntaxFactory.Token(SyntaxKind.VirtualKeyword);

            EqualityTesting.AssertEqual(
                default(SyntaxTriviaList.Reversed),
                default(SyntaxTriviaList.Reversed)
                );
            EqualityTesting.AssertEqual(
                new SyntaxTriviaList(node1, node1.Node, 0, 0).Reverse(),
                new SyntaxTriviaList(node1, node1.Node, 0, 0).Reverse()
                );
            EqualityTesting.AssertNotEqual(
                new SyntaxTriviaList(node1, node1.Node, 0, 1).Reverse(),
                new SyntaxTriviaList(node1, node1.Node, 0, 0).Reverse()
                );
            EqualityTesting.AssertNotEqual(
                new SyntaxTriviaList(node1, node2.Node, 0, 0).Reverse(),
                new SyntaxTriviaList(node1, node1.Node, 0, 0).Reverse()
                );
            EqualityTesting.AssertNotEqual(
                new SyntaxTriviaList(node2, node1.Node, 0, 0).Reverse(),
                new SyntaxTriviaList(node1, node1.Node, 0, 0).Reverse()
                );

            // position not considered:
            EqualityTesting.AssertEqual(
                new SyntaxTriviaList(node1, node1.Node, 1, 0).Reverse(),
                new SyntaxTriviaList(node1, node1.Node, 0, 0).Reverse()
                );
        }
        public void Reverse_Equality()
        {
            var node1 = SyntaxFactory.ReturnStatement();
            var node2 = SyntaxFactory.ReturnStatement();

            EqualityTesting.AssertEqual(default(ChildSyntaxList.Reversed), default(ChildSyntaxList.Reversed));
            EqualityTesting.AssertEqual(new ChildSyntaxList(node1).Reverse(), new ChildSyntaxList(node1).Reverse());
        }
示例#8
0
        public void Equality()
        {
            var node1 = SyntaxFactory.ReturnStatement();
            var node2 = SyntaxFactory.ReturnStatement();

            EqualityTesting.AssertEqual(default(SyntaxList <CSharpSyntaxNode>), default(SyntaxList <CSharpSyntaxNode>));
            EqualityTesting.AssertEqual(new SyntaxList <CSharpSyntaxNode>(node1), new SyntaxList <CSharpSyntaxNode>(node1));

            EqualityTesting.AssertNotEqual(new SyntaxList <CSharpSyntaxNode>(node1), new SyntaxList <CSharpSyntaxNode>(node2));
        }
示例#9
0
        public void Equality()
        {
            var c1 = CreateCompilationWithMscorlib("");
            var c2 = CreateCompilationWithMscorlib("");
            var a1 = c1.Assembly;
            var a2 = c2.Assembly;

            EqualityTesting.AssertEqual(default(NamespaceExtent), default(NamespaceExtent));
            EqualityTesting.AssertNotEqual(default(NamespaceExtent), new NamespaceExtent(c2));
            EqualityTesting.AssertNotEqual(new NamespaceExtent(c1), default(NamespaceExtent));

            EqualityTesting.AssertEqual(new NamespaceExtent(c1), new NamespaceExtent(c1));
            EqualityTesting.AssertNotEqual(new NamespaceExtent(c1), new NamespaceExtent(c2));
            EqualityTesting.AssertEqual(new NamespaceExtent(a1), new NamespaceExtent(a1));
            EqualityTesting.AssertNotEqual(new NamespaceExtent(a1), new NamespaceExtent(a2));
        }
示例#10
0
        public void Equality()
        {
            var c     = CreateStandardCompilation("");
            var obj   = c.GetSpecialType(SpecialType.System_Object);
            var int32 = c.GetSpecialType(SpecialType.System_Int32);

            EqualityTesting.AssertEqual(default(TypeInfo), default(TypeInfo));
            EqualityTesting.AssertEqual(new TypeInfo(obj, int32), new TypeInfo(obj, int32));
            EqualityTesting.AssertNotEqual(new TypeInfo(obj, obj), new TypeInfo(obj, int32));
            EqualityTesting.AssertNotEqual(new TypeInfo(int32, obj), new TypeInfo(obj, obj));
            EqualityTesting.AssertEqual(new TypeInfo(int32, int32), new TypeInfo(int32, int32));

            var intEnum1 = c.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T).Construct(int32);
            var intEnum2 = c.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T).Construct(int32);

            EqualityTesting.AssertEqual(new TypeInfo(intEnum1, int32), new TypeInfo(intEnum2, int32));
        }
示例#11
0
        public void Equality()
        {
            var c     = (Compilation)CreateCompilation(@"
class E1
{
    public E GetEnumerator() { return null; }
    public bool MoveNext() { return false; }
    public object Current { get; }
    public void Dispose() { }
}

class E2
{
    public E GetEnumerator() { return null; }
    public bool MoveNext() { return false; }
    public object Current { get; }
    public void Dispose() { }
}
");
            var e1    = (ITypeSymbol)c.GlobalNamespace.GetMembers("E1").Single();
            var ge1   = (IMethodSymbol)e1.GetMembers("GetEnumerator").Single();
            var mn1   = (IMethodSymbol)e1.GetMembers("MoveNext").Single();
            var cur1  = (IPropertySymbol)e1.GetMembers("Current").Single();
            var disp1 = (IMethodSymbol)e1.GetMembers("Dispose").Single();
            var conv1 = Conversion.Identity;

            var e2    = (ITypeSymbol)c.GlobalNamespace.GetMembers("E2").Single();
            var ge2   = (IMethodSymbol)e2.GetMembers("GetEnumerator").Single();
            var mn2   = (IMethodSymbol)e2.GetMembers("MoveNext").Single();
            var cur2  = (IPropertySymbol)e2.GetMembers("Current").Single();
            var disp2 = (IMethodSymbol)e2.GetMembers("Dispose").Single();
            var conv2 = Conversion.NoConversion;

            EqualityTesting.AssertEqual(default(ForEachStatementInfo), default(ForEachStatementInfo));
            EqualityTesting.AssertEqual(new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv1), new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv1));
            EqualityTesting.AssertNotEqual(new ForEachStatementInfo(isAsync: true, ge2, mn1, cur1, disp1, e1, conv1, conv1), new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv1));
            EqualityTesting.AssertNotEqual(new ForEachStatementInfo(isAsync: true, ge1, mn2, cur1, disp1, e1, conv1, conv1), new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv1));
            EqualityTesting.AssertNotEqual(new ForEachStatementInfo(isAsync: true, ge1, mn1, cur2, disp1, e1, conv1, conv1), new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv1));
            EqualityTesting.AssertNotEqual(new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp2, e1, conv1, conv1), new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv1));
            EqualityTesting.AssertNotEqual(new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv2, conv1), new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv1));
            EqualityTesting.AssertNotEqual(new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv2), new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv1));
            EqualityTesting.AssertNotEqual(new ForEachStatementInfo(isAsync: true, ge1, mn1, cur1, disp1, e1, conv1, conv1), new ForEachStatementInfo(isAsync: false, ge1, mn1, cur1, disp1, e1, conv1, conv1));
        }
示例#12
0
        public void Equality()
        {
            var c     = CreateStandardCompilation("");
            var obj   = c.GetSpecialType(SpecialType.System_Object);
            var int32 = c.GetSpecialType(SpecialType.System_Int32);

            EqualityTesting.AssertEqual(default(QueryClauseInfo), default(QueryClauseInfo));

            EqualityTesting.AssertEqual(
                new QueryClauseInfo(
                    new SymbolInfo(obj, ImmutableArray.Create <ISymbol>(obj, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(obj, ImmutableArray.Create <ISymbol>(obj, int32), CandidateReason.Inaccessible)),
                new QueryClauseInfo(
                    new SymbolInfo(obj, ImmutableArray.Create <ISymbol>(obj, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(obj, ImmutableArray.Create <ISymbol>(obj, int32), CandidateReason.Inaccessible)));

            EqualityTesting.AssertNotEqual(
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)),
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(obj, int32), CandidateReason.Inaccessible)));

            EqualityTesting.AssertNotEqual(
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(obj, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)),
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)));

            EqualityTesting.AssertNotEqual(
                new QueryClauseInfo(
                    new SymbolInfo(obj, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)),
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)));

            EqualityTesting.AssertNotEqual(
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(obj, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)),
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)));

            EqualityTesting.AssertNotEqual(
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, obj), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)),
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)));

            EqualityTesting.AssertNotEqual(
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(obj, int32), CandidateReason.Inaccessible)),
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)));

            EqualityTesting.AssertNotEqual(
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, obj), CandidateReason.Inaccessible)),
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)));

            EqualityTesting.AssertNotEqual(
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Ambiguous),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)),
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)));

            EqualityTesting.AssertNotEqual(
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Ambiguous)),
                new QueryClauseInfo(
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible),
                    new SymbolInfo(int32, ImmutableArray.Create <ISymbol>(int32, int32), CandidateReason.Inaccessible)));
        }