File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed
src/generators/Silk.NET.SilkTouch.Scraper
tests/Silk.NET.SilkTouch.Scraper.Tests Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public sealed class ClangScraper
35
35
/// <returns>Any number of symbols scraped from the given xml</returns>
36
36
public IEnumerable < Symbol > ScrapeXML ( XmlDocument document )
37
37
{
38
- var bindings = document . ChildNodes . Cast < XmlNode > ( ) . FirstOrDefault ( x => x . LocalName == "bindings" && x is XmlElement ) as XmlElement ;
38
+ var bindings = document . ChildNodes . Cast < XmlNode > ( ) . OfType < XmlElement > ( ) . FirstOrDefault ( ) ;
39
39
40
40
if ( bindings is null )
41
41
{
Original file line number Diff line number Diff line change @@ -21,13 +21,27 @@ public IEnumerable<Symbol> Visit(XmlNode node)
21
21
return VisitBinding ( bindings ) ;
22
22
case XmlElement { Name : "namespace" } @namespace :
23
23
return VisitNamespace ( @namespace ) ;
24
+ case XmlElement { Name : "struct" } @struct :
25
+ return VisitStruct ( @struct ) ;
24
26
default :
25
27
{
26
28
throw new NotImplementedException ( ) ;
27
29
}
28
30
}
29
31
}
30
32
33
+ private IEnumerable < Symbol > VisitStruct ( XmlElement @struct )
34
+ {
35
+ return new [ ]
36
+ {
37
+ new StructSymbol
38
+ (
39
+ new IdentifierSymbol ( @struct . Attributes ? [ "name" ] ? . Value ?? throw new InvalidOperationException ( ) ) ,
40
+ StructLayout . Empty
41
+ )
42
+ } ;
43
+ }
44
+
31
45
private IEnumerable < Symbol > VisitBinding ( XmlElement bindings )
32
46
{
33
47
return bindings . ChildNodes . Cast < XmlNode > ( ) . Where ( x => x is not null ) . SelectMany ( Visit ) ;
Original file line number Diff line number Diff line change 1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Xml ;
5
+ using Silk . NET . SilkTouch . Symbols ;
4
6
using Xunit ;
5
7
6
8
namespace Silk . NET . SilkTouch . Scraper . Tests ;
@@ -10,6 +12,25 @@ public class StructScrapingTests
10
12
[ Fact ]
11
13
public void StructXMLGeneratesStructSymbol ( )
12
14
{
15
+ var doc = new XmlDocument ( ) ;
16
+ doc . LoadXml ( @"<struct name=""Test""></struct>" ) ;
13
17
18
+ var symbols = new ClangScraper ( ) . ScrapeXML ( doc ) ;
19
+
20
+ var symbol = Assert . Single ( symbols ) ;
21
+ var @struct = Assert . IsType < StructSymbol > ( symbol ) ;
22
+ }
23
+
24
+ [ Fact ]
25
+ public void StructXMLGeneratesCorrectIdentifier ( )
26
+ {
27
+ var doc = new XmlDocument ( ) ;
28
+ doc . LoadXml ( @"<struct name=""Test""></struct>" ) ;
29
+
30
+ var symbols = new ClangScraper ( ) . ScrapeXML ( doc ) ;
31
+
32
+ var symbol = Assert . Single ( symbols ) ;
33
+ var @struct = Assert . IsType < StructSymbol > ( symbol ) ;
34
+ Assert . Equal ( "Test" , @struct . Identifier . Value ) ;
14
35
}
15
36
}
You can’t perform that action at this time.
0 commit comments