Skip to content

Commit bd30bdc

Browse files
committed
Avoid overflowing MBPlacemarkScope values
Also added tests to ensure that the raw values and descriptions of this enumeration are correct.
1 parent e668e4f commit bd30bdc

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

MapboxGeocoder.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
DA2E03F21CB0FE0200D1269A /* MBRectangularRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2E03F11CB0FE0200D1269A /* MBRectangularRegion.swift */; };
2121
DA2EC05C1CED72E900D4BA5D /* MBPlacemarkScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2EC05B1CED72E900D4BA5D /* MBPlacemarkScope.swift */; };
2222
DA2EC05E1CED732F00D4BA5D /* MBGeocodeOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2EC05D1CED732F00D4BA5D /* MBGeocodeOptions.swift */; };
23+
DA4D90071DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */; };
24+
DA4D90081DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */; };
25+
DA4D90091DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */; };
2326
DA5170AD1CF1B1DB00CD6DCF /* MapboxGeocoder.h in Headers */ = {isa = PBXBuildFile; fileRef = DDC229581A36073B006BE405 /* MapboxGeocoder.h */; settings = {ATTRIBUTES = (Public, ); }; };
2427
DA5170AE1CF1B1E000CD6DCF /* MBGeocodeOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2EC05D1CED732F00D4BA5D /* MBGeocodeOptions.swift */; };
2528
DA5170AF1CF1B1E000CD6DCF /* MBGeocoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC229591A36073B006BE405 /* MBGeocoder.swift */; };
@@ -171,6 +174,7 @@
171174
DA2E03F11CB0FE0200D1269A /* MBRectangularRegion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBRectangularRegion.swift; sourceTree = "<group>"; };
172175
DA2EC05B1CED72E900D4BA5D /* MBPlacemarkScope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBPlacemarkScope.swift; sourceTree = "<group>"; };
173176
DA2EC05D1CED732F00D4BA5D /* MBGeocodeOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBGeocodeOptions.swift; sourceTree = "<group>"; };
177+
DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlacemarkScopeTests.swift; sourceTree = "<group>"; };
174178
DA5170961CF1B18F00CD6DCF /* MapboxGeocoder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MapboxGeocoder.framework; sourceTree = BUILT_PRODUCTS_DIR; };
175179
DA51709F1CF1B18F00CD6DCF /* MapboxGeocoderTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MapboxGeocoderTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
176180
DA5170C11CF253EE00CD6DCF /* MapboxGeocoder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MapboxGeocoder.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -402,6 +406,7 @@
402406
DA701C001CB1292C00B0E520 /* GeocoderTests.swift */,
403407
DA210BAA1CB4BE73008088FD /* ForwardGeocodingTests.swift */,
404408
DDF1E84C1BD6F7BA00C40C78 /* ReverseGeocodingTests.swift */,
409+
DA4D90061DD63AEC006EC71A /* PlacemarkScopeTests.swift */,
405410
DDF1E84E1BD6F7BA00C40C78 /* Info.plist */,
406411
DDF1E8571BD700EB00C40C78 /* Fixtures */,
407412
);
@@ -1043,6 +1048,7 @@
10431048
buildActionMask = 2147483647;
10441049
files = (
10451050
DA5170B61CF1B1EF00CD6DCF /* ReverseGeocodingTests.swift in Sources */,
1051+
DA4D90081DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */,
10461052
DA5170B41CF1B1EF00CD6DCF /* GeocoderTests.swift in Sources */,
10471053
DA5170B51CF1B1EF00CD6DCF /* ForwardGeocodingTests.swift in Sources */,
10481054
);
@@ -1065,6 +1071,7 @@
10651071
buildActionMask = 2147483647;
10661072
files = (
10671073
DA5170E11CF2542800CD6DCF /* ReverseGeocodingTests.swift in Sources */,
1074+
DA4D90091DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */,
10681075
DA5170DF1CF2542800CD6DCF /* GeocoderTests.swift in Sources */,
10691076
DA5170E01CF2542800CD6DCF /* ForwardGeocodingTests.swift in Sources */,
10701077
);
@@ -1118,6 +1125,7 @@
11181125
buildActionMask = 2147483647;
11191126
files = (
11201127
DDF1E84D1BD6F7BA00C40C78 /* ReverseGeocodingTests.swift in Sources */,
1128+
DA4D90071DD63AEC006EC71A /* PlacemarkScopeTests.swift in Sources */,
11211129
DA210BAB1CB4BE73008088FD /* ForwardGeocodingTests.swift in Sources */,
11221130
DA701C011CB1292C00B0E520 /* GeocoderTests.swift in Sources */,
11231131
);

