11using System ;
2+ using System . Collections . Generic ;
23using System . Globalization ;
34using System . IO ;
45using System . Linq ;
6+ using System . Reflection ;
57using System . Text ;
68using System . Threading ;
79using Microsoft . VisualStudio . TestTools . UnitTesting ;
@@ -235,12 +237,12 @@ public void TestWhitespace()
235237 Assert . AreEqual ( 2 , map . Worldspawn . Children . Count ) ;
236238 }
237239
240+ [ DataTestMethod ]
238241 [ DataRow ( QuakeFormatFile , DisplayName = nameof ( QuakeFormatFile ) ) ]
239242 [ DataRow ( ValveFormatFile , DisplayName = nameof ( ValveFormatFile ) ) ]
240243 [ DataRow ( Quake2StandardFormatFile , DisplayName = nameof ( Quake2StandardFormatFile ) ) ]
241244 [ DataRow ( Quake2ValveFormatFile , DisplayName = nameof ( Quake2ValveFormatFile ) ) ]
242245 [ DataRow ( LotsOfWhitespace , DisplayName = nameof ( LotsOfWhitespace ) ) ]
243- [ DataTestMethod ]
244246 public void TestAddCommentToEveryRow ( string file )
245247 {
246248 var commented = String . Join ( '\n ' , file . Split ( '\n ' ) . Select ( x => x + " // this is a comment " ) ) ;
@@ -263,4 +265,40 @@ public void TestLocales(string culture)
263265
264266 Assert . AreEqual ( 4 , map . Worldspawn . Children . Count ) ;
265267 }
268+
269+ private static readonly string [ ] ReparseHints = { "idTech2" , "Worldcraft" } ;
270+
271+ public static IEnumerable < object [ ] > GetFileHintCombinations ( )
272+ {
273+ foreach ( var h in ReparseHints )
274+ {
275+ yield return new object [ ] { nameof ( QuakeFormatFile ) , h , QuakeFormatFile } ;
276+ yield return new object [ ] { nameof ( ValveFormatFile ) , h , ValveFormatFile } ;
277+ yield return new object [ ] { nameof ( Quake2StandardFormatFile ) , h , Quake2StandardFormatFile } ;
278+ yield return new object [ ] { nameof ( Quake2ValveFormatFile ) , h , Quake2ValveFormatFile } ;
279+ yield return new object [ ] { nameof ( LotsOfWhitespace ) , h , LotsOfWhitespace } ;
280+ }
281+ }
282+
283+ public static string GetFileHintCombinationDisplayName ( MethodInfo method , object [ ] data )
284+ {
285+ return $ "{ method . Name } ({ data [ 0 ] } , { data [ 1 ] } )";
286+ }
287+
288+ [ DataTestMethod ]
289+ [ DynamicData ( nameof ( GetFileHintCombinations ) , DynamicDataSourceType . Method , DynamicDataDisplayName = nameof ( GetFileHintCombinationDisplayName ) ) ]
290+ public void TestReParse ( string name , string hint , string file )
291+ {
292+ var format = new QuakeMapFormat ( ) ;
293+ var stream = new MemoryStream ( Encoding . ASCII . GetBytes ( file ) ) ;
294+ var expected = format . Read ( stream ) ;
295+
296+ using var ms = new MemoryStream ( ) ;
297+ format . Write ( ms , expected , hint ) ;
298+ ms . Seek ( 0 , SeekOrigin . Begin ) ;
299+ Console . Write ( Encoding . ASCII . GetString ( ms . ToArray ( ) ) ) ;
300+
301+ var actual = format . Read ( ms ) ;
302+ TestUtils . AreEqualMap ( expected , actual ) ;
303+ }
266304}
0 commit comments