summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLStyleLayerTests.m
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/test/MGLStyleLayerTests.m')
-rw-r--r--platform/darwin/test/MGLStyleLayerTests.m67
1 files changed, 67 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLStyleLayerTests.m b/platform/darwin/test/MGLStyleLayerTests.m
index 74c6b2f906..590d6eda7f 100644
--- a/platform/darwin/test/MGLStyleLayerTests.m
+++ b/platform/darwin/test/MGLStyleLayerTests.m
@@ -1,7 +1,13 @@
#import "MGLStyleLayerTests.h"
+#import "NSString+MGLAdditions.h"
+
+#define TEST_STRICT_NAMING_CONVENTIONS 0
+
@implementation MGLStyleLayerTests
+@dynamic layerType;
+
- (void)setUp {
[super setUp];
#if TARGET_OS_IPHONE
@@ -19,4 +25,65 @@
#endif
}
+- (void)testPropertyName:(NSString *)name isBoolean:(BOOL)isBoolean {
+ NS_MUTABLE_ARRAY_OF(NSString *) *components = [name componentsSeparatedByString:@"-"].mutableCopy;
+ if (isBoolean) {
+ if ([components.firstObject isEqualToString:@"is"]) {
+ [components removeObjectAtIndex:0];
+ if (![components.lastObject.lexicalClasses containsObject:NSLinguisticTagAdjective]) {
+ XCTAssertTrue([components.lastObject.lexicalClasses containsObject:NSLinguisticTagVerb],
+ @"Boolean getter %@ that starts with “is” should contain an adjective, past participle, or verb.", name);
+ XCTAssertNotEqualObjects(components.lastObject.lemma, components.lastObject,
+ @"Boolean getter %@ should not have infinitive, imperative, or present tense verb.", name);
+ }
+ } else {
+ if ([components.firstObject isEqualToString:[self class].layerType]
+ || [components.firstObject isEqualToString:@"icon"] || [components.firstObject isEqualToString:@"text"]) {
+ [components removeObjectAtIndex:0];
+ }
+#if TEST_STRICT_NAMING_CONVENTIONS
+ XCTAssertTrue([components.firstObject.lexicalClasses containsObject:NSLinguisticTagVerb],
+ @"Boolean getter %@ that doesn’t start with “is” should contain a verb.", name);
+ XCTAssertNotEqualObjects(components.firstObject.lemma, components.lastObject);
+#endif
+ }
+ } else {
+ XCTAssertFalse([components.firstObject isEqualToString:@"is"]);
+#if TEST_STRICT_NAMING_CONVENTIONS
+ XCTAssertTrue([components.lastObject.lexicalClasses containsObject:NSLinguisticTagNoun],
+ @"Non-Boolean getter %@ should contain a noun.", name);
+#endif
+ }
+}
+
+@end
+
+@implementation NSString (MGLStyleLayerTestAdditions)
+
+- (NS_ARRAY_OF(NSString *) *)lexicalClasses {
+ NSOrthography *orthography = [NSOrthography orthographyWithDominantScript:@"Latn"
+ languageMap:@{@"Latn": @[@"en"]}];
+ NSLinguisticTaggerOptions options = (NSLinguisticTaggerOmitPunctuation
+ | NSLinguisticTaggerOmitWhitespace
+ | NSLinguisticTaggerOmitOther);
+ return [self linguisticTagsInRange:self.mgl_wholeRange
+ scheme:NSLinguisticTagSchemeLexicalClass
+ options:options
+ orthography:orthography
+ tokenRanges:NULL];
+}
+
+- (NSString *)lemma {
+ NSOrthography *orthography = [NSOrthography orthographyWithDominantScript:@"Latn"
+ languageMap:@{@"Latn": @[@"en"]}];
+ NSLinguisticTaggerOptions options = (NSLinguisticTaggerOmitPunctuation
+ | NSLinguisticTaggerOmitWhitespace
+ | NSLinguisticTaggerOmitOther);
+ return [self linguisticTagsInRange:self.mgl_wholeRange
+ scheme:NSLinguisticTagSchemeLemma
+ options:options
+ orthography:orthography
+ tokenRanges:NULL].firstObject;
+}
+
@end