This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios, macos] Added Swift MGLStyleValue tests
Added tests of MGLStyleValue written in Swift, along with bridging headers just in case they become needed in the future.
- Loading branch information
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import XCTest | ||
import Mapbox | ||
|
||
class MGLStyleValueTests: XCTestCase { | ||
func testConstantValues() { | ||
let geoJSONSource = MGLGeoJSONSource(identifier: "test", features: [], options: nil) | ||
let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "test", source: geoJSONSource) | ||
|
||
// Boolean | ||
symbolStyleLayer.iconAllowOverlap = MGLStyleConstantValue(rawValue: true) | ||
XCTAssertEqual((symbolStyleLayer.iconAllowOverlap as! MGLStyleConstantValue<NSNumber>).rawValue, true) | ||
|
||
// Number | ||
symbolStyleLayer.iconHaloWidth = MGLStyleConstantValue(rawValue: 3) | ||
XCTAssertEqual((symbolStyleLayer.iconHaloWidth as! MGLStyleConstantValue<NSNumber>).rawValue, 3) | ||
|
||
// String | ||
symbolStyleLayer.textField = MGLStyleConstantValue(rawValue: "{name}") | ||
XCTAssertEqual((symbolStyleLayer.textField as! MGLStyleConstantValue<NSString>).rawValue, "{name}") | ||
} | ||
|
||
func testFunctions() { | ||
let geoJSONSource = MGLGeoJSONSource(identifier: "test", features: [], options: nil) | ||
let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "test", source: geoJSONSource) | ||
|
||
// Boolean | ||
let stops: [NSNumber: MGLStyleValue<NSNumber>] = [ | ||
1: MGLStyleValue(rawValue: true), | ||
2: MGLStyleValue(rawValue: false), | ||
3: MGLStyleValue(rawValue: true), | ||
4: MGLStyleValue(rawValue: false), | ||
] | ||
symbolStyleLayer.iconAllowOverlap = MGLStyleFunction<NSNumber>(base: 1, stops: stops) | ||
XCTAssertEqual((symbolStyleLayer.iconAllowOverlap as! MGLStyleFunction<NSNumber>), MGLStyleFunction(base: 1, stops: stops)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// | ||
// Use this file to import your target's public headers that you would like to expose to Swift. | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// | ||
// Use this file to import your target's public headers that you would like to expose to Swift. | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12093c1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@1ec5 pardon my ignorance, but it's unclear why lines 2-4 are errors. What would be the proper way for declaring this:
Cannot assign value of type UIColor to type MGLStyleValue<UIColor>!
as MGLStyleAttributeValue!
was working in alpha.412093c1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dang, I'm blind.
12093c1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MGLStyleValue(rawValue: UIColor.orange)
also works. Feel free to chime in at #5970 with your feedback on the type system. It’s more complicated than you originally intuited because each property can be set to either a constant value or a function (MGLStyleFunction).