1+ using Genbox . FastData . Enums ;
2+ using Genbox . FastData . Generator . CPlusPlus . Internal . Framework ;
3+ using Genbox . FastData . Generator . Extensions ;
4+ using Genbox . FastData . Generator . Framework ;
5+ using static Genbox . FastData . Generator . Helpers . FormatHelper ;
6+ using static Genbox . FastData . InternalShared . Helpers . TestHelper ;
7+
8+ namespace Genbox . FastData . Generator . CPlusPlus . Tests ;
9+
10+ public class FeatureTests ( CPlusPlusContext context ) : IClassFixture < CPlusPlusContext >
11+ {
12+ [ Fact ]
13+ public async Task StructSupportTest ( )
14+ {
15+ int [ ] values = [ 1 , 2 , 3 ] ;
16+ const string id = nameof ( StructSupportTest ) ;
17+
18+ string genSource = FastDataGenerator . GenerateKeyed ( values , [
19+ new X { Age = 1 , Name = "Bob" } ,
20+ new X { Age = 2 , Name = "Billy" } ,
21+ new X { Age = 3 , Name = "Bibi" } ,
22+ ] , new FastDataConfig { StructureType = StructureType . Array } , CPlusPlusCodeGenerator . Create ( new CPlusPlusCodeGeneratorConfig ( id ) ) ) ;
23+
24+ await Verify ( genSource )
25+ . UseFileName ( id )
26+ . UseDirectory ( "Features" )
27+ . DisableDiff ( ) ;
28+
29+ CPlusPlusLanguageDef langDef = new CPlusPlusLanguageDef ( ) ;
30+ TypeMap map = new TypeMap ( langDef . TypeDefinitions , GeneratorEncoding . ASCII ) ;
31+
32+ string testSource = $$ """
33+ #include <string>
34+ #include <iostream>
35+
36+ {{ genSource }}
37+
38+ int main(int argc, char* argv[])
39+ {
40+ {{ FormatList ( values , x => $ """
41+ if (!{ id } ::contains({ map . ToValueLabel ( x ) } ))
42+ return false;
43+ """ , "\n " ) }}
44+
45+ return 1;
46+ }
47+ """ ;
48+
49+ string executable = context . Compiler . Compile ( id , testSource ) ;
50+ Assert . Equal ( 1 , RunProcess ( executable ) ) ;
51+ }
52+
53+ internal struct X
54+ {
55+ public int Age { get ; set ; }
56+ public string Name { get ; set ; }
57+ }
58+ }
0 commit comments