Skip to content

Commit 84ea299

Browse files
authored
Add a handful of extra tests (#879)
1 parent 24e0793 commit 84ea299

File tree

3 files changed

+55
-23
lines changed

3 files changed

+55
-23
lines changed

tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructIntegrationTests.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.CodeAnalysis.CSharp.Syntax;
5+
using Silk.NET.SilkTouch.Symbols;
6+
using Xunit;
7+
8+
namespace Silk.NET.SilkTouch.Emitter.Tests;
9+
10+
public sealed class EmitterStructTests : EmitterTest
11+
{
12+
[Fact]
13+
public void StructIsStructSyntax()
14+
{
15+
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test")));
16+
Assert.IsType<StructDeclarationSyntax>(syntax);
17+
}
18+
19+
[Fact]
20+
public void StructHasStructKeyword()
21+
{
22+
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"))) as StructDeclarationSyntax;
23+
Assert.Equal("struct", syntax!.Keyword.Text);
24+
}
25+
26+
[Fact]
27+
public void StructHasCorrectIdentifier()
28+
{
29+
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"))) as StructDeclarationSyntax;
30+
Assert.Equal("Test", syntax!.Identifier.Text);
31+
}
32+
33+
[Fact]
34+
public void StructIsOnlyPublic()
35+
{
36+
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"))) as StructDeclarationSyntax;
37+
var @public = Assert.Single(syntax!.Modifiers);
38+
Assert.Equal("public", @public.Text);
39+
}
40+
41+
[Fact]
42+
public void IntegrationEmptyStruct()
43+
{
44+
// Note that this test also covers trivia, which is not checked otherwise.
45+
Assert.Equal("public struct Test{}", Transform(new StructSymbol(new IdentifierSymbol("Test"))).ToFullString());
46+
}
47+
}

tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using Microsoft.CodeAnalysis.CSharp;
5+
using Silk.NET.SilkTouch.Symbols;
6+
47
namespace Silk.NET.SilkTouch.Emitter.Tests;
58

69
public abstract class EmitterTest
@@ -9,4 +12,9 @@ protected CSharpEmitter CreateEmitter()
912
{
1013
return new CSharpEmitter();
1114
}
15+
16+
protected CSharpSyntaxNode Transform(Symbol symbol)
17+
{
18+
return CreateEmitter().Transform(symbol);
19+
}
1220
}

0 commit comments

Comments
 (0)