Skip to content

Commit bf9c5a6

Browse files
committed
[Xcodeproj] Match Xcode's c99names
1 parent 827b703 commit bf9c5a6

File tree

8 files changed

+65
-6
lines changed

8 files changed

+65
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import PackageDescription
2+
3+
let package = Package(
4+
name: "PackageWithNonc99NameModules",
5+
targets: [
6+
Target(name: "A-B", dependencies: ["B-C"])]
7+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import B_C
2+
3+
func ab() {
4+
bc()
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public func bc() {
2+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import ModuleName1
1+
import Module_Name_1
22

33
public class Foo {
44
var bar: Int = 0
5-
}
5+
}

Sources/PackageType/c99name().swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Removes characters from name that are invalid in C99 module-names.
1313
*/
1414
public func c99name(name: String) throws -> String {
15-
var mapped = name.unicodeScalars.filter {
15+
var mapped: [UnicodeScalar] = name.unicodeScalars.map {
1616
switch $0.value {
1717
case// a-z A-Z 0-9 _
1818
65...90, 97...122, 48...57, 95,
@@ -178,9 +178,9 @@ public func c99name(name: String) throws -> String {
178178
0x4E00...0x9FA5,
179179
// Hangul,
180180
0xAC00...0xD7A3:
181-
return true
181+
return $0
182182
default:
183-
return false
183+
return "_"
184184
}
185185
}
186186

Tests/Functional/MiscellaneousTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class MiscellaneousTestCase: XCTestCase {
369369
func testSpaces() {
370370
fixture(name: "Miscellaneous/Spaces Fixture") { prefix in
371371
XCTAssertBuilds(prefix)
372-
XCTAssertFileExists(prefix, ".build/debug/ModuleName1.build/Foo.swift.o")
372+
XCTAssertFileExists(prefix, ".build/debug/Module_Name_1.build/Foo.swift.o")
373373
}
374374
}
375375
}

Tests/PackageType/c99nameTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
@testable import PackageType
12+
import XCTest
13+
14+
class c99nameTests: XCTestCase {
15+
func testSimpleName() {
16+
let name = assertc99Name("foo")
17+
XCTAssertEqual(name, "foo")
18+
}
19+
20+
func testNameWithInvalidCharacter() {
21+
let name = assertc99Name("foo-bar")
22+
XCTAssertEqual(name, "foo_bar")
23+
}
24+
}
25+
26+
func assertc99Name(_ name: String) -> String {
27+
do {
28+
return try c99name(name: name)
29+
} catch {
30+
XCTFail("Couldn't find the c99name: \(error)")
31+
fatalError()
32+
}
33+
}

Tests/Xcodeproj/FunctionalTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ class FunctionalTests: XCTestCase {
7878
XCTAssertFileExists(moduleUser, "build", "Debug", "SystemModuleUser")
7979
}
8080
}
81+
82+
func testModuleNamesWithNonC99Names() {
83+
fixture(name: "Miscellaneous/PackageWithNonc99NameModules") { prefix in
84+
XCTAssertXcodeprojGen(prefix)
85+
let pbx = Path.join(prefix, "PackageWithNonc99NameModules.xcodeproj")
86+
XCTAssertDirectoryExists(pbx)
87+
XCTAssertXcodeBuild(project: pbx)
88+
let build = Path.join(prefix, "build", "Debug")
89+
XCTAssertFileExists(build, "libA-B.dylib")
90+
XCTAssertFileExists(build, "libB-C.dylib")
91+
}
92+
}
8193
}
8294

8395
func write(path: String, write: (OutputByteStream) -> Void) throws -> String {

0 commit comments

Comments
 (0)