Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Assert warnings in Unit Test projects #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct foo {};
var semanticModel = compilation.GetSemanticModel();
var diagnostics = syntaxTree.GetDiagnostics().Concat(semanticModel.GetDiagnostics()).ToImmutableArray();

Assert.Equal(1, diagnostics.Length);
Assert.Single(diagnostics);
Assert.Equal(DiagnosticId.SymbolRedefined, (DiagnosticId) diagnostics[0].Descriptor.Code);
}

Expand All @@ -35,7 +35,7 @@ struct foo {};
var semanticModel = compilation.GetSemanticModel();
var diagnostics = syntaxTree.GetDiagnostics().Concat(semanticModel.GetDiagnostics()).ToImmutableArray();

Assert.Equal(1, diagnostics.Length);
Assert.Single(diagnostics);
Assert.Equal(DiagnosticId.SymbolRedefined, (DiagnosticId) diagnostics[0].Descriptor.Code);
}

Expand All @@ -52,7 +52,7 @@ void main()
var semanticModel = compilation.GetSemanticModel();
var diagnostics = syntaxTree.GetDiagnostics().Concat(semanticModel.GetDiagnostics()).ToImmutableArray();

Assert.Equal(1, diagnostics.Length);
Assert.Single(diagnostics);
Assert.Equal(DiagnosticId.UndeclaredVariable, (DiagnosticId) diagnostics[0].Descriptor.Code);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,15 @@ public void TestGlobalDeclarationWithPredefinedType(string typeText)
var file = ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);
Assert.Equal(text, file.ToString());
Assert.Equal(0, file.GetDiagnostics().Count());
Assert.Empty(file.GetDiagnostics());

Assert.Equal(SyntaxKind.VariableDeclarationStatement, file.Declarations[0].Kind);
var fs = (VariableDeclarationStatementSyntax)file.Declarations[0];
Assert.NotNull(fs.Declaration.Type);
Assert.Equal(typeText, fs.Declaration.Type.ToString());
Assert.Equal(1, fs.Declaration.Variables.Count);
Assert.Single(fs.Declaration.Variables);
Assert.NotNull(fs.Declaration.Variables[0].Identifier);
Assert.Equal("c", fs.Declaration.Variables[0].Identifier.ToString());
Assert.Null(fs.Declaration.Variables[0].Initializer);
Expand All @@ -420,16 +420,16 @@ public void TestGlobalDeclarationWithUnormFloatType()
var file = ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);
Assert.Equal(text, file.ToString());
Assert.Equal(0, file.GetDiagnostics().Count());
Assert.Empty(file.GetDiagnostics());

Assert.Equal(SyntaxKind.VariableDeclarationStatement, file.Declarations[0].Kind);
var fs = (VariableDeclarationStatementSyntax)file.Declarations[0];
Assert.NotNull(fs.Declaration.Type);
Assert.Equal(typeText, fs.Declaration.Type.ToString());
Assert.Equal(SyntaxKind.PredefinedObjectType, fs.Declaration.Type.Kind);
Assert.Equal(1, fs.Declaration.Variables.Count);
Assert.Single(fs.Declaration.Variables);
Assert.NotNull(fs.Declaration.Variables[0].Identifier);
Assert.Equal("c", fs.Declaration.Variables[0].Identifier.ToString());
Assert.Null(fs.Declaration.Variables[0].Initializer);
Expand All @@ -445,16 +445,16 @@ public void TestGlobalDeclarationWithUnnamedStructType()
var file = ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);
Assert.Equal(text, file.ToString());
Assert.Equal(0, file.GetDiagnostics().Count());
Assert.Empty(file.GetDiagnostics());

Assert.Equal(SyntaxKind.VariableDeclarationStatement, file.Declarations[0].Kind);
var fs = (VariableDeclarationStatementSyntax)file.Declarations[0];
Assert.NotNull(fs.Declaration.Type);
Assert.Equal(typeText, fs.Declaration.Type.ToString());
Assert.Equal(SyntaxKind.StructType, fs.Declaration.Type.Kind);
Assert.Equal(1, fs.Declaration.Variables.Count);
Assert.Single(fs.Declaration.Variables);
Assert.NotNull(fs.Declaration.Variables[0].Identifier);
Assert.Equal("c", fs.Declaration.Variables[0].Identifier.ToString());
Assert.Null(fs.Declaration.Variables[0].Initializer);
Expand All @@ -471,16 +471,16 @@ public void TestGlobalDeclarationWithTypedefStructType()
var file = ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);
Assert.Equal(text, file.ToString());
Assert.Equal(0, file.GetDiagnostics().Count());
Assert.Empty(file.GetDiagnostics());

