Skip to content

Commit a40341f

Browse files
committed
add test
1 parent cb28c35 commit a40341f

File tree

4 files changed

+120
-27
lines changed

4 files changed

+120
-27
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>StringKey</key>
6+
<dict>
7+
<key>NSStringLocalizedFormatKey</key>
8+
<string>%#@VARIABLE@</string>
9+
<key>VARIABLE</key>
10+
<dict>
11+
<key>NSStringFormatSpecTypeKey</key>
12+
<string>NSStringPluralRuleType</string>
13+
<key>NSStringFormatValueTypeKey</key>
14+
<string></string>
15+
<key>zero</key>
16+
<string></string>
17+
<key>one</key>
18+
<string></string>
19+
<key>two</key>
20+
<string></string>
21+
<key>few</key>
22+
<string></string>
23+
<key>many</key>
24+
<string></string>
25+
<key>other</key>
26+
<string></string>
27+
</dict>
28+
</dict>
29+
</dict>
30+
</plist>

Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
1E2A4D61E96521FF7123D7B0 /* XPC Service.xpc in CopyFiles */ = {isa = PBXBuildFile; fileRef = 22237B8EBD9E6BE8EBC8735F /* XPC Service.xpc */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4444
1E457F55331FD2C3E8E00BE2 /* Result.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 0C5AC2545AE4D4F7F44E2E9B /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4545
1F9168A43FD8E2FCC2699E14 /* Documentation.docc in Sources */ = {isa = PBXBuildFile; fileRef = B5C943D39DD7812CAB94B614 /* Documentation.docc */; settings = {COMPILER_FLAGS = "-Werror"; }; };
46+
20B51B15FDAA4B296642DB9D /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = E8222828982682ACB6942EC9 /* Localizable.stringsdict */; };
4647
210B49C23B9717C668B40C8C /* FrameworkFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5F527F2590C14956518174 /* FrameworkFile.swift */; };
4748
2116F89CF5A04EA0EFA30A89 /* TestProjectUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D88C6BF7355702B74396791 /* TestProjectUITests.swift */; };
4849
212BCB51DAF3212993DDD49E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D51CC8BCCBD68A90E90A3207 /* Assets.xcassets */; };
@@ -87,6 +88,7 @@
8788
58C18019E71E372F635A3FB4 /* MoreUnder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA8718C7CD3BE86D9B1F5120 /* MoreUnder.swift */; };
8889
5D10822B0E7C33DD6979F656 /* Standalone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F5BD97AF0F94A15A5B7DDB7 /* Standalone.swift */; };
8990
5E0369B907E239D1E6884ECF /* TestFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E43116070AFEF5D8C3A5A957 /* TestFramework.framework */; };
91+
5E13975282BB84D5C33727B8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2FC2A8A829CE71B1CF415FF7 /* Main.storyboard */; };
9092
61401517ECCEB2362582B5DA /* libEndpointSecurity.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 0BC75409252FF15F540FBB7B /* libEndpointSecurity.tbd */; };
9193
61516CAC12B2843FBC4572E6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 59DA55A04FA2366B5D0BEEFF /* Assets.xcassets */; };
9294
61601545B6BE00CA74A4E38F /* SceneKitCatalog.scnassets in Resources */ = {isa = PBXBuildFile; fileRef = C9E358FBE2B54D2B5C7FD609 /* SceneKitCatalog.scnassets */; };
@@ -157,6 +159,7 @@
157159
CCA17097382757012B58C17C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1BC32A813B80A53962A1F365 /* Assets.xcassets */; };
158160
D5458D67C3596943114C3205 /* Standalone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F5BD97AF0F94A15A5B7DDB7 /* Standalone.swift */; };
159161
D61BEABD5B26B2DE67D0C2EC /* FrameworkFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5F527F2590C14956518174 /* FrameworkFile.swift */; };
162+
D6312C8EBF458001D43FBDC2 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = E8222828982682ACB6942EC9 /* Localizable.stringsdict */; };
160163
D8ED40ED61AD912385CFF5F0 /* StaticLibrary_ObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D0C79A8C750EC0DE748C463 /* StaticLibrary_ObjC.m */; };
161164
DD5FBFC3C1B2DB3D0D1CF210 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B785B1161553A7DD6DA4255 /* NetworkExtension.framework */; };
162165
E0B27599D701E6BB0223D0A8 /* FilterDataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16AA52945B70B1BF9E246350 /* FilterDataProvider.swift */; };
@@ -798,6 +801,7 @@
798801
E43116070AFEF5D8C3A5A957 /* TestFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TestFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; };
799802
E55F45EACB0F382722D61C8D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
800803
E5E0A80CCE8F8DB662DCD2D0 /* EndpointSecuritySystemExtension.systemextension */ = {isa = PBXFileReference; explicitFileType = "wrapper.system-extension"; includeInIndex = 0; path = EndpointSecuritySystemExtension.systemextension; sourceTree = BUILT_PRODUCTS_DIR; };
804+
E9182F7632482B8412DC5AE0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
801805
E9672EF8FE1DDC8DE0705129 /* PushNotificationPayload.apns */ = {isa = PBXFileReference; lastKnownFileType = text; path = PushNotificationPayload.apns; sourceTree = "<group>"; };
802806
EDCC70978B8AD49373DA0DE0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
803807
EE1343F2238429D4DA9D830B /* File1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = File1.swift; path = Group/File1.swift; sourceTree = "<group>"; };
@@ -1342,6 +1346,7 @@
13421346
1FA5E208EC184E3030D2A21D /* Clip.entitlements */,
13431347
6F165CDD5BCC13AFF50B65E2 /* Info.plist */,
13441348
79325B44B19B83EC6CEDBCC5 /* LaunchScreen.storyboard */,
1349+
E8222828982682ACB6942EC9 /* Localizable.stringsdict */,
13451350
2FC2A8A829CE71B1CF415FF7 /* Main.storyboard */,
13461351
DFE6A6FAAFF701FE729293DE /* ViewController.swift */,
13471352
);
@@ -1941,6 +1946,7 @@
19411946
buildConfigurationList = 129D9E77D45A66B1C78578F2 /* Build configuration list for PBXNativeTarget "App_Clip_UITests" */;
19421947
buildPhases = (
19431948
2E1429F0FB524A2BCFC61DF1 /* Sources */,
1949+
78249BAE6D3EE80459CF1FA9 /* Resources */,
19441950
05D615CB74F875917AA8C9B0 /* Embed Frameworks */,
19451951
);
19461952
buildRules = (
@@ -2306,6 +2312,14 @@
23062312
);
23072313
runOnlyForDeploymentPostprocessing = 0;
23082314
};
2315+
78249BAE6D3EE80459CF1FA9 /* Resources */ = {
2316+
isa = PBXResourcesBuildPhase;
2317+
buildActionMask = 2147483647;
2318+
files = (
2319+
D6312C8EBF458001D43FBDC2 /* Localizable.stringsdict in Resources */,
2320+
);
2321+
runOnlyForDeploymentPostprocessing = 0;
2322+
};
23092323
8508BA1B733839E314AF2853 /* Resources */ = {
23102324
isa = PBXResourcesBuildPhase;
23112325
buildActionMask = 2147483647;
@@ -2317,6 +2331,7 @@
23172331
E5DD0AD6F7AE1DD4AF98B83E /* Localizable.stringsdict in Resources */,
23182332
2A7EB1A9A365A7EC5D49AFCF /* LocalizedStoryboard.storyboard in Resources */,
23192333
49A4B8937BB5520B36EA33F0 /* Main.storyboard in Resources */,
2334+
5E13975282BB84D5C33727B8 /* Main.storyboard in Resources */,
23202335
900CFAD929CAEE3861127627 /* MyBundle.bundle in Resources */,
23212336
C88598A49087A212990F4E8B /* ResourceFolder in Resources */,
23222337
61601545B6BE00CA74A4E38F /* SceneKitCatalog.scnassets in Resources */,
@@ -2341,6 +2356,7 @@
23412356
files = (
23422357
61516CAC12B2843FBC4572E6 /* Assets.xcassets in Resources */,
23432358
B18C121B0A4D43ED8149D8E2 /* LaunchScreen.storyboard in Resources */,
2359+
20B51B15FDAA4B296642DB9D /* Localizable.stringsdict in Resources */,
23442360
0F99AECCB4691803C791CDCE /* Main.storyboard in Resources */,
23452361
);
23462362
runOnlyForDeploymentPostprocessing = 0;
@@ -3081,6 +3097,14 @@
30813097
name = LaunchScreen.storyboard;
30823098
sourceTree = "<group>";
30833099
};
3100+
E8222828982682ACB6942EC9 /* Localizable.stringsdict */ = {
3101+
isa = PBXVariantGroup;
3102+
children = (
3103+
E9182F7632482B8412DC5AE0 /* en */,
3104+
);
3105+
name = Localizable.stringsdict;
3106+
sourceTree = "<group>";
3107+
};
30843108
/* End PBXVariantGroup section */
30853109

