2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . Collections . Immutable ;
5
+ using System . Linq ;
6
+ using Microsoft . CodeAnalysis ;
7
+ using Microsoft . CodeAnalysis . CSharp ;
8
+ using Microsoft . CodeAnalysis . CSharp . Syntax ;
5
9
using Silk . NET . SilkTouch . Symbols ;
6
10
using Xunit ;
7
11
@@ -10,11 +14,63 @@ namespace Silk.NET.SilkTouch.Emitter.Tests;
10
14
public sealed class EmitterFieldIntegrationTests : EmitterTest
11
15
{
12
16
[ Fact ]
13
- public void StructHasStructKeyword ( )
17
+ public void FieldIntegration ( )
14
18
{
15
19
var syntax = Transform ( new FieldSymbol ( new StructSymbol ( new IdentifierSymbol ( "int" ) , StructLayout . Empty ) , new IdentifierSymbol ( "Test" ) ) ) ;
16
20
17
21
var result = syntax . ToFullString ( ) ;
18
22
Assert . Equal ( "public int Test;" , result ) ;
19
23
}
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
+ }
20
76
}
0 commit comments