Skip to content

Commit

Permalink
Add readonly ref readonly parsing test
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkiGibson committed Feb 24, 2019
1 parent 4997b24 commit c35df0e
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,56 @@ public void TestStructMethodWithReadonly()
Assert.Equal(SyntaxKind.None, ms.SemicolonToken.Kind());
}

[Fact]
public void TestReadOnlyRefReturning()
{
var text = "struct a { readonly ref readonly int M() { } }";
var file = this.ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Members.Count);
Assert.Equal(text, file.ToString());
Assert.Equal(0, file.Errors().Length);

Assert.Equal(SyntaxKind.StructDeclaration, file.Members[0].Kind());
var structDecl = (TypeDeclarationSyntax)file.Members[0];
Assert.Equal(0, structDecl.AttributeLists.Count);
Assert.Equal(0, structDecl.Modifiers.Count);
Assert.NotNull(structDecl.Keyword);
Assert.Equal(SyntaxKind.StructKeyword, structDecl.Keyword.Kind());
Assert.NotNull(structDecl.Identifier);
Assert.Equal("a", structDecl.Identifier.ToString());
Assert.Null(structDecl.BaseList);
Assert.Equal(0, structDecl.ConstraintClauses.Count);
Assert.NotNull(structDecl.OpenBraceToken);
Assert.NotNull(structDecl.CloseBraceToken);

Assert.Equal(1, structDecl.Members.Count);

Assert.Equal(SyntaxKind.MethodDeclaration, structDecl.Members[0].Kind());
var ms = (MethodDeclarationSyntax)structDecl.Members[0];
Assert.Equal(0, ms.AttributeLists.Count);
Assert.Equal(1, ms.Modifiers.Count);
Assert.Equal(SyntaxKind.ReadOnlyKeyword, ms.Modifiers[0].Kind());
Assert.Equal(SyntaxKind.RefType, ms.ReturnType.Kind());
var rt = (RefTypeSyntax)ms.ReturnType;
Assert.Equal(SyntaxKind.RefKeyword, rt.RefKeyword.Kind());
Assert.Equal(SyntaxKind.ReadOnlyKeyword, rt.ReadOnlyKeyword.Kind());
Assert.Equal("int", rt.Type.ToString());
Assert.NotNull(ms.Identifier);
Assert.Equal("M", ms.Identifier.ToString());
Assert.NotNull(ms.ParameterList.OpenParenToken);
Assert.False(ms.ParameterList.OpenParenToken.IsMissing);
Assert.Equal(0, ms.ParameterList.Parameters.Count);
Assert.NotNull(ms.ParameterList.CloseParenToken);
Assert.False(ms.ParameterList.CloseParenToken.IsMissing);
Assert.Equal(0, ms.ConstraintClauses.Count);
Assert.NotNull(ms.Body);
Assert.NotEqual(SyntaxKind.None, ms.Body.OpenBraceToken.Kind());
Assert.NotEqual(SyntaxKind.None, ms.Body.CloseBraceToken.Kind());
Assert.Equal(SyntaxKind.None, ms.SemicolonToken.Kind());
}

[Fact]
public void TestStructExpressionPropertyWithReadonly()
{
Expand Down

0 comments on commit c35df0e

Please sign in to comment.