11using System ;
2+ using System . Linq ;
3+ using System . Text . RegularExpressions ;
24using NUnit . Framework ;
35
46namespace UnityNuGet . Tests
@@ -8,7 +10,9 @@ public class UnityMetaTests
810 [ Test ]
911 public void GetMetaForDll_FormatsDefineConstraintsProperly_WithoutConstraints ( )
1012 {
11- var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , true , Array . Empty < string > ( ) , Array . Empty < string > ( ) ) ;
13+ var platformDefs = PlatformDefinition . CreateAllPlatforms ( ) ;
14+ var anyOs = platformDefs . Find ( UnityOs . AnyOs , UnityCpu . AnyCpu ) ;
15+ var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , anyOs , Array . Empty < string > ( ) , Array . Empty < string > ( ) ) ;
1216 StringAssert . DoesNotContain ( "defineConstraints" , output ) ;
1317
1418 // This is on the same line in the template, so ensure it's intact
@@ -18,7 +22,9 @@ public void GetMetaForDll_FormatsDefineConstraintsProperly_WithoutConstraints()
1822 [ Test ]
1923 public void GetMetaForDll_FormatsLabelsProperly_WithoutLabels ( )
2024 {
21- var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , true , Array . Empty < string > ( ) , Array . Empty < string > ( ) ) ;
25+ var platformDefs = PlatformDefinition . CreateAllPlatforms ( ) ;
26+ var anyOs = platformDefs . Find ( UnityOs . AnyOs , UnityCpu . AnyCpu ) ;
27+ var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , anyOs , Array . Empty < string > ( ) , Array . Empty < string > ( ) ) ;
2228 StringAssert . DoesNotContain ( "labels" , output ) ;
2329
2430 // This is on the same line in the template, so ensure it's intact
@@ -30,7 +36,9 @@ public void GetMetaForDll_FormatsLabelsProperly_WithoutLabels()
3036 public void GetMetaForDll_FormatsDefineConstraintsProperly_WithConstraints (
3137 string [ ] constraints , string expected )
3238 {
33- var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , true , Array . Empty < string > ( ) , constraints ) ;
39+ var platformDefs = PlatformDefinition . CreateAllPlatforms ( ) ;
40+ var anyOs = platformDefs . Find ( UnityOs . AnyOs , UnityCpu . AnyCpu ) ;
41+ var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , anyOs , Array . Empty < string > ( ) , constraints ) ;
3442
3543 StringAssert . Contains ( expected , output ) ;
3644
@@ -43,7 +51,9 @@ public void GetMetaForDll_FormatsDefineConstraintsProperly_WithConstraints(
4351 public void GetMetaForDll_FormatsLabelsProperly_WithLabels (
4452 string [ ] labels , string expected )
4553 {
46- var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , true , labels , Array . Empty < string > ( ) ) ;
54+ var platformDefs = PlatformDefinition . CreateAllPlatforms ( ) ;
55+ var anyOs = platformDefs . Find ( UnityOs . AnyOs , UnityCpu . AnyCpu ) ;
56+ var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , anyOs , labels , Array . Empty < string > ( ) ) ;
4757
4858 StringAssert . Contains ( expected , output ) ;
4959
@@ -55,16 +65,98 @@ public void GetMetaForDll_FormatsLabelsProperly_WithLabels(
5565 [ TestCase ( false , "0" ) ]
5666 public void GetMetaForDll_FormatsAnyPlatformEnabledProperly ( bool value , string expected )
5767 {
58- var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , value , Array . Empty < string > ( ) , Array . Empty < string > ( ) ) ;
68+ PlatformDefinition platformDef ;
69+
70+ if ( value )
71+ {
72+ var platformDefs = PlatformDefinition . CreateAllPlatforms ( ) ;
73+ platformDef = platformDefs . Find ( UnityOs . AnyOs , UnityCpu . AnyCpu ) ;
74+ }
75+ else
76+ {
77+ platformDef = new PlatformDefinition ( UnityOs . AnyOs , UnityCpu . None , isEditorConfig : false ) ;
78+ }
79+
80+ var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , platformDef , Array . Empty < string > ( ) , Array . Empty < string > ( ) ) ;
5981
6082 StringAssert . Contains ( $ "\n platformData:\n - first:\n Any:\n second:\n enabled: { expected } \n ", output ) ;
6183 }
6284
6385 [ Test ]
6486 public void GetMetaForDll_ContainsNoWindowsNewlines ( )
6587 {
66- var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , true , Array . Empty < string > ( ) , new [ ] { "TEST" } ) ;
88+ var platformDefs = PlatformDefinition . CreateAllPlatforms ( ) ;
89+ var anyOs = platformDefs . Find ( UnityOs . AnyOs , UnityCpu . AnyCpu ) ;
90+ var output = UnityMeta . GetMetaForDll ( Guid . NewGuid ( ) , anyOs , Array . Empty < string > ( ) , new [ ] { "TEST" } ) ;
6791 StringAssert . DoesNotContain ( "\r " , output ) ;
6892 }
93+
94+ [ TestCase ( UnityOs . Android , "Android" , "Android" ) ]
95+ [ TestCase ( UnityOs . WebGL , "WebGL" , "WebGL" ) ]
96+ [ TestCase ( UnityOs . iOS , "iPhone" , "iOS" ) ]
97+ public void GetMetaForDll_NonEditor ( UnityOs os , string platformName , string osName )
98+ {
99+ var platformDefs = PlatformDefinition . CreateAllPlatforms ( ) ;
100+ var output = UnityMeta . GetMetaForDll (
101+ Guid . NewGuid ( ) ,
102+ platformDefs . Find ( os ) ,
103+ Array . Empty < string > ( ) ,
104+ Array . Empty < string > ( ) ) ;
105+
106+ // There should be a single 'Exclude Android: 0' match
107+ var excludeRegex = new Regex ( "Exclude (.*): 0" ) ;
108+ var excludeMatches = excludeRegex . Matches ( output ) ;
109+ Assert . IsNotNull ( excludeMatches ) ;
110+ Assert . AreEqual ( excludeMatches . Count , 1 ) ;
111+ Assert . AreEqual ( excludeMatches . Single ( ) . Groups . Count , 2 ) ;
112+ Assert . AreEqual ( excludeMatches . Single ( ) . Groups [ 1 ] . Value , osName ) ;
113+
114+ // There should be a single 'enabled: 1' match
115+ var enableRegex = new Regex ( "enabled: 1" ) ;
116+ var enableMatches = enableRegex . Matches ( output ) ;
117+ Assert . IsNotNull ( enableMatches ) ;
118+ Assert . AreEqual ( enableMatches . Count , 1 ) ;
119+
120+ StringAssert . Contains ( $ "- first:\n { platformName } : { osName } \n second:\n enabled: 1\n ", output ) ;
121+ }
122+
123+ [ TestCase ( UnityOs . Windows , new [ ] { "Win" , "Win64" } ) ]
124+ [ TestCase ( UnityOs . Linux , new [ ] { "Linux64" } ) ]
125+ [ TestCase ( UnityOs . OSX , new [ ] { "OSXUniversal" } ) ]
126+ public void GetMetaForDll_Editor ( UnityOs os , string [ ] osNames )
127+ {
128+ var platformDefs = PlatformDefinition . CreateAllPlatforms ( ) ;
129+ var pDef = platformDefs . Find ( os ) ;
130+ var output = UnityMeta . GetMetaForDll (
131+ Guid . NewGuid ( ) ,
132+ pDef ,
133+ Array . Empty < string > ( ) ,
134+ Array . Empty < string > ( ) ) ;
135+
136+ // There should be only 'Exclude Editor: 0' and 'Exclude {{ osName }}: 0' matches
137+ var excludeRegex = new Regex ( "Exclude (.*): 0" ) ;
138+ var excludeMatches = excludeRegex . Matches ( output ) ;
139+ Assert . IsNotNull ( excludeMatches ) ;
140+ var actualExcludes = excludeMatches
141+ . Select ( match => match . Groups [ 1 ] . Value )
142+ . ToHashSet ( ) ;
143+
144+ var expectedExcludes = osNames
145+ . Append ( "Editor" )
146+ . ToHashSet ( ) ;
147+ Assert . IsTrue ( actualExcludes . SetEquals ( expectedExcludes ) ) ;
148+
149+ // There should be as many 'enabled: 1' matches as exclude matches
150+ var enableRegex = new Regex ( "enabled: 1" ) ;
151+ var enableMatches = enableRegex . Matches ( output ) ;
152+ Assert . IsNotNull ( enableMatches ) ;
153+ Assert . AreEqual ( enableMatches . Count , excludeMatches . Count ) ;
154+
155+ foreach ( var osName in actualExcludes )
156+ {
157+ var platformName = ( osName == "Editor" ) ? osName : "Standalone" ;
158+ StringAssert . Contains ( $ "- first:\n { platformName } : { osName } \n second:\n enabled: 1\n ", output ) ;
159+ }
160+ }
69161 }
70162}
0 commit comments