summaryrefslogtreecommitdiff
path: root/platform/darwin/test
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-22 11:12:27 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-04-22 11:29:10 -0700
commit2a1a5f088564b2d6c2e3765d0d741edf1886fc81 (patch)
tree4f58085117a42213db7b70e21cc16a535fe3ff34 /platform/darwin/test
parente5c6cfde4b4f36cadeadfcb320bd641c4517f366 (diff)
downloadqtlocation-mapboxgl-2a1a5f088564b2d6c2e3765d0d741edf1886fc81.tar.gz
[ios, osx] Split MGLDirectionFormatter in two
Split MGLDirectionFormatter into MGLClockDirectionFormatter, which specializes in clock positions, and MGLCompassDirectionFormatter, which boxes the compass. This neatly avoids any confusion that might arise if the developer fails to read the documentation and thinks the original unified formatter can convert between the two types of directions.
Diffstat (limited to 'platform/darwin/test')
-rw-r--r--platform/darwin/test/MGLClockDirectionFormatterTests.m49
-rw-r--r--platform/darwin/test/MGLCompassDirectionFormatterTests.m (renamed from platform/darwin/test/MGLDirectionFormatterTests.m)58
2 files changed, 55 insertions, 52 deletions
diff --git a/platform/darwin/test/MGLClockDirectionFormatterTests.m b/platform/darwin/test/MGLClockDirectionFormatterTests.m
new file mode 100644
index 0000000000..b85f4bed8c
--- /dev/null
+++ b/platform/darwin/test/MGLClockDirectionFormatterTests.m
@@ -0,0 +1,49 @@
+#import <Mapbox/Mapbox.h>
+#import <XCTest/XCTest.h>
+
+static NSString * const MGLTestLocaleIdentifier = @"en-US";
+
+@interface MGLClockDirectionFormatterTests : XCTestCase
+
+@end
+
+@implementation MGLClockDirectionFormatterTests
+
+- (void)testClockDirections {
+ MGLClockDirectionFormatter *shortFormatter = [[MGLClockDirectionFormatter alloc] init];
+ shortFormatter.unitStyle = NSFormattingUnitStyleShort;
+ shortFormatter.locale = [NSLocale localeWithLocaleIdentifier:MGLTestLocaleIdentifier];
+
+ MGLClockDirectionFormatter *mediumFormatter = [[MGLClockDirectionFormatter alloc] init];
+ mediumFormatter.locale = [NSLocale localeWithLocaleIdentifier:MGLTestLocaleIdentifier];
+
+ MGLClockDirectionFormatter *longFormatter = [[MGLClockDirectionFormatter alloc] init];
+ longFormatter.unitStyle = NSFormattingUnitStyleLong;
+ longFormatter.locale = [NSLocale localeWithLocaleIdentifier:MGLTestLocaleIdentifier];
+
+ XCTAssertEqualObjects(@"9:00", [shortFormatter stringFromDirection:-90]);
+ XCTAssertEqualObjects(@"9 o’clock", [mediumFormatter stringFromDirection:-90]);
+ XCTAssertEqualObjects(@"nine o’clock", [longFormatter stringFromDirection:-90]);
+
+ XCTAssertEqualObjects(@"12:00", [shortFormatter stringFromDirection:0]);
+ XCTAssertEqualObjects(@"12 o’clock", [mediumFormatter stringFromDirection:0]);
+ XCTAssertEqualObjects(@"twelve o’clock", [longFormatter stringFromDirection:0]);
+
+ XCTAssertEqualObjects(@"2:00", [shortFormatter stringFromDirection:45]);
+ XCTAssertEqualObjects(@"2 o’clock", [mediumFormatter stringFromDirection:45]);
+ XCTAssertEqualObjects(@"two o’clock", [longFormatter stringFromDirection:45]);
+
+ XCTAssertEqualObjects(@"3:00", [shortFormatter stringFromDirection:90]);
+ XCTAssertEqualObjects(@"3 o’clock", [mediumFormatter stringFromDirection:90]);
+ XCTAssertEqualObjects(@"three o’clock", [longFormatter stringFromDirection:90]);
+
+ XCTAssertEqualObjects(@"6:00", [shortFormatter stringFromDirection:180]);
+ XCTAssertEqualObjects(@"6 o’clock", [mediumFormatter stringFromDirection:180]);
+ XCTAssertEqualObjects(@"six o’clock", [longFormatter stringFromDirection:180]);
+
+ XCTAssertEqualObjects(@"9:00", [shortFormatter stringFromDirection:270]);
+ XCTAssertEqualObjects(@"9 o’clock", [mediumFormatter stringFromDirection:270]);
+ XCTAssertEqualObjects(@"nine o’clock", [longFormatter stringFromDirection:270]);
+}
+
+@end
diff --git a/platform/darwin/test/MGLDirectionFormatterTests.m b/platform/darwin/test/MGLCompassDirectionFormatterTests.m
index 81c5223068..034e07818b 100644
--- a/platform/darwin/test/MGLDirectionFormatterTests.m
+++ b/platform/darwin/test/MGLCompassDirectionFormatterTests.m
@@ -1,27 +1,21 @@
#import <Mapbox/Mapbox.h>
#import <XCTest/XCTest.h>
-static NSString * const MGLTestLocaleIdentifier = @"en-US";
-
-@interface MGLDirectionFormatterTests : XCTestCase
+@interface MGLCompassDirectionFormatterTests : XCTestCase
@end
-@implementation MGLDirectionFormatterTests
+@implementation MGLCompassDirectionFormatterTests
-- (void)testAbsoluteDirections {
- MGLDirectionFormatter *shortFormatter = [[MGLDirectionFormatter alloc] init];
- XCTAssertEqual(shortFormatter.origin, MGLDirectionFormatterOriginNorth, @"Reference point should be north by default.");
+- (void)testCompassDirections {
+ MGLCompassDirectionFormatter *shortFormatter = [[MGLCompassDirectionFormatter alloc] init];
shortFormatter.unitStyle = NSFormattingUnitStyleShort;
- shortFormatter.locale = [NSLocale localeWithLocaleIdentifier:MGLTestLocaleIdentifier];
- MGLDirectionFormatter *mediumFormatter = [[MGLDirectionFormatter alloc] init];
+ MGLCompassDirectionFormatter *mediumFormatter = [[MGLCompassDirectionFormatter alloc] init];
XCTAssertEqual(mediumFormatter.unitStyle, NSFormattingUnitStyleMedium, @"Unit style should be medium by default.");
- mediumFormatter.locale = [NSLocale localeWithLocaleIdentifier:MGLTestLocaleIdentifier];
- MGLDirectionFormatter *longFormatter = [[MGLDirectionFormatter alloc] init];
+ MGLCompassDirectionFormatter *longFormatter = [[MGLCompassDirectionFormatter alloc] init];
longFormatter.unitStyle = NSFormattingUnitStyleLong;
- longFormatter.locale = [NSLocale localeWithLocaleIdentifier:MGLTestLocaleIdentifier];
XCTAssertEqualObjects(@"NW", [shortFormatter stringFromDirection:-45]);
XCTAssertEqualObjects(@"northwest", [mediumFormatter stringFromDirection:-45]);
@@ -68,44 +62,4 @@ static NSString * const MGLTestLocaleIdentifier = @"en-US";
XCTAssertEqualObjects([mediumFormatter stringFromDirection:720], [longFormatter stringFromDirection:720]);
}
-- (void)testRelativeDirections {
- MGLDirectionFormatter *shortFormatter = [[MGLDirectionFormatter alloc] init];
- shortFormatter.origin = MGLDirectionFormatterOriginStraightAhead;
- shortFormatter.unitStyle = NSFormattingUnitStyleShort;
- shortFormatter.locale = [NSLocale localeWithLocaleIdentifier:MGLTestLocaleIdentifier];
-
- MGLDirectionFormatter *mediumFormatter = [[MGLDirectionFormatter alloc] init];
- mediumFormatter.origin = MGLDirectionFormatterOriginStraightAhead;
- mediumFormatter.locale = [NSLocale localeWithLocaleIdentifier:MGLTestLocaleIdentifier];
-
- MGLDirectionFormatter *longFormatter = [[MGLDirectionFormatter alloc] init];
- longFormatter.origin = MGLDirectionFormatterOriginStraightAhead;
- longFormatter.unitStyle = NSFormattingUnitStyleLong;
- longFormatter.locale = [NSLocale localeWithLocaleIdentifier:MGLTestLocaleIdentifier];
-
- XCTAssertEqualObjects(@"9:00", [shortFormatter stringFromDirection:-90]);
- XCTAssertEqualObjects(@"9 o’clock", [mediumFormatter stringFromDirection:-90]);
- XCTAssertEqualObjects(@"nine o’clock", [longFormatter stringFromDirection:-90]);
-
- XCTAssertEqualObjects(@"12:00", [shortFormatter stringFromDirection:0]);
- XCTAssertEqualObjects(@"12 o’clock", [mediumFormatter stringFromDirection:0]);
- XCTAssertEqualObjects(@"twelve o’clock", [longFormatter stringFromDirection:0]);
-
- XCTAssertEqualObjects(@"2:00", [shortFormatter stringFromDirection:45]);
- XCTAssertEqualObjects(@"2 o’clock", [mediumFormatter stringFromDirection:45]);
- XCTAssertEqualObjects(@"two o’clock", [longFormatter stringFromDirection:45]);
-
- XCTAssertEqualObjects(@"3:00", [shortFormatter stringFromDirection:90]);
- XCTAssertEqualObjects(@"3 o’clock", [mediumFormatter stringFromDirection:90]);
- XCTAssertEqualObjects(@"three o’clock", [longFormatter stringFromDirection:90]);
-
- XCTAssertEqualObjects(@"6:00", [shortFormatter stringFromDirection:180]);
- XCTAssertEqualObjects(@"6 o’clock", [mediumFormatter stringFromDirection:180]);
- XCTAssertEqualObjects(@"six o’clock", [longFormatter stringFromDirection:180]);
-
- XCTAssertEqualObjects(@"9:00", [shortFormatter stringFromDirection:270]);
- XCTAssertEqualObjects(@"9 o’clock", [mediumFormatter stringFromDirection:270]);
- XCTAssertEqualObjects(@"nine o’clock", [longFormatter stringFromDirection:270]);
-}
-
@end