30863110
/* Begin XCBuildConfiguration section */

Tests/Fixtures/TestProject/project.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ targets:
121121
resourceTags:
122122
- tag1
123123
- tag2
124+
- path: App_Clip/Base.lproj/Main.storyboard
124125
settings:
125126
INFOPLIST_FILE: App_iOS/Info.plist
126127
PRODUCT_BUNDLE_IDENTIFIER: com.project.app
@@ -390,7 +391,9 @@ targets:
390391
App_Clip_UITests:
391392
type: bundle.ui-testing
392393
platform: iOS
393-
sources: App_Clip_UITests
394+
sources:
395+
- path: App_Clip_UITests
396+
- path: App_Clip/en.lproj/Localizable.stringsdict
394397
dependencies:
395398
- target: App_Clip
396399
# https://github.com/yonaskolb/XcodeGen/issues/1232

Tests/XcodeGenKitTests/SourceGeneratorTests.swift

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -143,41 +143,77 @@ class SourceGeneratorTests: XCTestCase {
143143
let directories = """
144144
Sources:
145145
Base.lproj:
146+
- LocalizedXib.xib
146147
- LocalizedStoryboard.storyboard
148+
- IntentDefinition.intentdefinition
149+
- BaseLocalizable.strings
147150
en.lproj:
151+
- LocalizedXib.strings
148152
- LocalizedStoryboard.strings
153+
- IntentDefinition.strings
154+
- BaseLocalizable.strings
155+
- Localizable.strings
156+
ja.lproj:
157+
- LocalizedXib.strings
158+
- LocalizedStoryboard.strings
159+
- IntentDefinition.strings
160+
- BaseLocalizable.strings
161+
- Localizable.strings
149162
"""
150163
try createDirectories(directories)
151164

152165
let target = Target(name: "Test", type: .application, platform: .iOS, sources: ["Sources"])
153-
let project = Project(basePath: directoryPath, name: "Test", targets: [target])
166+
let project = Project(basePath: directoryPath, name: "Test", targets: [target], options: SpecOptions(developmentLanguage: "en"))
154167

155168
let pbxProj = try project.generatePbxProj()
156-
157-
func getFileReferences(_ path: String) -> [PBXFileReference] {
158-
pbxProj.fileReferences.filter { $0.path == path }
159-
}
160-
161-
func getVariableGroups(_ name: String?) -> [PBXVariantGroup] {
162-
pbxProj.variantGroups.filter { $0.name == name }
163-
}
164-
165-
let resourceName = "LocalizedStoryboard.storyboard"
166-
let baseResource = "Base.lproj/LocalizedStoryboard.storyboard"
167-
let localizedResource = "en.lproj/LocalizedStoryboard.strings"
168-
169-
let variableGroup = try unwrap(getVariableGroups(resourceName).first)
170-
171-
do {
172-
let refs = getFileReferences(baseResource)
173-
try expect(refs.count) == 1
174-
try expect(variableGroup.children.filter { $0 == refs.first }.count) == 1
175-
}
176-
177-
do {
178-
let refs = getFileReferences(localizedResource)
179-
try expect(refs.count) == 1
180-
try expect(variableGroup.children.filter { $0 == refs.first }.count) == 1
169+
170+
let resourceList: [(name: String, basePath: String, localizedResources: [String])] = [
171+
// resouce is stored in base localized directory
172+
(
173+
name: "LocalizedXib.xib",
174+
basePath: "Base.lproj/LocalizedXib.xib",
175+
localizedResources: ["en.lproj/LocalizedXib.strings", "ja.lproj/LocalizedXib.strings"]
176+
),
177+
(
178+
name: "LocalizedStoryboard.storyboard",
179+
basePath: "Base.lproj/LocalizedStoryboard.storyboard",
180+
localizedResources: ["en.lproj/LocalizedStoryboard.strings", "ja.lproj/LocalizedStoryboard.strings"]
181+
),
182+
(
183+
name: "IntentDefinition.intentdefinition",
184+
basePath: "Base.lproj/IntentDefinition.intentdefinition",
185+
localizedResources: ["en.lproj/IntentDefinition.strings", "ja.lproj/IntentDefinition.strings"]
186+
),
187+
(
188+
name: "BaseLocalizable.strings",
189+
basePath: "Base.lproj/BaseLocalizable.strings",
190+
localizedResources: ["en.lproj/BaseLocalizable.strings", "ja.lproj/BaseLocalizable.strings"]
191+
),
192+
// resouce is not stored in base localized directory
193+
(
194+
name: "Localizable.strings",
195+
basePath: "en.lproj/Localizable.strings",
196+
localizedResources: ["ja.lproj/Localizable.strings"]
197+
)
198+
]
199+
200+
try resourceList.forEach { resource in
201+
202+
let variableGroup = try unwrap(pbxProj.variantGroups.filter { $0.name == resource.name }.first)
203+
204+
do {
205+
let refs = pbxProj.fileReferences.filter { $0.path == resource.basePath }
206+
try expect(refs.count) == 1
207+
try expect(variableGroup.children.filter { $0 == refs.first }.count) == 1
208+
}
209+
210+
try resource.localizedResources.forEach { localizedResource in
211+
do {
212+
let refs = pbxProj.fileReferences.filter { $0.path == localizedResource }
213+
try expect(refs.count) == 1
214+
try expect(variableGroup.children.filter { $0 == refs.first }.count) == 1
215+
}
216+
}
181217
}
182218
}
183219

0 commit comments

Comments
 (0)