Skip to content

Extra tests for Struct emission #879

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

Merged
merged 1 commit into from
Apr 10, 2022
Merged
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

This file was deleted.

47 changes: 47 additions & 0 deletions tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.CodeAnalysis.CSharp.Syntax;
using Silk.NET.SilkTouch.Symbols;
using Xunit;

namespace Silk.NET.SilkTouch.Emitter.Tests;

public sealed class EmitterStructTests : EmitterTest
{
[Fact]
public void StructIsStructSyntax()
{
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test")));
Assert.IsType<StructDeclarationSyntax>(syntax);
}

[Fact]
public void StructHasStructKeyword()
{
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"))) as StructDeclarationSyntax;
Assert.Equal("struct", syntax!.Keyword.Text);
}

[Fact]
public void StructHasCorrectIdentifier()
{
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"))) as StructDeclarationSyntax;
Assert.Equal("Test", syntax!.Identifier.Text);
}

[Fact]
public void StructIsOnlyPublic()
{
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"))) as StructDeclarationSyntax;
var @public = Assert.Single(syntax!.Modifiers);
Assert.Equal("public", @public.Text);
}

[Fact]
public void IntegrationEmptyStruct()
{
// Note that this test also covers trivia, which is not checked otherwise.
Assert.Equal("public struct Test{}", Transform(new StructSymbol(new IdentifierSymbol("Test"))).ToFullString());
}
}
8 changes: 8 additions & 0 deletions tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.CodeAnalysis.CSharp;
using Silk.NET.SilkTouch.Symbols;

namespace Silk.NET.SilkTouch.Emitter.Tests;

public abstract class EmitterTest
Expand All @@ -9,4 +12,9 @@ protected CSharpEmitter CreateEmitter()
{
return new CSharpEmitter();
}

protected CSharpSyntaxNode Transform(Symbol symbol)
{
return CreateEmitter().Transform(symbol);
}
}