@@ -28,7 +28,7 @@ - (void)setUp {
2828 [super setUp ];
2929
3030 [MGLAccountManager setAccessToken: @" pk.feedcafedeadbeefbadebede" ];
31- NSURL *styleURL = [[NSBundle bundleForClass: [self class ]] URLForResource: @" one-liner " withExtension: @" json" ];
31+ NSURL *styleURL = [[NSBundle bundleForClass: [self class ]] URLForResource: @" basic-style " withExtension: @" json" ];
3232 self.mapView = [[MGLMapView alloc ] initWithFrame: CGRectMake (0 , 0 , 100 , 100 ) styleURL: styleURL];
3333 self.mapView .delegate = self;
3434 if (!self.mapView .style ) {
@@ -140,11 +140,8 @@ - (void)testName {
140140
141141- (void )testSources {
142142 NSSet <MGLSource *> *initialSources = self.style .sources ;
143- if ([initialSources.anyObject.identifier isEqualToString: @" com.mapbox.annotations" ]) {
144- XCTAssertEqual (self.style .sources .count , 1UL );
145- } else {
146- XCTAssertEqual (self.style .sources .count , 0UL );
147- }
143+ XCTAssertTrue (initialSources.count <= 2 );
144+
148145 MGLShapeSource *shapeSource = [[MGLShapeSource alloc ] initWithIdentifier: @" shapeSource" shape: nil options: nil ];
149146 [self .style addSource: shapeSource];
150147 XCTAssertEqual (self.style .sources .count , initialSources.count + 1 );
@@ -250,11 +247,9 @@ - (void)testRemovingSourceInUse {
250247
251248- (void )testLayers {
252249 NSArray <MGLStyleLayer *> *initialLayers = self.style .layers ;
253- if ([initialLayers.firstObject.identifier isEqualToString: @" com.mapbox.annotations.points" ]) {
254- XCTAssertEqual (self.style .layers .count , 1UL );
255- } else {
256- XCTAssertEqual (self.style .layers .count , 0UL );
257- }
250+
251+ XCTAssertTrue (initialLayers.count <= 2 );
252+
258253 MGLShapeSource *shapeSource = [[MGLShapeSource alloc ] initWithIdentifier: @" shapeSource" shape: nil options: nil ];
259254 [self .style addSource: shapeSource];
260255 MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc ] initWithIdentifier: @" fillLayer" source: shapeSource];
@@ -396,6 +391,8 @@ - (void)testLayersOrder {
396391 NSURL *url = [NSURL fileURLWithPath: filePath];
397392 MGLShapeSource *source = [[MGLShapeSource alloc ] initWithIdentifier: @" sourceID" URL: url options: nil ];
398393 [self .style addSource: source];
394+
395+ NSUInteger startIndex = self.style .layers .count ;
399396
400397 MGLCircleStyleLayer *layer1 = [[MGLCircleStyleLayer alloc ] initWithIdentifier: @" layer1" source: source];
401398 [self .style addLayer: layer1];
@@ -413,7 +410,7 @@ - (void)testLayersOrder {
413410 [self .style insertLayer: layer0 belowLayer: layer1];
414411
415412 NSArray <MGLStyleLayer *> *layers = [self .style layers ];
416- NSUInteger startIndex = 0 ;
413+
417414 if ([layers.firstObject.identifier isEqualToString: @" com.mapbox.annotations.points" ]) {
418415 startIndex++;
419416 }
@@ -427,6 +424,36 @@ - (void)testLayersOrder {
427424
428425#pragma mark Localization tests
429426
427+ - (void )testLocalization {
428+ MGLSymbolStyleLayer *countryLabel = (MGLSymbolStyleLayer *)[self .style layerWithIdentifier: @" country-label" ];
429+ {
430+ NSLocale *locale = [NSLocale localeWithLocaleIdentifier: @" de_DE" ];
431+ [self .style localizeLabelsIntoLocale: locale];
432+
433+ NSArray * keypathArray = @[ [NSExpression expressionForKeyPath: @" name_de" ],
434+ [NSExpression expressionForKeyPath: @" name" ]];
435+ NSExpression *coalesceExpression = [NSExpression expressionWithFormat: @" mgl_coalesce:(%@ )" , @[ [NSExpression expressionWithFormat: @" mgl_coalesce:(%@ )" , keypathArray],
436+ [NSExpression expressionWithFormat: @" mgl_coalesce:(%@ )" , keypathArray] ]];
437+ MGLAttributedExpression *attributedExpression = [MGLAttributedExpression attributedExpression: coalesceExpression attributes: @{}];
438+ NSExpression *localizedExpression = [NSExpression mgl_expressionForAttributedExpressions: @[ [NSExpression expressionForConstantValue: attributedExpression] ]];
439+ XCTAssertEqualObjects (countryLabel.text , localizedExpression);
440+ countryLabel.text = [NSExpression expressionWithFormat: @" mgl_coalesce({%K, %K})" , @" name_en" , @" name" ];
441+ }
442+ {
443+ NSLocale *locale = [NSLocale localeWithLocaleIdentifier: @" es" ];
444+ [self .style localizeLabelsIntoLocale: locale];
445+
446+ NSArray * keypathArray = @[ [NSExpression expressionForKeyPath: @" name_es" ],
447+ [NSExpression expressionForKeyPath: @" name" ]];
448+ NSExpression *coalesceExpression = [NSExpression expressionWithFormat: @" mgl_coalesce:(%@ )" , @[ [NSExpression expressionWithFormat: @" mgl_coalesce:(%@ )" , keypathArray],
449+ [NSExpression expressionWithFormat: @" mgl_coalesce:(%@ )" , keypathArray] ]];
450+ MGLAttributedExpression *attributedExpression = [MGLAttributedExpression attributedExpression: coalesceExpression attributes: @{}];
451+ NSExpression *localizedExpression = [NSExpression mgl_expressionForAttributedExpressions: @[ [NSExpression expressionForConstantValue: attributedExpression] ]];
452+ XCTAssertEqualObjects (countryLabel.text , localizedExpression);
453+ countryLabel.text = [NSExpression expressionWithFormat: @" mgl_coalesce({%K, %K})" , @" name_en" , @" name" ];
454+ }
455+ }
456+
430457- (void )testLanguageMatching {
431458 {
432459 NSArray *preferences = @[@" en" ];
0 commit comments