@@ -6,7 +6,7 @@ namespace PCL2.Neo.Tests.Minecraft.Models;
66public class MetadataFileTest
77{
88 [ Test ]
9- public void Test ( )
9+ public void MainParsingTest ( )
1010 {
1111 foreach ( var metadataFilePath in Directory . EnumerateFiles ( "./MCMetadataFiles" ) )
1212 {
@@ -76,4 +76,184 @@ public void Test()
7676 Assert . That ( meta . Type , Is . Not . EqualTo ( MetadataFile . ReleaseTypeEnum . Unknown ) ) ;
7777 }
7878 }
79+
80+ [ Test ]
81+ public void ArgumentsParsingTest ( )
82+ {
83+ object [ ] testGameArgs =
84+ [
85+ "--username" ,
86+ "${auth_player_name}" ,
87+ "--version" ,
88+ "${version_name}" ,
89+ "--gameDir" ,
90+ "${game_directory}" ,
91+ "--assetsDir" ,
92+ "${assets_root}" ,
93+ "--assetIndex" ,
94+ "${assets_index_name}" ,
95+ "--uuid" ,
96+ "${auth_uuid}" ,
97+ "--accessToken" ,
98+ "${auth_access_token}" ,
99+ "--clientId" ,
100+ "${clientid}" ,
101+ "--xuid" ,
102+ "${auth_xuid}" ,
103+ "--userType" ,
104+ "${user_type}" ,
105+ "--versionType" ,
106+ "${version_type}" ,
107+ new MetadataFile . ConditionalArg
108+ {
109+ Rules = [
110+ new MetadataFile . Rule
111+ {
112+ Action = MetadataFile . Rule . ActionEnum . Allow ,
113+ Features = new Dictionary < string , bool >
114+ {
115+ [ "is_demo_user" ] = true
116+ }
117+ }
118+ ] ,
119+ Value = [ "--demo" ]
120+ } ,
121+ new MetadataFile . ConditionalArg
122+ {
123+ Rules = [
124+ new MetadataFile . Rule
125+ {
126+ Action = MetadataFile . Rule . ActionEnum . Allow ,
127+ Features = new Dictionary < string , bool >
128+ {
129+ [ "has_custom_resolution" ] = true
130+ }
131+ }
132+ ] ,
133+ Value =
134+ [
135+ "--width" ,
136+ "${resolution_width}" ,
137+ "--height" ,
138+ "${resolution_height}"
139+ ]
140+ } ,
141+ new MetadataFile . ConditionalArg
142+ {
143+ Rules = [
144+ new MetadataFile . Rule
145+ {
146+ Action = MetadataFile . Rule . ActionEnum . Allow ,
147+ Features = new Dictionary < string , bool >
148+ {
149+ [ "has_quick_plays_support" ] = true
150+ }
151+ }
152+ ] ,
153+ Value =
154+ [
155+ "--quickPlayPath" ,
156+ "${quickPlayPath}"
157+ ]
158+ } ,
159+ new MetadataFile . ConditionalArg
160+ {
161+ Rules = [
162+ new MetadataFile . Rule
163+ {
164+ Action = MetadataFile . Rule . ActionEnum . Allow ,
165+ Features = new Dictionary < string , bool >
166+ {
167+ [ "is_quick_play_singleplayer" ] = true
168+ }
169+ }
170+ ] ,
171+ Value =
172+ [
173+ "--quickPlaySingleplayer" ,
174+ "${quickPlaySingleplayer}"
175+ ]
176+ } ,
177+ new MetadataFile . ConditionalArg
178+ {
179+ Rules = [
180+ new MetadataFile . Rule
181+ {
182+ Action = MetadataFile . Rule . ActionEnum . Allow ,
183+ Features = new Dictionary < string , bool >
184+ {
185+ [ "is_quick_play_multiplayer" ] = true
186+ }
187+ }
188+ ] ,
189+ Value =
190+ [
191+ "--quickPlayMultiplayer" ,
192+ "${quickPlayMultiplayer}"
193+ ]
194+ } ,
195+ new MetadataFile . ConditionalArg
196+ {
197+ Rules = [
198+ new MetadataFile . Rule
199+ {
200+ Action = MetadataFile . Rule . ActionEnum . Allow ,
201+ Features = new Dictionary < string , bool >
202+ {
203+ [ "is_quick_play_realms" ] = true
204+ }
205+ }
206+ ] ,
207+ Value =
208+ [
209+ "--quickPlayRealms" ,
210+ "${quickPlayRealms}"
211+ ]
212+ }
213+ ] ;
214+
215+ var jsonObj = JsonNode . Parse ( File . ReadAllText ( "./MCMetadataFiles/1.21.5.json" ) ) ! . AsObject ( ) ;
216+ var meta = new MetadataFile ( jsonObj , false ) ;
217+ meta . Parse ( ) ;
218+ Assert . That ( meta . Arguments . Game . Count , Is . EqualTo ( testGameArgs . Length ) ) ;
219+ for ( int i = 0 ; i < meta . Arguments . Game . Count ; i ++ )
220+ {
221+ if ( testGameArgs [ i ] is string )
222+ {
223+ Assert . That ( meta . Arguments . Game [ i ] . Value . Count , Is . EqualTo ( 1 ) ) ;
224+ Assert . That ( meta . Arguments . Game [ i ] . Value [ 0 ] , Is . EqualTo ( testGameArgs [ i ] ) ) ;
225+ }
226+ else
227+ {
228+ var arg = meta . Arguments . Game [ i ] ;
229+ var testArg = ( MetadataFile . ConditionalArg ) testGameArgs [ i ] ;
230+
231+ Assert . That ( arg . Value . SequenceEqual ( testArg . Value ) , Is . True ) ;
232+ Assert . That (
233+ ( arg . Rules is null && testArg . Rules is null ) ||
234+ ( arg . Rules is not null && testArg . Rules is not null ) ) ;
235+ if ( arg . Rules is not null && testArg . Rules is not null )
236+ {
237+ Assert . That ( arg . Rules . Count , Is . EqualTo ( testArg . Rules . Count ) ) ;
238+ foreach ( ( MetadataFile . Rule rule , MetadataFile . Rule testRule ) in arg . Rules . Zip ( testArg . Rules ) )
239+ {
240+ Assert . That ( rule . Action , Is . EqualTo ( testRule . Action ) ) ;
241+ Assert . That ( ( rule . Features is null && testRule . Features is null ) ||
242+ ( rule . Features is not null && testRule . Features is not null ) ) ;
243+ if ( rule . Features is not null && testRule . Features is not null )
244+ Assert . That ( rule . Features . SequenceEqual ( testRule . Features ) ) ;
245+ Assert . That ( ( rule . Os is null && testRule . Os is null ) ||
246+ ( rule . Os is not null && testRule . Os is not null ) ) ;
247+ if ( rule . Os is not null && testRule . Os is not null )
248+ {
249+ Assert . That ( rule . Os . Arch , Is . EqualTo ( testRule . Os . Arch ) ) ;
250+ Assert . That ( rule . Os . Name , Is . EqualTo ( testRule . Os . Name ) ) ;
251+ Assert . That ( rule . Os . Version , Is . EqualTo ( testRule . Os . Version ) ) ;
252+ }
253+ }
254+ }
255+ }
256+ }
257+
258+ }
79259}
0 commit comments