Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add support for file URLs in MTLURLValueTransformerName #262

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+6 −1
Split
@@ -23,7 +23,7 @@ + (void)load {
MTLValueTransformer *URLValueTransformer = [MTLValueTransformer
reversibleTransformerWithForwardBlock:^ id (NSString *str) {
if (![str isKindOfClass:NSString.class]) return nil;
- return [NSURL URLWithString:str];
+ return [NSURL URLWithString:str] ?: [NSURL fileURLWithPath:str];
}
reverseBlock:^ id (NSURL *URL) {
if (![URL isKindOfClass:NSURL.class]) return nil;
@@ -25,6 +25,11 @@
expect([transformer transformedValue:URLString]).to.equal([NSURL URLWithString:URLString]);
expect([transformer reverseTransformedValue:[NSURL URLWithString:URLString]]).to.equal(URLString);
+ // Write temporary file for use in testing file URLs
+ NSURL *fileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"file.txt"]];
@robb

robb Mar 10, 2014

Owner

Let's use a fixed String and URL as input and not rely on the test environment's temp dir.

It also looks like there a spaces in the beginning of the line.

@mrh-is

mrh-is Mar 10, 2014

I was trying that, but if you don't give it a real path, +fileURLWithPath: gives you nil. Perhaps I just couldn't find the right way though.

+ expect([transformer transformedValue:fileURL.absoluteString]).to.equal(fileURL);
+ expect([transformer reverseTransformedValue:fileURL]).to.equal(fileURL.absoluteString);
+
expect([transformer transformedValue:nil]).to.beNil();
expect([transformer reverseTransformedValue:nil]).to.beNil();
});