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
3535    /// <returns>Any number of symbols scraped from the given xml</returns> 
3636    public  IEnumerable < Symbol >  ScrapeXML ( XmlDocument  document ) 
3737    { 
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 ( ) ; 
3939
4040        if  ( bindings  is  null ) 
4141        { 
Original file line number Diff line number Diff line change @@ -21,13 +21,27 @@ public IEnumerable<Symbol> Visit(XmlNode node)
2121                return  VisitBinding ( bindings ) ; 
2222            case  XmlElement  {  Name :  "namespace"  }  @namespace : 
2323                return  VisitNamespace ( @namespace ) ; 
24+             case  XmlElement  {  Name :  "struct"  }  @struct : 
25+                 return  VisitStruct ( @struct ) ; 
2426            default : 
2527            { 
2628                throw  new  NotImplementedException ( ) ; 
2729            } 
2830        } 
2931    } 
3032
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+ 
3145    private  IEnumerable < Symbol >  VisitBinding ( XmlElement  bindings ) 
3246    { 
3347        return  bindings . ChildNodes . Cast < XmlNode > ( ) . Where ( x =>  x  is  not null ) . SelectMany ( Visit ) ; 
Original file line number Diff line number Diff line change 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  System . Xml ; 
5+ using  Silk . NET . SilkTouch . Symbols ; 
46using  Xunit ; 
57
68namespace  Silk . NET . SilkTouch . Scraper . Tests ; 
@@ -10,6 +12,25 @@ public class StructScrapingTests
1012    [ Fact ] 
1113    public  void  StructXMLGeneratesStructSymbol ( ) 
1214    { 
15+         var  doc  =  new  XmlDocument ( ) ; 
16+         doc . LoadXml ( @"<struct name=""Test""></struct>" ) ; 
1317
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 ) ; 
1435    } 
1536} 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments