Skip to content

Commit f9c8043

Browse files
authored
Field Tests (#896)
1 parent a280613 commit f9c8043

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Immutable;
5+
using System.Linq;
6+
using Microsoft.CodeAnalysis;
7+
using Microsoft.CodeAnalysis.CSharp;
8+
using Microsoft.CodeAnalysis.CSharp.Syntax;
59
using Silk.NET.SilkTouch.Symbols;
610
using Xunit;
711

@@ -10,11 +14,63 @@ namespace Silk.NET.SilkTouch.Emitter.Tests;
1014
public sealed class EmitterFieldIntegrationTests : EmitterTest
1115
{
1216
[Fact]
13-
public void StructHasStructKeyword()
17+
public void FieldIntegration()
1418
{
1519
var syntax = Transform(new FieldSymbol(new StructSymbol(new IdentifierSymbol("int"),StructLayout.Empty), new IdentifierSymbol("Test")));
1620

1721
var result = syntax.ToFullString();
1822
Assert.Equal("public int Test;", result);
1923
}
24+
25+
[Fact]
26+
public void FieldIsPublic()
27+
{
28+
var syntax = Transform
29+
(
30+
new FieldSymbol
31+
(
32+
new StructSymbol(new IdentifierSymbol("int"), ImmutableArray<MemberSymbol>.Empty),
33+
new IdentifierSymbol("Test")
34+
)
35+
) as FieldDeclarationSyntax;
36+
37+
Assert.NotNull(syntax);
38+
Assert.Single(syntax!.Modifiers, x => x.IsKind(SyntaxKind.PublicKeyword));
39+
}
40+
41+
[Fact]
42+
public void FieldHasCorrectTypeIdentifier()
43+
{
44+
var syntax = Transform
45+
(
46+
new FieldSymbol
47+
(
48+
new StructSymbol(new IdentifierSymbol("int"), ImmutableArray<MemberSymbol>.Empty),
49+
new IdentifierSymbol("Test")
50+
)
51+
) as FieldDeclarationSyntax;
52+
53+
Assert.NotNull(syntax);
54+
var type = syntax!.Declaration.Type as SimpleNameSyntax;
55+
Assert.NotNull(type);
56+
Assert.Equal("int", type!.Identifier.Text);
57+
}
58+
59+
[Fact]
60+
public void FieldHasCorrectIdentifier()
61+
{
62+
var syntax = Transform
63+
(
64+
new FieldSymbol
65+
(
66+
new StructSymbol(new IdentifierSymbol("int"), ImmutableArray<MemberSymbol>.Empty),
67+
new IdentifierSymbol("Test")
68+
)
69+
) as FieldDeclarationSyntax;
70+
71+
Assert.NotNull(syntax);
72+
73+
var variableDeclaratorSyntax = Assert.Single(syntax!.Declaration.Variables);
74+
Assert.Equal("Test", variableDeclaratorSyntax.Identifier.Text);
75+
}
2076
}

0 commit comments

Comments
 (0)