Assert.Equal(SyntaxKind.TypedefStatement, file.Declarations[0].Kind);
var ts = (TypedefStatementSyntax)file.Declarations[0];
Assert.NotNull(ts.Type);
Assert.Equal(typeText, ts.Type.ToString());
Assert.Equal(SyntaxKind.StructType, ts.Type.Kind);
Assert.Equal(1, ts.Declarators.Count);
Assert.Single(ts.Declarators);
var ds = ts.Declarators[0];
Assert.NotNull(ds.Identifier);
Assert.Equal("c", ds.Identifier.ToString());
Expand All @@ -495,9 +495,9 @@ public void TestGlobalFunctionDeclaration()
var file = ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);
Assert.Equal(text, file.ToString());
Assert.Equal(0, file.GetDiagnostics().Count());
Assert.Empty(file.GetDiagnostics());

Assert.Equal(SyntaxKind.FunctionDeclaration, file.Declarations[0].Kind);
var fs = (FunctionDeclarationSyntax)file.Declarations[0];
Expand All @@ -506,7 +506,7 @@ public void TestGlobalFunctionDeclaration()
Assert.Equal("Foo", fs.Name.ToString());
Assert.NotNull(fs.ParameterList.OpenParenToken);
Assert.False(fs.ParameterList.OpenParenToken.IsMissing);
Assert.Equal(1, fs.ParameterList.Parameters.Count);
Assert.Single(fs.ParameterList.Parameters);
var fp = fs.ParameterList.Parameters[0];
Assert.Equal("int", fp.Type.ToString());
Assert.Equal("a", fp.Declarator.Identifier.ToString());
Expand All @@ -523,28 +523,28 @@ public void TestGlobalFunctionDefinition()
var file = ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);
Assert.Equal(text, file.ToString());
Assert.Equal(0, file.GetDiagnostics().Count());
Assert.Empty(file.GetDiagnostics());

Assert.Equal(SyntaxKind.FunctionDefinition, file.Declarations[0].Kind);
var fs = (FunctionDefinitionSyntax)file.Declarations[0];
Assert.Equal(1, fs.Modifiers.Count);
Assert.Single(fs.Modifiers);
Assert.Equal(SyntaxKind.InlineKeyword, fs.Modifiers[0].Kind);
Assert.NotNull(fs.ReturnType);
Assert.Equal("void", fs.ReturnType.ToString());
Assert.Equal("Foo", fs.Name.ToString());
Assert.NotNull(fs.ParameterList.OpenParenToken);
Assert.False(fs.ParameterList.OpenParenToken.IsMissing);
Assert.Equal(1, fs.ParameterList.Parameters.Count);
Assert.Single(fs.ParameterList.Parameters);
var fp = fs.ParameterList.Parameters[0];
Assert.Equal("int", fp.Type.ToString());
Assert.Equal("a", fp.Declarator.Identifier.ToString());
Assert.NotNull(fs.ParameterList.CloseParenToken);
Assert.False(fs.ParameterList.CloseParenToken.IsMissing);
Assert.NotNull(fs.Body);
Assert.NotNull(fs.Body.OpenBraceToken);
Assert.Equal(1, fs.Body.Statements.Count);
Assert.Single(fs.Body.Statements);
Assert.NotNull(fs.Body.CloseBraceToken);
Assert.Null(fs.SemicolonToken);
}
Expand All @@ -556,28 +556,28 @@ public void TestExportFunctionDefinition()
var file = ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);
Assert.Equal(text, file.ToString());
Assert.Equal(0, file.GetDiagnostics().Count());
Assert.Empty(file.GetDiagnostics());

Assert.Equal(SyntaxKind.FunctionDefinition, file.Declarations[0].Kind);
var fs = (FunctionDefinitionSyntax)file.Declarations[0];
Assert.Equal(1, fs.Modifiers.Count);
Assert.Single(fs.Modifiers);
Assert.Equal(SyntaxKind.ExportKeyword, fs.Modifiers[0].Kind);
Assert.NotNull(fs.ReturnType);
Assert.Equal("void", fs.ReturnType.ToString());
Assert.Equal("Foo", fs.Name.ToString());
Assert.NotNull(fs.ParameterList.OpenParenToken);
Assert.False(fs.ParameterList.OpenParenToken.IsMissing);
Assert.Equal(1, fs.ParameterList.Parameters.Count);
Assert.Single(fs.ParameterList.Parameters);
var fp = fs.ParameterList.Parameters[0];
Assert.Equal("int", fp.Type.ToString());
Assert.Equal("a", fp.Declarator.Identifier.ToString());
Assert.NotNull(fs.ParameterList.CloseParenToken);
Assert.False(fs.ParameterList.CloseParenToken.IsMissing);
Assert.NotNull(fs.Body);
Assert.NotNull(fs.Body.OpenBraceToken);
Assert.Equal(1, fs.Body.Statements.Count);
Assert.Single(fs.Body.Statements);
Assert.NotNull(fs.Body.CloseBraceToken);
Assert.Null(fs.SemicolonToken);
}
Expand All @@ -589,15 +589,15 @@ public void TestSamplerStateInitializer()
var file = ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);
Assert.Equal(text, file.ToString());
Assert.Empty(file.GetDiagnostics());

