Repository navigation
Prevent stopless functions - #7309
Conversation
|
@frederoni, thanks for your PR! By analyzing this pull request, we identified @1ec5, @boundsj and @incanus to be potential reviewers. |
bf5ba71 to
d8a5f81
Compare
There was a problem hiding this comment.
stops.count would be more efficient.
There was a problem hiding this comment.
[self class] resolves to MGLConstantStyleValue or MGLStyleFunction, but I think self would be more informative since it calls -description.
There was a problem hiding this comment.
For internal errors, use NSAssert(). For developer errors, raise an NSException and give it a name like NSInvalidArgumentException that the developer can identify the exception by.
There was a problem hiding this comment.
If you give the exception a name, you can use XCTAssertThrowsSpecificNamed() here.
There was a problem hiding this comment.
Let’s call this MGLStyleValueTests for consistency with the file that contains the implementation.
There was a problem hiding this comment.
MGLStyleValueTests is taken by a Swift class with the same name but I can't use that class to catch a specific exception name if the method itself doesn't throw the exception. Renamed it to MGLStyleValueObjCTests for now.
There was a problem hiding this comment.
Ah, I see. Alternatively, maybe we can call this class MGLStyleValueTests and turn the Swift class into an extension on MGLStyleValueTests. Not sure if XCTest will be happy with that or not.
d8a5f81 to
4c48ab4
Compare
| if (self = [super init]) { | ||
| if (!stops.count) | ||
| { | ||
| [NSException raise:@"NSInvalidArgumentException" format:@"%@ requires at least one stop.", self]; |
There was a problem hiding this comment.
Use the constant, NSInvalidArgumentException.
| @implementation MGLStyleValueObjCTests | ||
|
|
||
| - (void)testStoplessFunction { | ||
| XCTAssertThrowsSpecificNamed([MGLStyleValue<NSNumber *> valueWithStops:@{}], NSException, @"NSInvalidArgumentException", @"Stopless function should raise an exception"); |
There was a problem hiding this comment.
The constant NSInvalidArgumentException works here too.
Fixes #7249
Raises an exception if an
MGLStyleFunctionis initialized with no stops.