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
// These tests are modeled off incorrect uses of the many-one pattern
// from real projects.
- (NSString *)test1:(int)plural {
if (plural) {
returnMCLocalizedString(@"TYPE_PLURAL"); // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
}
returnMCLocalizedString(@"TYPE");
}
- (NSString *)test2:(int)numOfReminders {
if (numOfReminders > 0) {
return [NSStringstringWithFormat:@"%@, %@", @"Test", (numOfReminders != 1) ? [NSStringstringWithFormat:NSLocalizedString(@"%@ Reminders", @"Plural count of reminders"), numOfReminders] : [NSStringstringWithFormat:NSLocalizedString(@"1 reminder", @"One reminder")]]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}} expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
}
returnnil;
}
- (void)test3 {
NSString *count;
if (self.unreadArticlesCount > 1)
{
count = [count stringByAppendingFormat:@"%@", KHLocalizedString(@"New Stories", @"Plural count for new stories")]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
} else {
count = [count stringByAppendingFormat:@"%@", KHLocalizedString(@"New Story", @"One new story")]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
}
}
- (NSString *)test4:(int)count {
if ( count == 1 )
{
return [NSStringstringWithFormat:KHLocalizedString(@"value.singular",nil), count]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
} else {
return [NSStringstringWithFormat:KHLocalizedString(@"value.plural",nil), count]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
}
}
- (NSString *)test5:(int)count {
int test = count == 1;
if (test)
{
return [NSStringstringWithFormat:KHLocalizedString(@"value.singular",nil), count]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
} else {
return [NSStringstringWithFormat:KHLocalizedString(@"value.plural",nil), count]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
}
}
// This tests the heuristic that the direct parent IfStmt must match the isCheckingPlurality confition to avoid false positives generated from complex code (generally the pattern we're looking for is simple If-Else)
- (NSString *)test6:(int)sectionIndex {
int someOtherVariable = 0;
if (sectionIndex == 1)
{
// Do some other crazy stuff
if (someOtherVariable)
returnKHLocalizedString(@"OK",nil); // no-warning
} else {
returnKHLocalizedString(@"value.plural",nil); // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
}
returnnil;
}
// False positives that we are not accounting for involve matching the heuristic
// of having 1 or 2 in the RHS of a BinaryOperator and having a localized string
// in the body of the IfStmt. This is seen a lot when checking for the section