public void ReturnsItselfAmongOtherFields() { Data.FieldData data = GetField("class Test { int field1, field2; }"); Data.FieldData[] other = data.GetUnderlayingFields().ToArray(); Assert.True(other.Length == 2 && other.Any(d => d == data) && other.Any(d => d.Name == "field2")); }
public void ReturnsSelf_When_HasNoOtherFieldsOnDeclaration() { Data.FieldData data = GetField("class Test { int field; }"); Data.FieldData[] other = data.GetUnderlayingFields().ToArray(); Assert.True(other.Length == 1 && data == other[0]); }
public void CanReturnMultipleFields() { Data.FieldData data = GetField("class Test { int field1, field2; }"); Data.FieldData[] other = data.GetUnderlayingFields().ToArray(); Assert.True(other.Length == 2 && other.Any(d => d.Name == "field1") && other.Any(d => d.Name == "field2")); }
public void ReturnsValidFieldData_When_HasMultipleFieldsInSingleDeclaration() { FieldDeclarationSyntax field = GetNode <FieldDeclarationSyntax>("class Test { int Age = 0, Index = 2 }"); SemanticModel semanticModel = Compilation.CurrentCompilation.GetSemanticModel(field.SyntaxTree); IFieldSymbol symbol1 = (semanticModel.GetDeclaredSymbol(field.Declaration.Variables[0]) as IFieldSymbol) !; IFieldSymbol symbol2 = (semanticModel.GetDeclaredSymbol(field.Declaration.Variables[1]) as IFieldSymbol) !; Data.FieldData?data = symbol1.GetMemberData(Compilation) as Data.FieldData; Data.FieldData[]? declaredFields = data?.GetUnderlayingFields().ToArray(); Assert.True(ValidateMember(data, field, symbol1) && declaredFields !.Length == 2 && ValidateMember(declaredFields[1], field, symbol2)); }