Assert.Equal(SyntaxKind.VariableDeclarationStatement, file.Declarations[0].Kind);
var fs = (VariableDeclarationStatementSyntax)file.Declarations[0];
Assert.NotNull(fs.Declaration.Type);
Assert.Equal("SamplerState", fs.Declaration.Type.ToString());
Assert.Equal(1, fs.Declaration.Variables.Count);
Assert.Single(fs.Declaration.Variables);
Assert.Equal("MySamplerState", fs.Declaration.Variables[0].Identifier.Text);
Assert.Equal(SyntaxKind.StateInitializer, fs.Declaration.Variables[0].Initializer.Kind);
var init = (StateInitializerSyntax) fs.Declaration.Variables[0].Initializer;
Expand Down Expand Up @@ -634,17 +634,17 @@ public void TestTechnique()
var file = ParseFile(text);

Assert.NotNull(file);
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);
Assert.Equal(text, file.ToString());
Assert.Equal(1, file.GetDiagnostics().Count());
Assert.Single(file.GetDiagnostics());

Assert.Equal(SyntaxKind.TechniqueDeclaration, file.Declarations[0].Kind);
var fs = (TechniqueSyntax)file.Declarations[0];
Assert.False(fs.TechniqueKeyword.IsMissing);
Assert.Null(fs.Name);
Assert.Equal(1, fs.Passes.Count);
Assert.Single(fs.Passes);
Assert.Equal("Pass1", fs.Passes[0].Name.Text);
Assert.Equal(0, fs.Passes[0].Statements.Count);
Assert.Empty(fs.Passes[0].Statements);

Assert.NotNull(fs.SemicolonToken);
}
Expand All @@ -658,11 +658,11 @@ public void TestAttributeSpecifierOnFunctionReturn()
Assert.NotNull(file);
Assert.Empty(file.GetDiagnostics());
Assert.Equal(text, file.ToString());
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);

Assert.Equal(SyntaxKind.FunctionDefinition, file.Declarations[0].Kind);
var fd = (FunctionDefinitionSyntax)file.Declarations[0];
Assert.Equal(1, fd.Attributes.Count);
Assert.Single(fd.Attributes);
}

[Fact]
Expand All @@ -674,11 +674,11 @@ public void TestAttributeSpecifierOnFunctionParameter()
Assert.NotNull(file);
Assert.Empty(file.GetDiagnostics());
Assert.Equal(text, file.ToString());
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);

Assert.Equal(SyntaxKind.FunctionDefinition, file.Declarations[0].Kind);
var fd = (FunctionDefinitionSyntax)file.Declarations[0];
Assert.Equal(1, fd.ParameterList.Parameters[0].Attributes.Count);
Assert.Single(fd.ParameterList.Parameters[0].Attributes);
}

[Fact]
Expand All @@ -690,11 +690,11 @@ public void TestAttributeSpecifierOnStructuredBuffer()
Assert.NotNull(file);
Assert.Empty(file.GetDiagnostics());
Assert.Equal(text, file.ToString());
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);

Assert.Equal(SyntaxKind.VariableDeclarationStatement, file.Declarations[0].Kind);
var fd = (VariableDeclarationStatementSyntax)file.Declarations[0];
Assert.Equal(1, fd.Attributes.Count);
Assert.Single(fd.Attributes);
}

[Fact]
Expand All @@ -706,15 +706,15 @@ public void TestAttributeSpecifierOnStructField()
Assert.NotNull(file);
Assert.Empty(file.GetDiagnostics());
Assert.Equal(text, file.ToString());
Assert.Equal(1, file.Declarations.Count);
Assert.Single(file.Declarations);

Assert.Equal(SyntaxKind.TypeDeclarationStatement, file.Declarations[0].Kind);
var fd = (TypeDeclarationStatementSyntax)file.Declarations[0];
Assert.Equal(SyntaxKind.StructType, fd.Type.Kind);
var st = (StructTypeSyntax)fd.Type;
Assert.Equal(SyntaxKind.VariableDeclarationStatement, st.Members[0].Kind);
var vd = (VariableDeclarationStatementSyntax)st.Members[0];
Assert.Equal(1, vd.Attributes.Count);
Assert.Single(vd.Attributes);
}

[Fact]
Expand All @@ -730,7 +730,7 @@ public void TestAttributeSpecifierOnGlobalVariable()

Assert.Equal(SyntaxKind.VariableDeclarationStatement, file.Declarations[1].Kind);
var fd = (VariableDeclarationStatementSyntax)file.Declarations[1];
Assert.Equal(1, fd.Attributes.Count);
Assert.Single(fd.Attributes);
}

private static CompilationUnitSyntax ParseFile(string text)
Expand Down
Loading
Loading