Skip to content

Commit

Permalink
Fixed multiplatform build and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Oct 9, 2020
1 parent 01b3475 commit 159e17c
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 66 deletions.
2 changes: 0 additions & 2 deletions Sources/OTCore/Clipboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public func SetClipboard(toString: String) -> Bool {
return true
#else
fatalError("setClipboard: Not implemented on this platform yet.")
return false
#endif
}

Expand All @@ -41,7 +40,6 @@ public func GetClipboardString() -> String? {
return UIPasteboard.general.string
#else
fatalError("getClipboardString: Not implemented on this platform yet.")
return false
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/OTCore/Swift Extensions/FloatingPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ extension Float: FloatingPointPower {
}
}

#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
extension Float80: FloatingPointPower {
/// OTCore:
/// Convenience method for pow()
Expand Down Expand Up @@ -325,7 +325,7 @@ extension StringProtocol {
/// OTCore: Convenience method to return a Float
public var float: Float? { Float(self) }

#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
/// OTCore: Convenience method to return a Float80
public var float80: Float80? { Float80(self) }
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/OTCore/Swift Extensions/Integers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension BinaryInteger {
/// OTCore: Convenience method to return a Float32
public var float32: Float32 { return Float32(self) }

#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
/// OTCore: Convenience method to return a Float80
public var float80: Float80 { return Float80(self) }
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/OTCore/Swift Extensions/Pasteboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension NSPasteboard.PasteboardType {
/// Can use in place of `.fileURL` when building for platforms earlier than macOS 10.13.
public static var fileURLBackCompat: Self {

if #available(OSX 10.13, *) {
if #available(macOS 10.13, *) {
return .fileURL

} else {
Expand Down
7 changes: 5 additions & 2 deletions Sources/OTCore/Swift Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,13 @@ extension String {

/// OTCore:
/// Returns a representation of the string in title case style, ie: "What to Capitalize in a Title" (English only)
@available(OSX 10.11, *)
@available(macOS 10.11, *)
public var titleCased: String {

var words = self.localizedCapitalized.split(separator: " ").map({ String($0) })
var words =
self.localizedCapitalized
.split(separator: " ")
.map({ String($0) })

// only process if there are more than 2 words
if words.count > 2 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OTCore/Swift Extensions/URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ extension FileManager {
/// Backwards compatible method for retrieving a temporary folder from the system.
public static var temporaryDirectoryCompat: URL {

if #available(OSX 10.12, iOS 10.0, *) {
if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
return FileManager.default.temporaryDirectory
} else {
return URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
Expand Down
84 changes: 84 additions & 0 deletions Tests/OTCoreTests/Swift Extensions/Data Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Extensions_Data_Tests: XCTestCase {

// Int is 32-bit on 32-bit systems, 64-bit on 64-bit systems

#if !(arch(arm) || arch(i386))

// .toData

XCTAssertEqual(0b1.int.toData(.littleEndian) , Data([0b1,0,0,0,0,0,0,0]))
Expand All @@ -37,11 +39,13 @@ class Extensions_Data_Tests: XCTestCase {
XCTAssertEqual(Data([1,2,3,4,5,6,7]) .toInt(), nil) // underflow
XCTAssertEqual(Data([1,2,3,4,5,6,7,8,9]).toInt(), nil) // overflow


XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toInt(from: .littleEndian),
0b00001000_00000111_00000110_00000101_00000100_00000011_00000010_00000001)
XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toInt(from: .bigEndian),
0b00000001_00000010_00000011_00000100_00000101_00000110_00000111_00001000)


// both ways
XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toInt()? .toData() , Data([1,2,3,4,5,6,7,8]))

Expand All @@ -51,6 +55,43 @@ class Extensions_Data_Tests: XCTestCase {
XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toInt(from: .littleEndian)?.toData(.bigEndian) , Data([8,7,6,5,4,3,2,1]))
XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toInt(from: .bigEndian)? .toData(.littleEndian) , Data([8,7,6,5,4,3,2,1]))

#elseif (arch(arm) || arch(i386))

// .toData

XCTAssertEqual(0b1.int.toData(.littleEndian) , Data([0b1,0,0,0]))
XCTAssertEqual(0b1.int.toData(.bigEndian) , Data([0,0,0,0b1]))

// .toInt64

XCTAssertEqual(Data([]) .toInt(), nil) // underflow
XCTAssertEqual(Data([1]) .toInt(), nil) // underflow
XCTAssertEqual(Data([1,2]) .toInt(), nil) // underflow
XCTAssertEqual(Data([1,2,3]) .toInt(), nil) // underflow
XCTAssertEqual(Data([1,2,3,4,5]).toInt(), nil) // overflow


XCTAssertEqual(Data([1,2,3,4]) .toInt(from: .littleEndian),
0b00000100_00000011_00000010_00000001)
XCTAssertEqual(Data([1,2,3,4]) .toInt(from: .bigEndian),
0b00000001_00000010_00000011_00000100)


// both ways
XCTAssertEqual(Data([1,2,3,4]) .toInt()? .toData() , Data([1,2,3,4]))

XCTAssertEqual(Data([1,2,3,4]) .toInt(from: .littleEndian)?.toData(.littleEndian) , Data([1,2,3,4]))
XCTAssertEqual(Data([1,2,3,4]) .toInt(from: .bigEndian)? .toData(.bigEndian) , Data([1,2,3,4]))

XCTAssertEqual(Data([1,2,3,4]) .toInt(from: .littleEndian)?.toData(.bigEndian) , Data([4,3,2,1]))
XCTAssertEqual(Data([1,2,3,4]) .toInt(from: .bigEndian)? .toData(.littleEndian) , Data([4,3,2,1]))

#else

XCTFail("Platform not supported yet.")

#endif

}

func testInt8() {
Expand Down Expand Up @@ -174,6 +215,10 @@ class Extensions_Data_Tests: XCTestCase {

func testUInt() {

// UInt is 32-bit on 32-bit systems, 64-bit on 64-bit systems

#if !(arch(arm) || arch(i386))

// .toData

XCTAssertEqual(0b1.uint.toData(.littleEndian) , Data([0b1,0,0,0,0,0,0,0]))
Expand All @@ -191,11 +236,13 @@ class Extensions_Data_Tests: XCTestCase {
XCTAssertEqual(Data([1,2,3,4,5,6,7]) .toUInt(), nil) // underflow
XCTAssertEqual(Data([1,2,3,4,5,6,7,8,9]).toUInt(), nil) // overflow


XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toUInt(from: .littleEndian),
0b00001000_00000111_00000110_00000101_00000100_00000011_00000010_00000001)
XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toUInt(from: .bigEndian),
0b00000001_00000010_00000011_00000100_00000101_00000110_00000111_00001000)


// both ways
XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toUInt()? .toData() , Data([1,2,3,4,5,6,7,8]))

Expand All @@ -205,6 +252,43 @@ class Extensions_Data_Tests: XCTestCase {
XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toUInt(from: .littleEndian)?.toData(.bigEndian) , Data([8,7,6,5,4,3,2,1]))
XCTAssertEqual(Data([1,2,3,4,5,6,7,8]) .toUInt(from: .bigEndian)? .toData(.littleEndian) , Data([8,7,6,5,4,3,2,1]))

#elseif (arch(arm) || arch(i386))

// .toData

XCTAssertEqual(0b1.uint.toData(.littleEndian) , Data([0b1,0,0,0]))
XCTAssertEqual(0b1.uint.toData(.bigEndian) , Data([0,0,0,0b1]))

// .toUInt

XCTAssertEqual(Data([]) .toUInt(), nil) // underflow
XCTAssertEqual(Data([1]) .toUInt(), nil) // underflow
XCTAssertEqual(Data([1,2]) .toUInt(), nil) // underflow
XCTAssertEqual(Data([1,2,3]) .toUInt(), nil) // underflow
XCTAssertEqual(Data([1,2,3,4,5]).toUInt(), nil) // overflow


XCTAssertEqual(Data([1,2,3,4]) .toUInt(from: .littleEndian),
0b00000100_00000011_00000010_00000001)
XCTAssertEqual(Data([1,2,3,4]) .toUInt(from: .bigEndian),
0b00000001_00000010_00000011_00000100)


// both ways
XCTAssertEqual(Data([1,2,3,4]) .toUInt()? .toData() , Data([1,2,3,4]))

XCTAssertEqual(Data([1,2,3,4]) .toUInt(from: .littleEndian)?.toData(.littleEndian) , Data([1,2,3,4]))
XCTAssertEqual(Data([1,2,3,4]) .toUInt(from: .bigEndian)? .toData(.bigEndian) , Data([1,2,3,4]))

XCTAssertEqual(Data([1,2,3,4]) .toUInt(from: .littleEndian)?.toData(.bigEndian) , Data([4,3,2,1]))
XCTAssertEqual(Data([1,2,3,4]) .toUInt(from: .bigEndian)? .toData(.littleEndian) , Data([4,3,2,1]))

#else

XCTFail("Platform not supported yet.")

#endif

}

func testUInt8() {
Expand Down
12 changes: 6 additions & 6 deletions Tests/OTCoreTests/Swift Extensions/FloatingPoint Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Extensions_FloatingPoint_Tests: XCTestCase {

// Float80

#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM

let float80 = Float80(123.456)

Expand Down Expand Up @@ -158,7 +158,7 @@ class Extensions_FloatingPoint_Tests: XCTestCase {
b = 0.0.boolValue
b = Float(1).boolValue

#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
b = Float80(1).boolValue
#endif

Expand All @@ -177,7 +177,7 @@ class Extensions_FloatingPoint_Tests: XCTestCase {

XCTAssertEqual( 2.0.power(3) , 8.0) // Double
XCTAssertEqual( Float(2.0).power(3) , 8.0)
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
XCTAssertEqual(Float80(2.0).power(3) , 8.0)
#endif
XCTAssertEqual(CGFloat(2.0).power(3) , 8.0)
Expand Down Expand Up @@ -307,7 +307,7 @@ class Extensions_FloatingPoint_Tests: XCTestCase {
str = 0.0.string
str = Float(1).string

#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
str = Float80(1).string
#endif

Expand All @@ -317,7 +317,7 @@ class Extensions_FloatingPoint_Tests: XCTestCase {

XCTAssertEqual( Float(1).string, "1.0")

#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
XCTAssertEqual(Float80(1).string, "1.0")
#endif

Expand All @@ -331,7 +331,7 @@ class Extensions_FloatingPoint_Tests: XCTestCase {
XCTAssertEqual("1.0".double, 1.0)
XCTAssertEqual("1.0".float, 1.0)

#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
XCTAssertEqual("1.0".float80, 1.0)
#endif

Expand Down
20 changes: 10 additions & 10 deletions Tests/OTCoreTests/Swift Extensions/Integers Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = 1.double
_ = 1.float
_ = 1.float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = 1.float80
#endif
_ = 1.cgFloat
Expand All @@ -54,7 +54,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = UInt(1).double
_ = UInt(1).float
_ = UInt(1).float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = UInt(1).float80
#endif
_ = UInt(1).cgFloat
Expand All @@ -76,7 +76,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = Int8(1).double
_ = Int8(1).float
_ = Int8(1).float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = Int8(1).float80
#endif
_ = Int8(1).cgFloat
Expand All @@ -98,7 +98,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = UInt8(1).double
_ = UInt8(1).float
_ = UInt8(1).float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = UInt8(1).float80
#endif
_ = UInt8(1).cgFloat
Expand All @@ -120,7 +120,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = Int16(1).double
_ = Int16(1).float
_ = Int16(1).float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = Int16(1).float80
#endif
_ = Int16(1).cgFloat
Expand All @@ -142,7 +142,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = UInt16(1).double
_ = UInt16(1).float
_ = UInt16(1).float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = UInt16(1).float80
#endif
_ = UInt16(1).cgFloat
Expand All @@ -164,7 +164,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = Int32(1).double
_ = Int32(1).float
_ = Int32(1).float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = Int32(1).float80
#endif
_ = Int32(1).cgFloat
Expand All @@ -186,7 +186,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = UInt32(1).double
_ = UInt32(1).float
_ = UInt32(1).float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = UInt32(1).float80
#endif
_ = UInt32(1).cgFloat
Expand All @@ -208,7 +208,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = Int64(1).double
_ = Int64(1).float
_ = Int64(1).float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = Int64(1).float80
#endif
_ = Int64(1).cgFloat
Expand All @@ -230,7 +230,7 @@ class Extensions_Integers_Tests: XCTestCase {
_ = UInt64(1).double
_ = UInt64(1).float
_ = UInt64(1).float32
#if !arch(arm64) // Float80 is removed for ARM64
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
_ = UInt64(1).float80
#endif
_ = UInt64(1).cgFloat
Expand Down
2 changes: 1 addition & 1 deletion Tests/OTCoreTests/Swift Extensions/Operators Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Extensions_Operators_Tests: XCTestCase {
XCTAssertEqual( 43.0 % 10.0, 3.0)
XCTAssertEqual( Float(43.0) % 10.0, 3.0)

#if !arch(arm64)
#if !(arch(arm64) || arch(arm)) // Float80 is now removed for ARM
XCTAssertEqual(Float80(43.0) % 10.0, 3.0)
#endif

Expand Down
Loading

0 comments on commit 159e17c

Please sign in to comment.