MapboxGeocoder/MBPlacemarkScope.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef NS_OPTIONS(NSUInteger, MBPlacemarkScope) {
2424
MBPlacemarkScopeAddress = (1 << 8),
2525

2626
/// A particularly notable or long-lived point of interest, such as a park, museum, or place of worship.
27-
MBPlacemarkScopeLandmark = (1 << 91),
27+
MBPlacemarkScopeLandmark = (1 << 10),
2828
/// A point of interest, such as a business or store.
2929
MBPlacemarkScopePointOfInterest = MBPlacemarkScopeLandmark | (1 << 9),
3030

MapboxGeocoder/MBPlacemarkScope.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ extension PlacemarkScope: CustomStringConvertible {
6262
if contains(.Address) {
6363
descriptions.append("address")
6464
}
65-
6665
if contains(.Landmark) {
67-
descriptions.append("poi.landmark")
68-
} else if contains(.PointOfInterest) {
69-
descriptions.append("poi")
66+
descriptions.append(contains(.PointOfInterest) ? "poi" : "poi.landmark")
7067
}
7168
return descriptions.joinWithSeparator(",")
7269
}

MapboxGeocoderTests/ForwardGeocodingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class ForwardGeocodingTests: XCTestCase {
8181
options.allowedScopes = [.Region, .Place, .Locality, .PointOfInterest]
8282
options.allowedISOCountryCodes = ["NC"]
8383
let task = geocoder.geocode(options: options) { (placemarks, attribution, error) in
84-
XCTAssertNil(placemarks?.count, "forward geocode should return no results for invalid query")
85-
XCTAssertNil(attribution)
84+
XCTAssertEqual(placemarks?.count, 0, "forward geocode should return no results for invalid query")
85+
XCTAssertEqual(attribution, "NOTICE: © 2016 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained.")
8686

8787
expection.fulfill()
8888
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import XCTest
2+
import MapboxGeocoder
3+
4+
class PlacemarkScopeTests: XCTestCase {
5+
func testContainment() {
6+
XCTAssert(PlacemarkScope.All.contains(.Country))
7+
XCTAssert(PlacemarkScope.All.contains(.Region))
8+
XCTAssert(PlacemarkScope.All.contains(.District))
9+
XCTAssert(PlacemarkScope.All.contains(.PostalCode))
10+
XCTAssert(PlacemarkScope.All.contains(.Place))
11+
XCTAssert(PlacemarkScope.All.contains(.Locality))
12+
XCTAssert(PlacemarkScope.All.contains(.Neighborhood))
13+
XCTAssert(PlacemarkScope.All.contains(.Address))
14+
XCTAssert(PlacemarkScope.PointOfInterest.contains(.Landmark))
15+
XCTAssert(PlacemarkScope.All.contains(.PointOfInterest))
16+
17+
XCTAssertEqual(PlacemarkScope.All.description.componentsSeparatedByString(",").count, 9, "testContainment() needs to be updated.")
18+
19+
XCTAssertLessThanOrEqual(PlacemarkScope.All.rawValue, PlacemarkScope.RawValue.max)
20+
XCTAssertLessThanOrEqual(PlacemarkScope(descriptions: PlacemarkScope.All.description.componentsSeparatedByString(","))?.rawValue ?? .max, PlacemarkScope.All.rawValue)
21+
}
22+
23+
func testDescriptions() {
24+
XCTAssertNil(PlacemarkScope(descriptions: ["neighbourhood"]))
25+
XCTAssertEqual(PlacemarkScope(descriptions: PlacemarkScope.All.description.componentsSeparatedByString(","))?.description, PlacemarkScope.All.description)
26+
27+
XCTAssertEqual(PlacemarkScope(descriptions: ["poi"]), .PointOfInterest)
28+
XCTAssertEqual(PlacemarkScope(descriptions: ["poi.landmark"]), .Landmark)
29+
XCTAssertEqual(PlacemarkScope(descriptions: ["poi", "poi.landmark"]), .PointOfInterest)
30+
}
31+
}

0 commit comments

Comments
 (0)