From 09120e19ba42a746996808a2ef5bbc9d18f9b35c Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 8 Jun 2018 16:40:26 +0800 Subject: [PATCH 1/7] :white_check_mark: add: `NSURLQueryItemSpec` to test url component --- AMRouter.xcodeproj/project.pbxproj | 4 +++ AMRouterTests/NSURLQueryItemSpec.m | 44 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 AMRouterTests/NSURLQueryItemSpec.m diff --git a/AMRouter.xcodeproj/project.pbxproj b/AMRouter.xcodeproj/project.pbxproj index 46049b0..db38c62 100644 --- a/AMRouter.xcodeproj/project.pbxproj +++ b/AMRouter.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 8EDB60CD20C7C72900EB2CBA /* AMComponentSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB60CC20C7C72900EB2CBA /* AMComponentSpec.m */; }; 8EDB60D220C7D3FE00EB2CBA /* AMComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB60D120C7D3FE00EB2CBA /* AMComponent.m */; }; 8EDB60D520C7EEA800EB2CBA /* AMMessageComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB60D420C7EEA800EB2CBA /* AMMessageComponent.m */; }; + 8EDB612020CA68E700EB2CBA /* NSURLQueryItemSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB611F20CA68E700EB2CBA /* NSURLQueryItemSpec.m */; }; 8EDC786F20C7C294001A3427 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDC786E20C7C294001A3427 /* AppDelegate.m */; }; 8EDC787220C7C294001A3427 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDC787120C7C294001A3427 /* ViewController.m */; }; 8EDC787520C7C294001A3427 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8EDC787320C7C294001A3427 /* Main.storyboard */; }; @@ -45,6 +46,7 @@ 8EDB60D120C7D3FE00EB2CBA /* AMComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMComponent.m; sourceTree = ""; }; 8EDB60D320C7EEA800EB2CBA /* AMMessageComponent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AMMessageComponent.h; sourceTree = ""; }; 8EDB60D420C7EEA800EB2CBA /* AMMessageComponent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AMMessageComponent.m; sourceTree = ""; }; + 8EDB611F20CA68E700EB2CBA /* NSURLQueryItemSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSURLQueryItemSpec.m; sourceTree = ""; }; 8EDC786A20C7C294001A3427 /* AMRouter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AMRouter.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8EDC786D20C7C294001A3427 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 8EDC786E20C7C294001A3427 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -172,6 +174,7 @@ children = ( 8EDB60C820C7C68D00EB2CBA /* Misc */, 8EDB60CC20C7C72900EB2CBA /* AMComponentSpec.m */, + 8EDB611F20CA68E700EB2CBA /* NSURLQueryItemSpec.m */, ); path = AMRouterTests; sourceTree = ""; @@ -378,6 +381,7 @@ buildActionMask = 2147483647; files = ( 8EDB60CD20C7C72900EB2CBA /* AMComponentSpec.m in Sources */, + 8EDB612020CA68E700EB2CBA /* NSURLQueryItemSpec.m in Sources */, 8EDB60CB20C7C6BE00EB2CBA /* SwiftSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/AMRouterTests/NSURLQueryItemSpec.m b/AMRouterTests/NSURLQueryItemSpec.m new file mode 100644 index 0000000..4327785 --- /dev/null +++ b/AMRouterTests/NSURLQueryItemSpec.m @@ -0,0 +1,44 @@ +// +// NSURLQueryItemSpec.m +// AMRouter +// +// Created by archmagees on 2018/06/08. +// Copyright © 2018 archmagees. All rights reserved. +// + +@import Quick; +@import Nimble; +@import Foundation; + +QuickSpecBegin(NSURLQueryItemSpec) + +context(@"there is a url", ^{ + + it(@"fabric://modulename/actionname/subaction?key1=value1&222=value2&key1=value1", ^ { + + NSString *url = @"fabric://modulename/actionname/subaction?key1=value1&222=value2&key1=value1"; + NSURL *URL = [NSURL URLWithString:url]; + + expect(URL.scheme).to(contain(@"fabric")); + expect(URL.host).to(contain(@"modulename")); + expect(URL.path).to(contain(@"actionname/subaction")); + + NSArray *queryItems = + [[NSURLComponents alloc] initWithURL:URL + resolvingAgainstBaseURL:NO].queryItems; + + [queryItems enumerateObjectsUsingBlock:^(NSURLQueryItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + + }]; + + NSLog(@"query items: %@", queryItems); + + expect(queryItems[0].name).to(contain(@"key1")); + expect(queryItems[1].name).to(contain(@"222")); + expect(queryItems[2].name).to(contain(@"key1")); + + }); + +}); + +QuickSpecEnd From 15e9d828aa0b93ca744b59ee5a64c92e8f4223ba Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 10 Jun 2018 14:19:41 +0800 Subject: [PATCH 2/7] :sparkles: add: category for `NSString` --- AMRouter.xcodeproj/project.pbxproj | 10 ++++ AMRouter/AMRouter/AMRouter.h | 1 - AMRouter/AMRouter/NSString+AMTrick.h | 19 ++++++ AMRouter/AMRouter/NSString+AMTrick.m | 31 ++++++++++ AMRouterTests/NSStringExtensionMethodsSpec.m | 63 ++++++++++++++++++++ AMRouterTests/NSURLQueryItemSpec.m | 11 ++-- 6 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 AMRouter/AMRouter/NSString+AMTrick.h create mode 100644 AMRouter/AMRouter/NSString+AMTrick.m create mode 100644 AMRouterTests/NSStringExtensionMethodsSpec.m diff --git a/AMRouter.xcodeproj/project.pbxproj b/AMRouter.xcodeproj/project.pbxproj index db38c62..092c28a 100644 --- a/AMRouter.xcodeproj/project.pbxproj +++ b/AMRouter.xcodeproj/project.pbxproj @@ -14,6 +14,8 @@ 8EDB60D220C7D3FE00EB2CBA /* AMComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB60D120C7D3FE00EB2CBA /* AMComponent.m */; }; 8EDB60D520C7EEA800EB2CBA /* AMMessageComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB60D420C7EEA800EB2CBA /* AMMessageComponent.m */; }; 8EDB612020CA68E700EB2CBA /* NSURLQueryItemSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB611F20CA68E700EB2CBA /* NSURLQueryItemSpec.m */; }; + 8EDB612220CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB612120CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m */; }; + 8EDB612520CCF8CA00EB2CBA /* NSString+AMTrick.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB612420CCF8CA00EB2CBA /* NSString+AMTrick.m */; }; 8EDC786F20C7C294001A3427 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDC786E20C7C294001A3427 /* AppDelegate.m */; }; 8EDC787220C7C294001A3427 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDC787120C7C294001A3427 /* ViewController.m */; }; 8EDC787520C7C294001A3427 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8EDC787320C7C294001A3427 /* Main.storyboard */; }; @@ -47,6 +49,9 @@ 8EDB60D320C7EEA800EB2CBA /* AMMessageComponent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AMMessageComponent.h; sourceTree = ""; }; 8EDB60D420C7EEA800EB2CBA /* AMMessageComponent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AMMessageComponent.m; sourceTree = ""; }; 8EDB611F20CA68E700EB2CBA /* NSURLQueryItemSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSURLQueryItemSpec.m; sourceTree = ""; }; + 8EDB612120CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSStringExtensionMethodsSpec.m; sourceTree = ""; }; + 8EDB612320CCF8C900EB2CBA /* NSString+AMTrick.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+AMTrick.h"; sourceTree = ""; }; + 8EDB612420CCF8CA00EB2CBA /* NSString+AMTrick.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+AMTrick.m"; sourceTree = ""; }; 8EDC786A20C7C294001A3427 /* AMRouter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AMRouter.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8EDC786D20C7C294001A3427 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 8EDC786E20C7C294001A3427 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -126,6 +131,8 @@ 8EDB60CF20C7D3FE00EB2CBA /* AMRouter.h */, 8EDB60D020C7D3FE00EB2CBA /* AMComponent.h */, 8EDB60D120C7D3FE00EB2CBA /* AMComponent.m */, + 8EDB612320CCF8C900EB2CBA /* NSString+AMTrick.h */, + 8EDB612420CCF8CA00EB2CBA /* NSString+AMTrick.m */, ); path = AMRouter; sourceTree = ""; @@ -175,6 +182,7 @@ 8EDB60C820C7C68D00EB2CBA /* Misc */, 8EDB60CC20C7C72900EB2CBA /* AMComponentSpec.m */, 8EDB611F20CA68E700EB2CBA /* NSURLQueryItemSpec.m */, + 8EDB612120CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m */, ); path = AMRouterTests; sourceTree = ""; @@ -369,6 +377,7 @@ 8EDB60D520C7EEA800EB2CBA /* AMMessageComponent.m in Sources */, 8EDC787220C7C294001A3427 /* ViewController.m in Sources */, 8EDC789D20C7C387001A3427 /* MessageModule.m in Sources */, + 8EDB612520CCF8CA00EB2CBA /* NSString+AMTrick.m in Sources */, 8EDC787D20C7C296001A3427 /* main.m in Sources */, 8EDB60D220C7D3FE00EB2CBA /* AMComponent.m in Sources */, 8EDC786F20C7C294001A3427 /* AppDelegate.m in Sources */, @@ -381,6 +390,7 @@ buildActionMask = 2147483647; files = ( 8EDB60CD20C7C72900EB2CBA /* AMComponentSpec.m in Sources */, + 8EDB612220CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m in Sources */, 8EDB612020CA68E700EB2CBA /* NSURLQueryItemSpec.m in Sources */, 8EDB60CB20C7C6BE00EB2CBA /* SwiftSpec.swift in Sources */, ); diff --git a/AMRouter/AMRouter/AMRouter.h b/AMRouter/AMRouter/AMRouter.h index 1bad749..e771e2f 100644 --- a/AMRouter/AMRouter/AMRouter.h +++ b/AMRouter/AMRouter/AMRouter.h @@ -16,4 +16,3 @@ FOUNDATION_EXPORT const unsigned char AMRouterVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import #import - diff --git a/AMRouter/AMRouter/NSString+AMTrick.h b/AMRouter/AMRouter/NSString+AMTrick.h new file mode 100644 index 0000000..88f2de3 --- /dev/null +++ b/AMRouter/AMRouter/NSString+AMTrick.h @@ -0,0 +1,19 @@ +// +// NSString+AMTrick.h +// AMRouter +// +// Created by archmagees on 2018/06/10. +// Copyright © 2018 archmagees. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSString (AMTrick) + +- (NSUInteger)countOfOccurrencesOfString:(NSString *)specSymbol; + +@end + +NS_ASSUME_NONNULL_END diff --git a/AMRouter/AMRouter/NSString+AMTrick.m b/AMRouter/AMRouter/NSString+AMTrick.m new file mode 100644 index 0000000..6a55b23 --- /dev/null +++ b/AMRouter/AMRouter/NSString+AMTrick.m @@ -0,0 +1,31 @@ +// +// NSString+AMTrick.m +// AMRouter +// +// Created by archmagees on 2018/06/10. +// Copyright © 2018 archmagees. All rights reserved. +// + +#import "NSString+AMTrick.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation NSString (AMTrick) + +- (NSUInteger)countOfOccurrencesOfString:(NSString *)specSymbol { + if (!self.length) { + return 0; + } + + if (!specSymbol.length) { + return 0; + } + + NSString *stringWithoutSymbol = [self stringByReplacingOccurrencesOfString:specSymbol withString:@""]; + NSUInteger diff = self.length - stringWithoutSymbol.length; + return diff; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/AMRouterTests/NSStringExtensionMethodsSpec.m b/AMRouterTests/NSStringExtensionMethodsSpec.m new file mode 100644 index 0000000..6fd4213 --- /dev/null +++ b/AMRouterTests/NSStringExtensionMethodsSpec.m @@ -0,0 +1,63 @@ +// +// NSStringExtensionMethodsSpec.m +// AMRouter +// +// Created by archmagees on 2018/06/08. +// Copyright © 2018 archmagees. All rights reserved. +// + +@import Quick; +@import Nimble; +@import Foundation; + +QuickSpecBegin(NSStringExtensionMethodsSpec) + +NSString * const kColonSymbol = @":"; +NSString * const kDelimiterSymbols = @"/?&."; + +context(@"there is a string", ^{ + + + __block NSString *url = nil; + + it(@":12345", ^ { + + url = @":12345"; + NSRange colonRange = [url rangeOfString:@":"]; + expect(colonRange.location).to(equal(0)); + expect(colonRange.length).to(equal(1)); + + // wrong + NSRange searchRange = NSMakeRange(NSMaxRange(colonRange), url.length); + NSCharacterSet *delimiterCharacterSet = [NSCharacterSet characterSetWithCharactersInString:kDelimiterSymbols]; + + expectAction(^ { + [url rangeOfCharacterFromSet:delimiterCharacterSet + options:NSLiteralSearch + range:searchRange]; + }).to(raiseException().named(NSRangeException)); + + // correct + NSUInteger colonEndIndex = NSMaxRange(colonRange); + searchRange = NSMakeRange(colonEndIndex, url.length - colonEndIndex); + + NSUInteger firstDelimiterIndex = + [url rangeOfCharacterFromSet:delimiterCharacterSet + options:NSLiteralSearch + range:searchRange].location; + expect(firstDelimiterIndex).to(equal(NSNotFound)); + + NSRange replaceRange = NSMakeRange(colonRange.location, + firstDelimiterIndex); + replaceRange = NSIntersectionRange(replaceRange, NSMakeRange(0, url.length)); + + NSMutableString *replacedUrl = [url mutableCopy]; + [replacedUrl replaceCharactersInRange:replaceRange withString:@"09876"]; + + expect(replacedUrl).to(contain(@"09876")); + + + }); +}); + +QuickSpecEnd diff --git a/AMRouterTests/NSURLQueryItemSpec.m b/AMRouterTests/NSURLQueryItemSpec.m index 4327785..7880d6e 100644 --- a/AMRouterTests/NSURLQueryItemSpec.m +++ b/AMRouterTests/NSURLQueryItemSpec.m @@ -14,14 +14,15 @@ context(@"there is a url", ^{ - it(@"fabric://modulename/actionname/subaction?key1=value1&222=value2&key1=value1", ^ { + it(@"fabric://modulename/actionname/subaction.htm?key1=value1&222=value2&key1=value1", ^ { - NSString *url = @"fabric://modulename/actionname/subaction?key1=value1&222=value2&key1=value1"; + NSString *url = @"fabric://modulename.com/v3/:actionname/:subaction.htm?key1=value1&222=value2&key1=:value1"; NSURL *URL = [NSURL URLWithString:url]; expect(URL.scheme).to(contain(@"fabric")); - expect(URL.host).to(contain(@"modulename")); - expect(URL.path).to(contain(@"actionname/subaction")); + expect(URL.host).to(contain(@"modulename.com")); + expect(URL.path).to(contain(@"v3/:actionname/:subaction")); + expect(URL.pathExtension).to(contain(@"htm")); NSArray *queryItems = [[NSURLComponents alloc] initWithURL:URL @@ -37,6 +38,8 @@ expect(queryItems[1].name).to(contain(@"222")); expect(queryItems[2].name).to(contain(@"key1")); + expect(queryItems[2].value).to(contain(@":value1")); + }); }); From 2e3fee11b525d45ed307d3f41e54dbdfe7f5a947 Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 10 Jun 2018 20:36:09 +0800 Subject: [PATCH 3/7] :sparkles: add: `AMUrlSchemeSynthesizer` Prepare for AMRouter class for future development. --- AMRouter.xcodeproj/project.pbxproj | 14 ++ AMRouter/AMRouter/AMRouter.h | 2 + AMRouter/AMRouter/AMUrlSchemeSynthesizer.h | 38 +++++ AMRouter/AMRouter/AMUrlSchemeSynthesizer.m | 138 +++++++++++++++++++ AMRouter/AMRouter/NSString+AMTrick.h | 2 +- AMRouter/AMRouter/NSString+AMTrick.m | 5 +- AMRouterTests/AMComponentSpec.m | 12 +- AMRouterTests/AMUrlSchemeSynthesizerSpec.m | 62 +++++++++ AMRouterTests/NSStringAMTrickSpec.m | 44 ++++++ AMRouterTests/NSStringExtensionMethodsSpec.m | 34 ++++- AMRouterTests/NSURLQueryItemSpec.m | 6 +- 11 files changed, 338 insertions(+), 19 deletions(-) create mode 100644 AMRouter/AMRouter/AMUrlSchemeSynthesizer.h create mode 100644 AMRouter/AMRouter/AMUrlSchemeSynthesizer.m create mode 100644 AMRouterTests/AMUrlSchemeSynthesizerSpec.m create mode 100644 AMRouterTests/NSStringAMTrickSpec.m diff --git a/AMRouter.xcodeproj/project.pbxproj b/AMRouter.xcodeproj/project.pbxproj index 092c28a..a8736a4 100644 --- a/AMRouter.xcodeproj/project.pbxproj +++ b/AMRouter.xcodeproj/project.pbxproj @@ -16,6 +16,9 @@ 8EDB612020CA68E700EB2CBA /* NSURLQueryItemSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB611F20CA68E700EB2CBA /* NSURLQueryItemSpec.m */; }; 8EDB612220CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB612120CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m */; }; 8EDB612520CCF8CA00EB2CBA /* NSString+AMTrick.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB612420CCF8CA00EB2CBA /* NSString+AMTrick.m */; }; + 8EDB612720CCFB4700EB2CBA /* NSStringAMTrickSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB612620CCFB4700EB2CBA /* NSStringAMTrickSpec.m */; }; + 8EDB612A20CD082600EB2CBA /* AMUrlSchemeSynthesizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB612920CD082600EB2CBA /* AMUrlSchemeSynthesizer.m */; }; + 8EDB612C20CD2D0500EB2CBA /* AMUrlSchemeSynthesizerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB612B20CD2D0500EB2CBA /* AMUrlSchemeSynthesizerSpec.m */; }; 8EDC786F20C7C294001A3427 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDC786E20C7C294001A3427 /* AppDelegate.m */; }; 8EDC787220C7C294001A3427 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDC787120C7C294001A3427 /* ViewController.m */; }; 8EDC787520C7C294001A3427 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8EDC787320C7C294001A3427 /* Main.storyboard */; }; @@ -52,6 +55,10 @@ 8EDB612120CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSStringExtensionMethodsSpec.m; sourceTree = ""; }; 8EDB612320CCF8C900EB2CBA /* NSString+AMTrick.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+AMTrick.h"; sourceTree = ""; }; 8EDB612420CCF8CA00EB2CBA /* NSString+AMTrick.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+AMTrick.m"; sourceTree = ""; }; + 8EDB612620CCFB4700EB2CBA /* NSStringAMTrickSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSStringAMTrickSpec.m; sourceTree = ""; }; + 8EDB612820CD082600EB2CBA /* AMUrlSchemeSynthesizer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AMUrlSchemeSynthesizer.h; sourceTree = ""; }; + 8EDB612920CD082600EB2CBA /* AMUrlSchemeSynthesizer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AMUrlSchemeSynthesizer.m; sourceTree = ""; }; + 8EDB612B20CD2D0500EB2CBA /* AMUrlSchemeSynthesizerSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AMUrlSchemeSynthesizerSpec.m; sourceTree = ""; }; 8EDC786A20C7C294001A3427 /* AMRouter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AMRouter.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8EDC786D20C7C294001A3427 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 8EDC786E20C7C294001A3427 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -133,6 +140,8 @@ 8EDB60D120C7D3FE00EB2CBA /* AMComponent.m */, 8EDB612320CCF8C900EB2CBA /* NSString+AMTrick.h */, 8EDB612420CCF8CA00EB2CBA /* NSString+AMTrick.m */, + 8EDB612820CD082600EB2CBA /* AMUrlSchemeSynthesizer.h */, + 8EDB612920CD082600EB2CBA /* AMUrlSchemeSynthesizer.m */, ); path = AMRouter; sourceTree = ""; @@ -183,6 +192,8 @@ 8EDB60CC20C7C72900EB2CBA /* AMComponentSpec.m */, 8EDB611F20CA68E700EB2CBA /* NSURLQueryItemSpec.m */, 8EDB612120CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m */, + 8EDB612620CCFB4700EB2CBA /* NSStringAMTrickSpec.m */, + 8EDB612B20CD2D0500EB2CBA /* AMUrlSchemeSynthesizerSpec.m */, ); path = AMRouterTests; sourceTree = ""; @@ -374,6 +385,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 8EDB612A20CD082600EB2CBA /* AMUrlSchemeSynthesizer.m in Sources */, 8EDB60D520C7EEA800EB2CBA /* AMMessageComponent.m in Sources */, 8EDC787220C7C294001A3427 /* ViewController.m in Sources */, 8EDC789D20C7C387001A3427 /* MessageModule.m in Sources */, @@ -389,7 +401,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 8EDB612720CCFB4700EB2CBA /* NSStringAMTrickSpec.m in Sources */, 8EDB60CD20C7C72900EB2CBA /* AMComponentSpec.m in Sources */, + 8EDB612C20CD2D0500EB2CBA /* AMUrlSchemeSynthesizerSpec.m in Sources */, 8EDB612220CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m in Sources */, 8EDB612020CA68E700EB2CBA /* NSURLQueryItemSpec.m in Sources */, 8EDB60CB20C7C6BE00EB2CBA /* SwiftSpec.swift in Sources */, diff --git a/AMRouter/AMRouter/AMRouter.h b/AMRouter/AMRouter/AMRouter.h index e771e2f..87d3954 100644 --- a/AMRouter/AMRouter/AMRouter.h +++ b/AMRouter/AMRouter/AMRouter.h @@ -16,3 +16,5 @@ FOUNDATION_EXPORT const unsigned char AMRouterVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import #import +#import +#import diff --git a/AMRouter/AMRouter/AMUrlSchemeSynthesizer.h b/AMRouter/AMRouter/AMUrlSchemeSynthesizer.h new file mode 100644 index 0000000..617fbca --- /dev/null +++ b/AMRouter/AMRouter/AMUrlSchemeSynthesizer.h @@ -0,0 +1,38 @@ +// +// AMUrlSchemeSynthesizer.h +// AMRouter +// +// Created by archmagees on 2018/06/10. +// Copyright © 2018 archmagees. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface AMUrlSchemeSynthesizer : NSObject + +/** + * @brief Create a string by replacing the placeholders in pattern. + * @discussion + * Pattern format is just like the url components. That is: + * `scheme://host/path.pathextension?query#fragment`, and usually the pattern + * format is passed as `:action?key1=:value1&key2=:value2`. + * + * @param pattern + * A string value indicates the template format. + * + * @param replacements + * An array which elements is NSString type, each of them will be used to + * replace the placeholders in template string. + * + * @return + * A string that has been processed. If it is nil, means there maybe an error + * in one of the parameters. + */ ++ (nullable NSString *)synthesizedStringWithPattern:(NSString *)pattern + replacements:(NSArray *)replacements; + +@end + +NS_ASSUME_NONNULL_END diff --git a/AMRouter/AMRouter/AMUrlSchemeSynthesizer.m b/AMRouter/AMRouter/AMUrlSchemeSynthesizer.m new file mode 100644 index 0000000..d632246 --- /dev/null +++ b/AMRouter/AMRouter/AMUrlSchemeSynthesizer.m @@ -0,0 +1,138 @@ +// +// AMUrlSchemeSynthesizer.m +// AMRouter +// +// Created by archmagees on 2018/06/10. +// Copyright © 2018 archmagees. All rights reserved. +// + +#import "AMUrlSchemeSynthesizer.h" +#import "NSString+AMTrick.h" + +NS_ASSUME_NONNULL_BEGIN + +static NSString * const kColonSymbol = @":"; +static NSString * const kDelimiterSymbols = @"/?&."; +static NSString * const kSeparatorSymbols = @"://"; + +@implementation AMUrlSchemeSynthesizer + +#pragma mark - Public + ++ (nullable NSString *)synthesizedStringWithPattern:(NSString *)pattern + replacements:(NSArray *)replacements { + if (!pattern.length || !replacements.count) { + return nil; + } + + NSMutableArray *tempReplacements = [replacements mutableCopy]; + + // failsafe check if it has a scheme part + NSArray *components = + [pattern componentsSeparatedByString:kSeparatorSymbols]; + + NSMutableArray *synthesizedStrings = [NSMutableArray array]; + + + void(^replacePlaceholder)(NSString * _Nonnull, NSArray * _Nonnull, BOOL * _Nonnull, BOOL * _Nonnull) = ^(NSString * _Nonnull stringWithPlaceholder, NSArray * _Nonnull matchedReplacements, BOOL * _Nonnull formatError, BOOL * _Nonnull stop) { + + NSString *actualComponent = [self stringByReplacingPlaceholdersInString:stringWithPlaceholder withReplacements:matchedReplacements]; + + if (!actualComponent.length) { + *stop = YES; + *formatError = YES; + return; + } + [synthesizedStrings addObject:actualComponent]; + }; + + __block BOOL formatError = NO; + + [components enumerateObjectsUsingBlock:^(NSString * _Nonnull stringComponent, NSUInteger idx, BOOL * _Nonnull stop) { + + if (![stringComponent containsString:kColonSymbol]) { + [synthesizedStrings addObject:stringComponent]; + } + else { + // TODO: still can optimize it by using loop count + if (idx == 0 && components.count == 2) { + replacePlaceholder(stringComponent, + @[ replacements[0] ], + &formatError, + stop); + [tempReplacements removeObjectAtIndex:0]; + } + else { + replacePlaceholder(stringComponent, + tempReplacements, + &formatError, + stop); + } + } + }]; + + + return formatError ? + nil : [synthesizedStrings componentsJoinedByString:kSeparatorSymbols]; +} + +#pragma mark - Private + ++ (nullable NSString *)stringByReplacingPlaceholdersInString:(NSString *)string + withReplacements:(const NSArray *)replacements { + + + NSUInteger count = [string am_countOfOccurrencesOfString:kColonSymbol]; + NSUInteger loopCount = replacements.count; + + if (loopCount == 0 || + loopCount != count) { + return nil; + } + + NSCharacterSet *delimiterCharacterSet = [NSCharacterSet characterSetWithCharactersInString:kDelimiterSymbols]; + + NSMutableString *mutableString = [string mutableCopy]; + + const NSRange wholeRange = NSMakeRange(0, string.length); + __block NSRange colonRange = NSMakeRange(0, 1); + __block NSRange searchRange = NSMakeRange(0, wholeRange.length); + __block NSRange replaceRange = NSMakeRange(0, 2); + __block NSUInteger delimiterSymbolRangeLocation = 1; + + __block BOOL formatError = NO; + + [replacements enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + + // failsafe there is a @"" in the replacements array + if (!obj.length) { + formatError = YES; + *stop = YES; + } + + colonRange = [mutableString rangeOfString:kColonSymbol]; + searchRange = NSMakeRange(NSMaxRange(colonRange), wholeRange.length); + searchRange = NSIntersectionRange(searchRange, wholeRange); + + + delimiterSymbolRangeLocation = + [mutableString rangeOfCharacterFromSet:delimiterCharacterSet + options:NSLiteralSearch + range:searchRange].location; + // the last placeholder is not end with delimiter symbols + if (delimiterSymbolRangeLocation == NSNotFound) { + delimiterSymbolRangeLocation = wholeRange.length; + } + replaceRange = + NSMakeRange(colonRange.location, delimiterSymbolRangeLocation); + + [mutableString replaceCharactersInRange:replaceRange withString:obj]; + + }]; + + return formatError ? nil : [mutableString copy]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/AMRouter/AMRouter/NSString+AMTrick.h b/AMRouter/AMRouter/NSString+AMTrick.h index 88f2de3..651cad0 100644 --- a/AMRouter/AMRouter/NSString+AMTrick.h +++ b/AMRouter/AMRouter/NSString+AMTrick.h @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN @interface NSString (AMTrick) -- (NSUInteger)countOfOccurrencesOfString:(NSString *)specSymbol; +- (NSUInteger)am_countOfOccurrencesOfString:(NSString *)specSymbol; @end diff --git a/AMRouter/AMRouter/NSString+AMTrick.m b/AMRouter/AMRouter/NSString+AMTrick.m index 6a55b23..8558178 100644 --- a/AMRouter/AMRouter/NSString+AMTrick.m +++ b/AMRouter/AMRouter/NSString+AMTrick.m @@ -12,7 +12,7 @@ @implementation NSString (AMTrick) -- (NSUInteger)countOfOccurrencesOfString:(NSString *)specSymbol { +- (NSUInteger)am_countOfOccurrencesOfString:(NSString *)specSymbol { if (!self.length) { return 0; } @@ -21,7 +21,8 @@ - (NSUInteger)countOfOccurrencesOfString:(NSString *)specSymbol { return 0; } - NSString *stringWithoutSymbol = [self stringByReplacingOccurrencesOfString:specSymbol withString:@""]; + NSString *stringWithoutSymbol = + [self stringByReplacingOccurrencesOfString:specSymbol withString:@""]; NSUInteger diff = self.length - stringWithoutSymbol.length; return diff; } diff --git a/AMRouterTests/AMComponentSpec.m b/AMRouterTests/AMComponentSpec.m index 511ab22..e47847b 100644 --- a/AMRouterTests/AMComponentSpec.m +++ b/AMRouterTests/AMComponentSpec.m @@ -16,7 +16,7 @@ QuickSpecBegin(AMComponentSpec) context(@"There is a component message", ^{ - it(@"should get notification status is YES", ^ { + it(@"should get notification status is YES", ^{ id obj = [AMComponent message]; expect(obj).to(beAKindOf([AMMessageComponent class])); @@ -25,7 +25,7 @@ }); - it(@"should release the target after invoke method -release...", ^ { + it(@"should release the target after invoke method -release...", ^{ id obj1 = [AMComponent message]; id obj2 = [AMComponent message]; @@ -45,7 +45,7 @@ expect(obj3).toNot(beIdenticalTo(obj4)); }); - it(@"register different class prefix", ^ { + it(@"register different class prefix", ^{ id amObj = [AMComponent message]; expect(amObj).to(beAKindOf([AMMessageComponent class])); @@ -65,12 +65,12 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnonnull" - it(@"if release target is nil, it will not crash", ^ { + it(@"if release target is nil, it will not crash", ^{ - expectAction(^ {[AMComponent releaseCachedTarget:nil];}).toNot(raiseException()); + expectAction(^{[AMComponent releaseCachedTarget:nil];}).toNot(raiseException()); }); - it(@"should return nil if target name is empty", ^ { + it(@"should return nil if target name is empty", ^{ id obj = [AMComponent targetWithName:@"" diff --git a/AMRouterTests/AMUrlSchemeSynthesizerSpec.m b/AMRouterTests/AMUrlSchemeSynthesizerSpec.m new file mode 100644 index 0000000..29e6c49 --- /dev/null +++ b/AMRouterTests/AMUrlSchemeSynthesizerSpec.m @@ -0,0 +1,62 @@ +// +// AMUrlSchemeSynthesizerSpec.m +// AMRouter +// +// Created by archmagees on 2018/06/10. +// Copyright © 2018 archmagees. All rights reserved. +// + +@import Quick; +@import Nimble; +#import "AMUrlSchemeSynthesizer.h" + +QuickSpecBegin(AMUrlSchemeSynthesizerSpec) + +context(@"there is template", ^{ + describe(@":scheme://:action", ^{ + it(@"should become umeng://login after convert", ^{ + NSString *string = + [AMUrlSchemeSynthesizer synthesizedStringWithPattern:@":scheme://:action" + replacements:@[ @"umeng", @"login" ]]; + + expect(string).to(contain(@"umeng://login")); + }); + }); + + describe(@"scheme://:action, but replacements is empty", ^{ + NSString *pattern = @"scheme://:action"; + it(@"should return nil", ^{ + NSString *string = + [AMUrlSchemeSynthesizer synthesizedStringWithPattern:pattern + replacements:@[ @"" ]]; + + expect(string).to(beNil()); + }); + + it(@"should become scheme://login", ^{ + NSString *string = + [AMUrlSchemeSynthesizer synthesizedStringWithPattern:pattern + replacements:@[ @"login" ]] ; + + expect(string).to(contain(@"scheme://login")); + }); + + it(@"return nil when replacements count not pair with pattern", ^{ + NSString *string = + [AMUrlSchemeSynthesizer synthesizedStringWithPattern:pattern + replacements:@[]]; + + expect(string).to(beNil()); + + string = + [AMUrlSchemeSynthesizer synthesizedStringWithPattern:pattern + replacements: + @[ @"", @"", @"" ]]; + + + }); + + }); +}); + +QuickSpecEnd diff --git a/AMRouterTests/NSStringAMTrickSpec.m b/AMRouterTests/NSStringAMTrickSpec.m new file mode 100644 index 0000000..f44222d --- /dev/null +++ b/AMRouterTests/NSStringAMTrickSpec.m @@ -0,0 +1,44 @@ +// +// NSStringAMTrickSpec.m +// AMRouter +// +// Created by archmagees on 2018/06/10. +// Copyright © 2018 archmagees. All rights reserved. +// + +@import Quick; +@import Nimble; +#import "NSString+AMTrick.h" + +QuickSpecBegin(NSStringAMTrickSpec) + +context(@"there is a string", ^{ + describe(@":action/:id?name=:nameid&", ^{ + it(@"should has 3 colon symbols", ^{ + NSString *string = @":action/:id?name=:nameid&"; + + NSUInteger count = [string am_countOfOccurrencesOfString:@":"]; + expect(count).to(equal(3)); + }); + }); + + describe(@"is empty", ^{ + + it(@"return value is 0", ^{ + NSString *string = @""; + NSUInteger count = [string am_countOfOccurrencesOfString:@":"]; + expect(count).to(equal(0)); + }); + }); + + describe(@":action", ^{ + + it(@"has zero count of @\"\"", ^{ + NSString *string = @":action"; + NSUInteger count = [string am_countOfOccurrencesOfString:@""]; + expect(count).to(equal(0)); + }); + }); +}); + +QuickSpecEnd diff --git a/AMRouterTests/NSStringExtensionMethodsSpec.m b/AMRouterTests/NSStringExtensionMethodsSpec.m index 6fd4213..0680092 100644 --- a/AMRouterTests/NSStringExtensionMethodsSpec.m +++ b/AMRouterTests/NSStringExtensionMethodsSpec.m @@ -15,15 +15,13 @@ NSString * const kColonSymbol = @":"; NSString * const kDelimiterSymbols = @"/?&."; -context(@"there is a string", ^{ +context(@"there is a string `:12345`", ^{ - __block NSString *url = nil; + NSString *url = @":12345"; - it(@":12345", ^ { - - url = @":12345"; - NSRange colonRange = [url rangeOfString:@":"]; + it(@"will be replaced to 09876", ^{ + NSRange colonRange = [url rangeOfString:kColonSymbol]; expect(colonRange.location).to(equal(0)); expect(colonRange.length).to(equal(1)); @@ -31,7 +29,7 @@ NSRange searchRange = NSMakeRange(NSMaxRange(colonRange), url.length); NSCharacterSet *delimiterCharacterSet = [NSCharacterSet characterSetWithCharactersInString:kDelimiterSymbols]; - expectAction(^ { + expectAction(^{ [url rangeOfCharacterFromSet:delimiterCharacterSet options:NSLiteralSearch range:searchRange]; @@ -56,8 +54,30 @@ expect(replacedUrl).to(contain(@"09876")); + }); + + describe(@"divided by string ://", ^{ + it(@"components count should be only 1", ^{ + + NSArray *components = [url componentsSeparatedByString:@"://"]; + + expect(components.count).to(equal(1)); + expect(components[0]).to(contain(url)); + + }); + }); + + describe(@"add it into an array and joined with a symbol", ^{ + it(@"", ^{ + NSArray *components = [url componentsSeparatedByString:@"://"]; + + NSString *synthesizedString = [components componentsJoinedByString:@"://"]; + + expect(synthesizedString).toNot(contain(@"://")); + }); }); + }); QuickSpecEnd diff --git a/AMRouterTests/NSURLQueryItemSpec.m b/AMRouterTests/NSURLQueryItemSpec.m index 7880d6e..7149f89 100644 --- a/AMRouterTests/NSURLQueryItemSpec.m +++ b/AMRouterTests/NSURLQueryItemSpec.m @@ -14,9 +14,9 @@ context(@"there is a url", ^{ - it(@"fabric://modulename/actionname/subaction.htm?key1=value1&222=value2&key1=value1", ^ { + it(@"fabric://modulename/actionname/subaction.htm?key1=value1&:222=value2&key1=value1", ^{ - NSString *url = @"fabric://modulename.com/v3/:actionname/:subaction.htm?key1=value1&222=value2&key1=:value1"; + NSString *url = @"fabric://modulename.com/v3/:actionname/:subaction.htm?key1=value1&:222=value2&key1=:value1"; NSURL *URL = [NSURL URLWithString:url]; expect(URL.scheme).to(contain(@"fabric")); @@ -35,7 +35,7 @@ NSLog(@"query items: %@", queryItems); expect(queryItems[0].name).to(contain(@"key1")); - expect(queryItems[1].name).to(contain(@"222")); + expect(queryItems[1].name).to(contain(@":222")); expect(queryItems[2].name).to(contain(@"key1")); expect(queryItems[2].value).to(contain(@":value1")); From ab972807e46fce92eda8a76de47ebd449d3d85e1 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 11 Jun 2018 17:18:42 +0800 Subject: [PATCH 4/7] :white_check_mark: add: more unit test in `NSURLQueryItemSpec` --- AMRouter.podspec | 3 + AMRouter.xcodeproj/project.pbxproj | 23 +++++- .../xcschemes/AMRouterTests.xcscheme | 1 + AMRouter/AMRouter/AMMacro.h | 52 +++++++++++++ AMRouter/AMRouter/AMUrlSchemeSynthesizer.h | 2 +- AMRouter/AMRouter/AMUrlSchemeSynthesizer.m | 20 ++--- .../Components/Message/AMMessageComponent.m | 10 ++- .../Message/MessageComponentInterface.h | 4 +- AMRouter/Components/Message/MessageModule.m | 10 ++- AMRouter/ViewController.m | 4 + AMRouterTests/AMComponentSpec.m | 11 +++ AMRouterTests/AMUrlSchemeSynthesizerSpec.m | 9 ++- AMRouterTests/NSURLQueryItemSpec.m | 76 ++++++++++++++----- Podfile | 1 + Podfile.lock | 10 ++- 15 files changed, 193 insertions(+), 43 deletions(-) create mode 100644 AMRouter/AMRouter/AMMacro.h diff --git a/AMRouter.podspec b/AMRouter.podspec index 36cff9d..a1e4dcd 100644 --- a/AMRouter.podspec +++ b/AMRouter.podspec @@ -1,3 +1,4 @@ +#!/usr/local/bin/ruby Pod::Spec.new do |s| s.name = 'AMRouter' s.module_name = 'AMRouter' @@ -15,4 +16,6 @@ Pod::Spec.new do |s| s.source_files = 'AMRouter/AMRouter/**/*.{h,m}' # s.vendored_framework = "Carthage/Build/iOS/AMRouter.framework" s.requires_arc = true + + s.dependency 'CocoaLumberjack', '~>3.4.2' end diff --git a/AMRouter.xcodeproj/project.pbxproj b/AMRouter.xcodeproj/project.pbxproj index a8736a4..3f444d3 100644 --- a/AMRouter.xcodeproj/project.pbxproj +++ b/AMRouter.xcodeproj/project.pbxproj @@ -43,6 +43,7 @@ 15739CBAC9C87DFC97D7132B /* Pods_AMRouter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AMRouter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 214DF5B71F3D612A1855B26E /* Pods-AMRouterTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AMRouterTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-AMRouterTests/Pods-AMRouterTests.release.xcconfig"; sourceTree = ""; }; 4D8F68259374D8D26C761A42 /* Pods-AMRouter.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AMRouter.release.xcconfig"; path = "Pods/Target Support Files/Pods-AMRouter/Pods-AMRouter.release.xcconfig"; sourceTree = ""; }; + 8E2199D020CE53A7006EDB02 /* AMMacro.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AMMacro.h; sourceTree = ""; }; 8EDB60C920C7C6BE00EB2CBA /* AMRouterTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AMRouterTests-Bridging-Header.h"; sourceTree = ""; }; 8EDB60CA20C7C6BE00EB2CBA /* SwiftSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftSpec.swift; sourceTree = ""; }; 8EDB60CC20C7C72900EB2CBA /* AMComponentSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AMComponentSpec.m; sourceTree = ""; }; @@ -76,7 +77,7 @@ 8EDC789A20C7C387001A3427 /* AMComponent+Message.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AMComponent+Message.m"; sourceTree = ""; }; 8EDC789B20C7C387001A3427 /* AMComponent+Message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AMComponent+Message.h"; sourceTree = ""; }; 8EDC789C20C7C387001A3427 /* MessageModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageModule.h; sourceTree = ""; }; - 8EDC789F20C7C551001A3427 /* AMRouter.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = AMRouter.podspec; sourceTree = ""; }; + 8EDC789F20C7C551001A3427 /* AMRouter.podspec */ = {isa = PBXFileReference; lastKnownFileType = text.script.ruby; path = AMRouter.podspec; sourceTree = ""; }; C4A5B7AE5C0D2F9AB7A03A6D /* Pods-AMRouterTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AMRouterTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AMRouterTests/Pods-AMRouterTests.debug.xcconfig"; sourceTree = ""; }; CC8985E85ACED1480D3FAFAB /* Pods-AMRouter.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AMRouter.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AMRouter/Pods-AMRouter.debug.xcconfig"; sourceTree = ""; }; D98CB695E91B9E9101246A87 /* Pods_AMRouterTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AMRouterTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -142,6 +143,7 @@ 8EDB612420CCF8CA00EB2CBA /* NSString+AMTrick.m */, 8EDB612820CD082600EB2CBA /* AMUrlSchemeSynthesizer.h */, 8EDB612920CD082600EB2CBA /* AMUrlSchemeSynthesizer.m */, + 8E2199D020CE53A7006EDB02 /* AMMacro.h */, ); path = AMRouter; sourceTree = ""; @@ -231,6 +233,7 @@ 8EDC786620C7C294001A3427 /* Sources */, 8EDC786720C7C294001A3427 /* Frameworks */, 8EDC786820C7C294001A3427 /* Resources */, + E0537F1D35AF7BA575B385FC /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -378,6 +381,24 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; + E0537F1D35AF7BA575B385FC /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-AMRouter/Pods-AMRouter-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CocoaLumberjack.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AMRouter/Pods-AMRouter-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/AMRouter.xcodeproj/xcshareddata/xcschemes/AMRouterTests.xcscheme b/AMRouter.xcodeproj/xcshareddata/xcschemes/AMRouterTests.xcscheme index e80341a..a290a2b 100644 --- a/AMRouter.xcodeproj/xcshareddata/xcschemes/AMRouterTests.xcscheme +++ b/AMRouter.xcodeproj/xcshareddata/xcschemes/AMRouterTests.xcscheme @@ -40,6 +40,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + codeCoverageEnabled = "YES" shouldUseLaunchSchemeArgsEnv = "YES"> + + +//#if __has_include() +// #import +// +// #ifdef DEBUG +// +// #undef LOG_LEVEL_DEF +// #define LOG_LEVEL_DEF AMRouterLogLevel +// +//#pragma clang diagnostic push +//#pragma clang diagnostic ignored "-Wunused-const-variable" +// +// #define AMSetDDLogLevel(debugDDLogLevel, noDebugDDLogLevel) \ +// static const DDLogLevel AMRouterLogLevel = debugDDLogLevel; \ +// DDLogLevel AMRouterLogLevelUnused = noDebugDDLogLevel; +// +//#pragma clang diagnostic pop +// +// #else +// +// #undef LOG_LEVEL_DEF +// #define LOG_LEVEL_DEF AMRouterLogLevel +// +// #define AMSetDDLogLevel(debugDDLogLevel, noDebugDDLogLevel) \ +// DDLogLevel AMRouterLogLevelUnused = debugDDLogLevel; \ +// static const DDLogLevel AMRouterLogLevel = noDebugDDLogLevel; +// +// #endif +// +//#endif +// +// +//#if __has_include() +//#else +//#pragma clang diagnostic push +//#pragma clang diagnostic ignored "-Wunused-const-variable" +// +// #define AMSetDDLogLevel(debugDDLogLevelNoEffect, noDebugDDLogLevelNoEffect) +// +//#pragma clang diagnostic pop +// +//#endif diff --git a/AMRouter/AMRouter/AMUrlSchemeSynthesizer.h b/AMRouter/AMRouter/AMUrlSchemeSynthesizer.h index 617fbca..469702f 100644 --- a/AMRouter/AMRouter/AMUrlSchemeSynthesizer.h +++ b/AMRouter/AMRouter/AMUrlSchemeSynthesizer.h @@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN * @discussion * Pattern format is just like the url components. That is: * `scheme://host/path.pathextension?query#fragment`, and usually the pattern - * format is passed as `:action?key1=:value1&key2=:value2`. + * format is passed as `:scheme://:action?key1=:value1&key2=:value2`. * * @param pattern * A string value indicates the template format. diff --git a/AMRouter/AMRouter/AMUrlSchemeSynthesizer.m b/AMRouter/AMRouter/AMUrlSchemeSynthesizer.m index d632246..bade8b1 100644 --- a/AMRouter/AMRouter/AMUrlSchemeSynthesizer.m +++ b/AMRouter/AMRouter/AMUrlSchemeSynthesizer.m @@ -94,12 +94,6 @@ + (nullable NSString *)stringByReplacingPlaceholdersInString:(NSString *)string NSMutableString *mutableString = [string mutableCopy]; - const NSRange wholeRange = NSMakeRange(0, string.length); - __block NSRange colonRange = NSMakeRange(0, 1); - __block NSRange searchRange = NSMakeRange(0, wholeRange.length); - __block NSRange replaceRange = NSMakeRange(0, 2); - __block NSUInteger delimiterSymbolRangeLocation = 1; - __block BOOL formatError = NO; [replacements enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { @@ -109,13 +103,15 @@ + (nullable NSString *)stringByReplacingPlaceholdersInString:(NSString *)string formatError = YES; *stop = YES; } + NSRange wholeRange = NSMakeRange(0, mutableString.length); - colonRange = [mutableString rangeOfString:kColonSymbol]; - searchRange = NSMakeRange(NSMaxRange(colonRange), wholeRange.length); + NSRange colonRange = [mutableString rangeOfString:kColonSymbol]; + NSRange searchRange = NSMakeRange(NSMaxRange(colonRange), wholeRange.length); + // failsafe, otherwise it will crash because of the length is out of + // the bound searchRange = NSIntersectionRange(searchRange, wholeRange); - - delimiterSymbolRangeLocation = + NSUInteger delimiterSymbolRangeLocation = [mutableString rangeOfCharacterFromSet:delimiterCharacterSet options:NSLiteralSearch range:searchRange].location; @@ -123,11 +119,11 @@ + (nullable NSString *)stringByReplacingPlaceholdersInString:(NSString *)string if (delimiterSymbolRangeLocation == NSNotFound) { delimiterSymbolRangeLocation = wholeRange.length; } - replaceRange = + NSRange replaceRange = NSMakeRange(colonRange.location, delimiterSymbolRangeLocation); + replaceRange = NSIntersectionRange(replaceRange, wholeRange); [mutableString replaceCharactersInRange:replaceRange withString:obj]; - }]; return formatError ? nil : [mutableString copy]; diff --git a/AMRouter/Components/Message/AMMessageComponent.m b/AMRouter/Components/Message/AMMessageComponent.m index 9c2c2d6..74d427f 100644 --- a/AMRouter/Components/Message/AMMessageComponent.m +++ b/AMRouter/Components/Message/AMMessageComponent.m @@ -8,14 +8,20 @@ #import "AMMessageComponent.h" +static NSUInteger unreadCount = 999; + @implementation AMMessageComponent - (BOOL)notificationEnabled { return NO; } -- (NSInteger)unreadCount { - return 999; +- (NSUInteger)unreadCount { + return unreadCount; +} + +- (void)increaseUnreadCount:(NSInteger)count { + unreadCount += count; } @end diff --git a/AMRouter/Components/Message/MessageComponentInterface.h b/AMRouter/Components/Message/MessageComponentInterface.h index d82b93a..b84979f 100644 --- a/AMRouter/Components/Message/MessageComponentInterface.h +++ b/AMRouter/Components/Message/MessageComponentInterface.h @@ -14,6 +14,8 @@ - (BOOL)notificationEnabled; -- (NSInteger)unreadCount; +- (NSUInteger)unreadCount; + +- (void)increaseUnreadCount:(NSInteger)count; @end diff --git a/AMRouter/Components/Message/MessageModule.m b/AMRouter/Components/Message/MessageModule.m index 94b0e6a..6952ca6 100644 --- a/AMRouter/Components/Message/MessageModule.m +++ b/AMRouter/Components/Message/MessageModule.m @@ -8,14 +8,20 @@ #import "MessageModule.h" +static NSUInteger unreadCount = 3; + @implementation MessageModule - (BOOL)notificationEnabled { return YES; } -- (NSInteger)unreadCount { - return 3; +- (NSUInteger)unreadCount { + return unreadCount; +} + +- (void)increaseUnreadCount:(NSInteger)count { + unreadCount += count; } @end diff --git a/AMRouter/ViewController.m b/AMRouter/ViewController.m index f832bde..6d4a991 100644 --- a/AMRouter/ViewController.m +++ b/AMRouter/ViewController.m @@ -23,7 +23,11 @@ - (void)viewDidLoad { NSInteger count = [[AMComponent message] unreadCount]; + [AMComponent message] + + NSLog(@"is notification enabled: %@", @(count)); + } diff --git a/AMRouterTests/AMComponentSpec.m b/AMRouterTests/AMComponentSpec.m index e47847b..51fc065 100644 --- a/AMRouterTests/AMComponentSpec.m +++ b/AMRouterTests/AMComponentSpec.m @@ -84,6 +84,17 @@ #pragma clang diagnostic pop + it(@"increase unread count 3", ^{ + id obj = [AMComponent message]; + + expect(obj.unreadCount).to(equal(999)); + + [obj increaseUnreadCount:1]; + expect(obj.unreadCount).to(equal(1000)); + + }); + + }); QuickSpecEnd diff --git a/AMRouterTests/AMUrlSchemeSynthesizerSpec.m b/AMRouterTests/AMUrlSchemeSynthesizerSpec.m index 29e6c49..3f7d159 100644 --- a/AMRouterTests/AMUrlSchemeSynthesizerSpec.m +++ b/AMRouterTests/AMUrlSchemeSynthesizerSpec.m @@ -13,13 +13,13 @@ QuickSpecBegin(AMUrlSchemeSynthesizerSpec) context(@"there is template", ^{ - describe(@":scheme://:action", ^{ + describe(@":scheme://:action?id=:id", ^{ it(@"should become umeng://login after convert", ^{ NSString *string = - [AMUrlSchemeSynthesizer synthesizedStringWithPattern:@":scheme://:action" - replacements:@[ @"umeng", @"login" ]]; + [AMUrlSchemeSynthesizer synthesizedStringWithPattern:@":scheme://:action?id=:id" + replacements:@[ @"umeng", @"login", @"123" ]]; - expect(string).to(contain(@"umeng://login")); + expect(string).to(contain(@"umeng://login?id=123")); }); }); @@ -41,6 +41,7 @@ expect(string).to(contain(@"scheme://login")); }); + it(@"return nil when replacements count not pair with pattern", ^{ NSString *string = [AMUrlSchemeSynthesizer synthesizedStringWithPattern:pattern diff --git a/AMRouterTests/NSURLQueryItemSpec.m b/AMRouterTests/NSURLQueryItemSpec.m index 7149f89..e7eed40 100644 --- a/AMRouterTests/NSURLQueryItemSpec.m +++ b/AMRouterTests/NSURLQueryItemSpec.m @@ -12,36 +12,74 @@ QuickSpecBegin(NSURLQueryItemSpec) -context(@"there is a url", ^{ +context(@"url", ^{ - it(@"fabric://modulename/actionname/subaction.htm?key1=value1&:222=value2&key1=value1", ^{ + describe(@"has triple slash symobl", ^{ + NSString *tripleSlashUrl = @"fabric:///mission/login?id=:id"; + NSURL *URL = [NSURL URLWithString:tripleSlashUrl]; + it(@"host will become nil", ^{ + expect(URL.host).to(beNil()); + expect(URL.path).to(contain(@"login")); + expect(URL.pathComponents).to(contain(@"mission")); + }); - NSString *url = @"fabric://modulename.com/v3/:actionname/:subaction.htm?key1=value1&:222=value2&key1=:value1"; + }); + + describe(@"which format is normal", ^{ + // + NSString *url = @"fabric://modulename.com/modulename.com2/v3/:actionname/:subaction.htm?key1=value1&:222=value2&key1=:value1"; NSURL *URL = [NSURL URLWithString:url]; - expect(URL.scheme).to(contain(@"fabric")); - expect(URL.host).to(contain(@"modulename.com")); - expect(URL.path).to(contain(@"v3/:actionname/:subaction")); - expect(URL.pathExtension).to(contain(@"htm")); - - NSArray *queryItems = - [[NSURLComponents alloc] initWithURL:URL - resolvingAgainstBaseURL:NO].queryItems; - - [queryItems enumerateObjectsUsingBlock:^(NSURLQueryItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + it(url, ^{ + + expect(URL.scheme).to(contain(@"fabric")); + expect(URL.host).to(contain(@"modulename.com")); + expect(URL.path).to(contain(@"modulename.com2/v3/:actionname/:subaction")); + expect(URL.pathExtension).to(contain(@"htm")); + + NSArray *queryItems = + [[NSURLComponents alloc] initWithURL:URL + resolvingAgainstBaseURL:NO].queryItems; + + [queryItems enumerateObjectsUsingBlock:^(NSURLQueryItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + + }]; + + NSLog(@"query items: %@", queryItems); - }]; + expect(queryItems[0].name).to(contain(@"key1")); + expect(queryItems[1].name).to(contain(@":222")); + expect(queryItems[2].name).to(contain(@"key1")); + + expect(queryItems[2].value).to(contain(@":value1")); + + }); - NSLog(@"query items: %@", queryItems); + it(@"path components should not contain query items", ^{ + NSArray *pathComponents = URL.pathComponents; + + expect(pathComponents).to(contain(@":subaction.htm")); + expect(pathComponents).toNot(contain(@"key1")); + expect(pathComponents).toNot(contain(@"?")); + expect(pathComponents).toNot(contain(@"value")); + + }); - expect(queryItems[0].name).to(contain(@"key1")); - expect(queryItems[1].name).to(contain(@":222")); - expect(queryItems[2].name).to(contain(@"key1")); + it(@"first element in path components is slash", ^{ + expect(URL.pathComponents[0]).to(contain(@"/")); + }); - expect(queryItems[2].value).to(contain(@":value1")); + it(@"has not host string in path components", ^{ + // first one will be replaced to "/", if url has only 2 slash + expect(URL.pathComponents).toNot(contain(@"modulename.com")); + }); }); + + + + }); QuickSpecEnd diff --git a/Podfile b/Podfile index c2f1454..cdc5e33 100644 --- a/Podfile +++ b/Podfile @@ -5,6 +5,7 @@ use_frameworks! target 'AMRouter' do + pod 'CocoaLumberjack', '~>3.4.2' target 'AMRouterTests' do inherit! :search_paths diff --git a/Podfile.lock b/Podfile.lock index 22d117e..58bd55b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,9 +1,16 @@ PODS: + - CocoaLumberjack (3.4.2): + - CocoaLumberjack/Default (= 3.4.2) + - CocoaLumberjack/Extensions (= 3.4.2) + - CocoaLumberjack/Default (3.4.2) + - CocoaLumberjack/Extensions (3.4.2): + - CocoaLumberjack/Default - Nimble (7.1.2) - OCMock (3.4.1) - Quick (1.3.0) DEPENDENCIES: + - CocoaLumberjack - Nimble (from `https://github.com/Quick/Nimble.git`) - OCMock (from `https://github.com/erikdoe/ocmock.git`) - Quick (from `https://github.com/Quick/Quick.git`) @@ -28,11 +35,12 @@ CHECKOUT OPTIONS: :git: https://github.com/Quick/Quick.git SPEC CHECKSUMS: + CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd Nimble: 4475e230ee4219b6c1e39044086c71249c6a039e OCMock: 2cd0716969bab32a2283ff3a46fd26a8c8b4c5e3 Quick: 37db81a2d4473d9f369136032768c341a2e0c03c -PODFILE CHECKSUM: 4b773f49e6c91372c6657d7354c7a5ddfd88f00e +PODFILE CHECKSUM: 35b9f396d3af09fa71df891429aa07a525eea8f5 COCOAPODS: 1.5.3 From 48a299a40a048de72c2444b36fd5fd24374022f9 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 23 Jul 2018 10:42:44 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=9A=9A=20[Chore]=20move=20and=20renam?= =?UTF-8?q?e=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AMRouter.xcodeproj/project.pbxproj | 58 ++++++++++++++++--- AMRouter/AMRouter/AMComponent.m | 2 +- AMRouter/AMRouter/AMRouter-Bridging-Header.h | 4 ++ AMRouter/AMRouter/Component.swift | 15 +++++ .../{ => Interface}/AMComponent+Message.h | 2 +- .../{ => Interface}/AMComponent+Message.m | 0 .../MessageComponentInterface.h | 0 .../Message/{ => PodA}/MessageModule.h | 0 .../Message/{ => PodA}/MessageModule.m | 0 .../Message/{ => PodB}/AMMessageComponent.h | 0 .../Message/{ => PodB}/AMMessageComponent.m | 1 + AMRouter/ViewController.m | 3 +- AMRouterTests/AMUrlSchemeSynthesizerSpec.m | 3 +- AMRouterTests/NSDictionarySpec.m | 35 +++++++++++ AMRouterTests/NSURLQueryItemSpec.m | 15 +++++ Gemfile.lock | 4 +- 16 files changed, 129 insertions(+), 13 deletions(-) create mode 100644 AMRouter/AMRouter/AMRouter-Bridging-Header.h create mode 100644 AMRouter/AMRouter/Component.swift rename AMRouter/Components/Message/{ => Interface}/AMComponent+Message.h (85%) rename AMRouter/Components/Message/{ => Interface}/AMComponent+Message.m (100%) rename AMRouter/Components/Message/{ => Interface}/MessageComponentInterface.h (100%) rename AMRouter/Components/Message/{ => PodA}/MessageModule.h (100%) rename AMRouter/Components/Message/{ => PodA}/MessageModule.m (100%) rename AMRouter/Components/Message/{ => PodB}/AMMessageComponent.h (100%) rename AMRouter/Components/Message/{ => PodB}/AMMessageComponent.m (98%) create mode 100644 AMRouterTests/NSDictionarySpec.m diff --git a/AMRouter.xcodeproj/project.pbxproj b/AMRouter.xcodeproj/project.pbxproj index 3f444d3..872302a 100644 --- a/AMRouter.xcodeproj/project.pbxproj +++ b/AMRouter.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 08487ED26C85DCE8CD12A028 /* Pods_AMRouter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15739CBAC9C87DFC97D7132B /* Pods_AMRouter.framework */; }; 20EB12DE1B6F47335102123D /* Pods_AMRouterTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D98CB695E91B9E9101246A87 /* Pods_AMRouterTests.framework */; }; + 8E2199D420CEBEF0006EDB02 /* NSDictionarySpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E2199D320CEBEEF006EDB02 /* NSDictionarySpec.m */; }; + 8EC78B542101F71600C8DEA7 /* Component.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EC78B532101F71600C8DEA7 /* Component.swift */; }; 8EDB60CB20C7C6BE00EB2CBA /* SwiftSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB60CA20C7C6BE00EB2CBA /* SwiftSpec.swift */; }; 8EDB60CD20C7C72900EB2CBA /* AMComponentSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB60CC20C7C72900EB2CBA /* AMComponentSpec.m */; }; 8EDB60D220C7D3FE00EB2CBA /* AMComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EDB60D120C7D3FE00EB2CBA /* AMComponent.m */; }; @@ -44,6 +46,9 @@ 214DF5B71F3D612A1855B26E /* Pods-AMRouterTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AMRouterTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-AMRouterTests/Pods-AMRouterTests.release.xcconfig"; sourceTree = ""; }; 4D8F68259374D8D26C761A42 /* Pods-AMRouter.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AMRouter.release.xcconfig"; path = "Pods/Target Support Files/Pods-AMRouter/Pods-AMRouter.release.xcconfig"; sourceTree = ""; }; 8E2199D020CE53A7006EDB02 /* AMMacro.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AMMacro.h; sourceTree = ""; }; + 8E2199D320CEBEEF006EDB02 /* NSDictionarySpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSDictionarySpec.m; sourceTree = ""; }; + 8EC78B522101F71600C8DEA7 /* AMRouter-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AMRouter-Bridging-Header.h"; sourceTree = ""; }; + 8EC78B532101F71600C8DEA7 /* Component.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Component.swift; sourceTree = ""; }; 8EDB60C920C7C6BE00EB2CBA /* AMRouterTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AMRouterTests-Bridging-Header.h"; sourceTree = ""; }; 8EDB60CA20C7C6BE00EB2CBA /* SwiftSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftSpec.swift; sourceTree = ""; }; 8EDB60CC20C7C72900EB2CBA /* AMComponentSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AMComponentSpec.m; sourceTree = ""; }; @@ -123,6 +128,34 @@ name = Pods; sourceTree = ""; }; + 8E51B35220E4B57000F706FF /* Interface */ = { + isa = PBXGroup; + children = ( + 8EDC789820C7C387001A3427 /* MessageComponentInterface.h */, + 8EDC789B20C7C387001A3427 /* AMComponent+Message.h */, + 8EDC789A20C7C387001A3427 /* AMComponent+Message.m */, + ); + path = Interface; + sourceTree = ""; + }; + 8E51B35320E4B57600F706FF /* PodA */ = { + isa = PBXGroup; + children = ( + 8EDC789C20C7C387001A3427 /* MessageModule.h */, + 8EDC789920C7C387001A3427 /* MessageModule.m */, + ); + path = PodA; + sourceTree = ""; + }; + 8E51B35420E4B58100F706FF /* PodB */ = { + isa = PBXGroup; + children = ( + 8EDB60D320C7EEA800EB2CBA /* AMMessageComponent.h */, + 8EDB60D420C7EEA800EB2CBA /* AMMessageComponent.m */, + ); + path = PodB; + sourceTree = ""; + }; 8EDB60C820C7C68D00EB2CBA /* Misc */ = { isa = PBXGroup; children = ( @@ -144,6 +177,8 @@ 8EDB612820CD082600EB2CBA /* AMUrlSchemeSynthesizer.h */, 8EDB612920CD082600EB2CBA /* AMUrlSchemeSynthesizer.m */, 8E2199D020CE53A7006EDB02 /* AMMacro.h */, + 8EC78B532101F71600C8DEA7 /* Component.swift */, + 8EC78B522101F71600C8DEA7 /* AMRouter-Bridging-Header.h */, ); path = AMRouter; sourceTree = ""; @@ -196,6 +231,7 @@ 8EDB612120CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m */, 8EDB612620CCFB4700EB2CBA /* NSStringAMTrickSpec.m */, 8EDB612B20CD2D0500EB2CBA /* AMUrlSchemeSynthesizerSpec.m */, + 8E2199D320CEBEEF006EDB02 /* NSDictionarySpec.m */, ); path = AMRouterTests; sourceTree = ""; @@ -211,13 +247,9 @@ 8EDC789720C7C387001A3427 /* Message */ = { isa = PBXGroup; children = ( - 8EDC789820C7C387001A3427 /* MessageComponentInterface.h */, - 8EDC789B20C7C387001A3427 /* AMComponent+Message.h */, - 8EDC789A20C7C387001A3427 /* AMComponent+Message.m */, - 8EDC789C20C7C387001A3427 /* MessageModule.h */, - 8EDC789920C7C387001A3427 /* MessageModule.m */, - 8EDB60D320C7EEA800EB2CBA /* AMMessageComponent.h */, - 8EDB60D420C7EEA800EB2CBA /* AMMessageComponent.m */, + 8E51B35220E4B57000F706FF /* Interface */, + 8E51B35320E4B57600F706FF /* PodA */, + 8E51B35420E4B58100F706FF /* PodB */, ); path = Message; sourceTree = ""; @@ -275,6 +307,7 @@ TargetAttributes = { 8EDC786920C7C294001A3427 = { CreatedOnToolsVersion = 9.3; + LastSwiftMigration = 0940; }; 8EDC788120C7C296001A3427 = { CreatedOnToolsVersion = 9.3; @@ -415,6 +448,7 @@ 8EDB60D220C7D3FE00EB2CBA /* AMComponent.m in Sources */, 8EDC786F20C7C294001A3427 /* AppDelegate.m in Sources */, 8EDC789E20C7C387001A3427 /* AMComponent+Message.m in Sources */, + 8EC78B542101F71600C8DEA7 /* Component.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -426,6 +460,7 @@ 8EDB60CD20C7C72900EB2CBA /* AMComponentSpec.m in Sources */, 8EDB612C20CD2D0500EB2CBA /* AMUrlSchemeSynthesizerSpec.m in Sources */, 8EDB612220CA9ADC00EB2CBA /* NSStringExtensionMethodsSpec.m in Sources */, + 8E2199D420CEBEF0006EDB02 /* NSDictionarySpec.m in Sources */, 8EDB612020CA68E700EB2CBA /* NSURLQueryItemSpec.m in Sources */, 8EDB60CB20C7C6BE00EB2CBA /* SwiftSpec.swift in Sources */, ); @@ -576,6 +611,7 @@ baseConfigurationReference = CC8985E85ACED1480D3FAFAB /* Pods-AMRouter.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = P82ZK576JR; INFOPLIST_FILE = AMRouter/Info.plist; @@ -586,6 +622,9 @@ ); PRODUCT_BUNDLE_IDENTIFIER = io.archmagees.AMRouter; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "AMRouter/AMRouter/AMRouter-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -595,6 +634,7 @@ baseConfigurationReference = 4D8F68259374D8D26C761A42 /* Pods-AMRouter.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = P82ZK576JR; INFOPLIST_FILE = AMRouter/Info.plist; @@ -605,6 +645,8 @@ ); PRODUCT_BUNDLE_IDENTIFIER = io.archmagees.AMRouter; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "AMRouter/AMRouter/AMRouter-Bridging-Header.h"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -613,6 +655,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = C4A5B7AE5C0D2F9AB7A03A6D /* Pods-AMRouterTests.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; @@ -637,6 +680,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 214DF5B71F3D612A1855B26E /* Pods-AMRouterTests.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; diff --git a/AMRouter/AMRouter/AMComponent.m b/AMRouter/AMRouter/AMComponent.m index c74f20a..2fc2a1e 100644 --- a/AMRouter/AMRouter/AMComponent.m +++ b/AMRouter/AMRouter/AMComponent.m @@ -86,7 +86,7 @@ - (nullable id)targetForKey:(NSString *)key dispatch_sync(operate_target_queue, ^{ dispatch_semaphore_wait(self->target_semaphore, - DISPATCH_TIME_NOW); + dispatch_time(DISPATCH_TIME_NOW, 3)); target = [self.cachedTargets objectForKey:key]; diff --git a/AMRouter/AMRouter/AMRouter-Bridging-Header.h b/AMRouter/AMRouter/AMRouter-Bridging-Header.h new file mode 100644 index 0000000..1b2cb5d --- /dev/null +++ b/AMRouter/AMRouter/AMRouter-Bridging-Header.h @@ -0,0 +1,4 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + diff --git a/AMRouter/AMRouter/Component.swift b/AMRouter/AMRouter/Component.swift new file mode 100644 index 0000000..0652bc4 --- /dev/null +++ b/AMRouter/AMRouter/Component.swift @@ -0,0 +1,15 @@ +// +// Component.swift +// AMRouter +// +// Created by archmagees on 2018/07/20. +// Copyright © 2018 archmagees. All rights reserved. +// + +import UIKit +import Foundation + +@objc +class Component: NSObject { + +} diff --git a/AMRouter/Components/Message/AMComponent+Message.h b/AMRouter/Components/Message/Interface/AMComponent+Message.h similarity index 85% rename from AMRouter/Components/Message/AMComponent+Message.h rename to AMRouter/Components/Message/Interface/AMComponent+Message.h index 4d6ca0d..efb58e0 100644 --- a/AMRouter/Components/Message/AMComponent+Message.h +++ b/AMRouter/Components/Message/Interface/AMComponent+Message.h @@ -13,6 +13,6 @@ @interface AMComponent (Message) + (id)message; -+ (id)messageModule; +//+ (id)messageModule; @end diff --git a/AMRouter/Components/Message/AMComponent+Message.m b/AMRouter/Components/Message/Interface/AMComponent+Message.m similarity index 100% rename from AMRouter/Components/Message/AMComponent+Message.m rename to AMRouter/Components/Message/Interface/AMComponent+Message.m diff --git a/AMRouter/Components/Message/MessageComponentInterface.h b/AMRouter/Components/Message/Interface/MessageComponentInterface.h similarity index 100% rename from AMRouter/Components/Message/MessageComponentInterface.h rename to AMRouter/Components/Message/Interface/MessageComponentInterface.h diff --git a/AMRouter/Components/Message/MessageModule.h b/AMRouter/Components/Message/PodA/MessageModule.h similarity index 100% rename from AMRouter/Components/Message/MessageModule.h rename to AMRouter/Components/Message/PodA/MessageModule.h diff --git a/AMRouter/Components/Message/MessageModule.m b/AMRouter/Components/Message/PodA/MessageModule.m similarity index 100% rename from AMRouter/Components/Message/MessageModule.m rename to AMRouter/Components/Message/PodA/MessageModule.m diff --git a/AMRouter/Components/Message/AMMessageComponent.h b/AMRouter/Components/Message/PodB/AMMessageComponent.h similarity index 100% rename from AMRouter/Components/Message/AMMessageComponent.h rename to AMRouter/Components/Message/PodB/AMMessageComponent.h diff --git a/AMRouter/Components/Message/AMMessageComponent.m b/AMRouter/Components/Message/PodB/AMMessageComponent.m similarity index 98% rename from AMRouter/Components/Message/AMMessageComponent.m rename to AMRouter/Components/Message/PodB/AMMessageComponent.m index 74d427f..4a95b68 100644 --- a/AMRouter/Components/Message/AMMessageComponent.m +++ b/AMRouter/Components/Message/PodB/AMMessageComponent.m @@ -21,6 +21,7 @@ - (NSUInteger)unreadCount { } - (void)increaseUnreadCount:(NSInteger)count { + unreadCount += count; } diff --git a/AMRouter/ViewController.m b/AMRouter/ViewController.m index 6d4a991..960fa33 100644 --- a/AMRouter/ViewController.m +++ b/AMRouter/ViewController.m @@ -22,8 +22,9 @@ - (void)viewDidLoad { NSInteger count = [[AMComponent message] unreadCount]; + [[AMComponent message] unreadCount]; - [AMComponent message] + [AMComponent message] NSLog(@"is notification enabled: %@", @(count)); diff --git a/AMRouterTests/AMUrlSchemeSynthesizerSpec.m b/AMRouterTests/AMUrlSchemeSynthesizerSpec.m index 3f7d159..d646b40 100644 --- a/AMRouterTests/AMUrlSchemeSynthesizerSpec.m +++ b/AMRouterTests/AMUrlSchemeSynthesizerSpec.m @@ -38,7 +38,7 @@ [AMUrlSchemeSynthesizer synthesizedStringWithPattern:pattern replacements:@[ @"login" ]] ; - expect(string).to(contain(@"scheme://login")); + expect(string).to(match(@"scheme://login")); }); @@ -54,6 +54,7 @@ replacements: @[ @"", @"", @"" ]]; + expect(string).to(beNil()); }); diff --git a/AMRouterTests/NSDictionarySpec.m b/AMRouterTests/NSDictionarySpec.m new file mode 100644 index 0000000..f2cebcf --- /dev/null +++ b/AMRouterTests/NSDictionarySpec.m @@ -0,0 +1,35 @@ +// +// NSDictionarySpec.m +// AMRouter +// +// Created by archmagees on 2018/06/11. +// Copyright © 2018 archmagees. All rights reserved. +// + +@import Quick; +@import Nimble; +@import Foundation; + +QuickSpecBegin(NSDictionarySpec) + +context(@"dictionary has multi level key values", ^{ + describe(@"one key's value is also a dictionary", ^{ + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + [dict addEntriesFromDictionary: + @{ + @"1" : @{ + @"2" : @"999", + @"_" : @"xyz" + }, + @"_" : @"abc" + }]; + + it(@"keys array should has not 4 elements", ^{ + expect(dict.allKeys.count).toNot(equal(4)); + expect(dict.allValues).toNot(contain(@"xyz")); + + }); + }); +}); + +QuickSpecEnd diff --git a/AMRouterTests/NSURLQueryItemSpec.m b/AMRouterTests/NSURLQueryItemSpec.m index e7eed40..3938c5d 100644 --- a/AMRouterTests/NSURLQueryItemSpec.m +++ b/AMRouterTests/NSURLQueryItemSpec.m @@ -76,6 +76,21 @@ }); + describe(@"without scheme part", ^{ + + it(@"path components should contain host part", ^{ + NSString *urlStringWithoutScheme = @"mission/login?id=:id"; + NSURL *URL = [NSURL URLWithString:urlStringWithoutScheme]; + expect(URL.pathComponents).to(contain(@"mission")); + expect(URL.pathComponents).toNot(contain(@"/")); + expect(URL.pathComponents[0]).to(contain(@"mission")); + expect(URL.pathComponents[0]).toNot(contain(@"/")); + + }); + + + }); + diff --git a/Gemfile.lock b/Gemfile.lock index 60da5ca..64a649f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -164,7 +164,7 @@ GEM declarative (< 0.1.0) declarative-option (< 0.2.0) uber (< 0.2.0) - retriable (3.1.1) + retriable (3.1.2) rouge (2.0.7) ruby-macho (1.2.0) rubyzip (1.2.1) @@ -209,7 +209,7 @@ GEM unf_ext (0.0.7.5) unicode-display_width (1.4.0) word_wrap (1.0.0) - xcode-install (2.4.0) + xcode-install (2.4.1) claide (>= 0.9.1, < 1.1.0) fastlane (>= 2.1.0, < 3.0.0) xcodeproj (1.5.9) From b561584a5af862bc32882b0320b35099b05f41b3 Mon Sep 17 00:00:00 2001 From: archmagees Date: Thu, 28 Nov 2019 21:40:21 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=94=A7=20=F0=9F=92=8E=20Update=20Gemf?= =?UTF-8?q?ile=20and=20Podfile=20and=20swift=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ⬆️ Update `swift` version to `5.0` in all targets. - ⬆️ Update Gemfile and Gemfile.lock. - ⬆️ Update `Podfile`. --- AMRouter.podspec | 4 +- AMRouter.xcodeproj/project.pbxproj | 40 ++-- .../xcshareddata/WorkspaceSettings.xcsettings | 8 + AMRouter/ViewController.m | 3 - Gemfile | 6 +- Gemfile.lock | 217 ++++++++++-------- Podfile | 24 +- Podfile.lock | 42 ++-- 8 files changed, 177 insertions(+), 167 deletions(-) create mode 100644 AMRouter.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/AMRouter.podspec b/AMRouter.podspec index a1e4dcd..3ec9131 100644 --- a/AMRouter.podspec +++ b/AMRouter.podspec @@ -2,14 +2,14 @@ Pod::Spec.new do |s| s.name = 'AMRouter' s.module_name = 'AMRouter' - s.version = '0.3.0' + s.version = '0.4.0' s.summary = 'AMRouter' s.description = <<-DESC This is AMRouter. DESC s.homepage = 'https://github.com/archmagees/AMRouter' s.license = { :type => 'MIT', :file => 'LICENSE' } - s.author = { 'Arthur' => 'archmagees@gmail.com' } + s.author = { 'Arthur' => 'archmagees.dev@gmail.com' } s.platform = :ios, '9.0' s.swift_version = '4.1' s.source = { :git => 'https://github.com/archmagees/AMRouter.git', :tag => s.version.to_s } diff --git a/AMRouter.xcodeproj/project.pbxproj b/AMRouter.xcodeproj/project.pbxproj index 872302a..4f04de9 100644 --- a/AMRouter.xcodeproj/project.pbxproj +++ b/AMRouter.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ @@ -379,21 +379,16 @@ buildActionMask = 2147483647; files = ( ); - inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-AMRouterTests/Pods-AMRouterTests-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework", - "${BUILT_PRODUCTS_DIR}/OCMock/OCMock.framework", - "${BUILT_PRODUCTS_DIR}/Quick/Quick.framework", + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-AMRouterTests/Pods-AMRouterTests-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMock.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework", + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-AMRouterTests/Pods-AMRouterTests-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AMRouterTests/Pods-AMRouterTests-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-AMRouterTests/Pods-AMRouterTests-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; B4F8C8163BCFF418BF3F817D /* [CP] Check Pods Manifest.lock */ = { @@ -419,17 +414,16 @@ buildActionMask = 2147483647; files = ( ); - inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-AMRouter/Pods-AMRouter-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework", + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-AMRouter/Pods-AMRouter-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CocoaLumberjack.framework", + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-AMRouter/Pods-AMRouter-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AMRouter/Pods-AMRouter-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-AMRouter/Pods-AMRouter-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -624,7 +618,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "AMRouter/AMRouter/AMRouter-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -646,7 +640,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.archmagees.AMRouter; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "AMRouter/AMRouter/AMRouter-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -655,7 +649,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = C4A5B7AE5C0D2F9AB7A03A6D /* Pods-AMRouterTests.debug.xcconfig */; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; @@ -670,7 +664,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "AMRouterTests/Misc/AMRouterTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AMRouter.app/AMRouter"; }; @@ -680,7 +674,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 214DF5B71F3D612A1855B26E /* Pods-AMRouterTests.release.xcconfig */; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; @@ -694,7 +688,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.archmagees.AMRouterTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "AMRouterTests/Misc/AMRouterTests-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AMRouter.app/AMRouter"; }; diff --git a/AMRouter.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/AMRouter.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/AMRouter.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/AMRouter/ViewController.m b/AMRouter/ViewController.m index 960fa33..32bcda9 100644 --- a/AMRouter/ViewController.m +++ b/AMRouter/ViewController.m @@ -24,9 +24,6 @@ - (void)viewDidLoad { [[AMComponent message] unreadCount]; [[AMComponent message] unreadCount]; - [AMComponent message] - - NSLog(@"is notification enabled: %@", @(count)); } diff --git a/Gemfile b/Gemfile index f624b0b..d982c48 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ -source "https://gems.ruby-china.org" +source 'https://rubygems.org' gem 'cocoapods' +gem 'cocoapods-binary' gem 'fastlane' gem 'slather' gem 'coveralls', require: false -gem 'CFPropertyList', '2.3.6' +gem 'CFPropertyList' gem 'xcode-install' - diff --git a/Gemfile.lock b/Gemfile.lock index 64a649f..48e96ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,48 +1,57 @@ GEM - remote: https://gems.ruby-china.org/ + remote: https://rubygems.org/ specs: - CFPropertyList (2.3.6) - activesupport (4.2.10) + CFPropertyList (3.0.1) + activesupport (4.2.11.1) i18n (~> 0.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - atomos (0.1.2) - babosa (1.0.2) - claide (1.0.2) - clamp (0.6.5) - cocoapods (1.5.3) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + algoliasearch (1.27.1) + httpclient (~> 2.8, >= 2.8.3) + json (>= 1.5.1) + atomos (0.1.3) + babosa (1.0.3) + claide (1.0.3) + clamp (1.3.1) + cocoapods (1.8.4) activesupport (>= 4.0.2, < 5) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.5.3) - cocoapods-deintegrate (>= 1.0.2, < 2.0) - cocoapods-downloader (>= 1.2.0, < 2.0) + cocoapods-core (= 1.8.4) + cocoapods-deintegrate (>= 1.0.3, < 2.0) + cocoapods-downloader (>= 1.2.2, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.3.0, < 2.0) + cocoapods-trunk (>= 1.4.0, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) escape (~> 0.0.4) - fourflusher (~> 2.0.1) + fourflusher (>= 2.3.0, < 3.0) gh_inspector (~> 1.0) - molinillo (~> 0.6.5) + molinillo (~> 0.6.6) nap (~> 1.0) - ruby-macho (~> 1.1) - xcodeproj (>= 1.5.7, < 2.0) - cocoapods-core (1.5.3) + ruby-macho (~> 1.4) + xcodeproj (>= 1.11.1, < 2.0) + cocoapods-binary (0.4.4) + cocoapods (>= 1.5.0, < 2.0) + fourflusher (~> 2.0) + xcpretty (~> 0.3.0) + cocoapods-core (1.8.4) activesupport (>= 4.0.2, < 6) + algoliasearch (~> 1.0) + concurrent-ruby (~> 1.1) fuzzy_match (~> 2.0.4) nap (~> 1.0) - cocoapods-deintegrate (1.0.2) - cocoapods-downloader (1.2.1) + cocoapods-deintegrate (1.0.4) + cocoapods-downloader (1.3.0) cocoapods-plugins (1.0.0) nap cocoapods-search (1.0.0) - cocoapods-stats (1.0.0) - cocoapods-trunk (1.3.0) + cocoapods-stats (1.1.0) + cocoapods-trunk (1.4.1) nap (>= 0.8, < 2.0) netrc (~> 0.11) cocoapods-try (1.1.0) @@ -50,83 +59,94 @@ GEM colored2 (3.1.2) commander-fastlane (4.4.6) highline (~> 1.7.2) - concurrent-ruby (1.0.5) - coveralls (0.8.21) + concurrent-ruby (1.1.5) + coveralls (0.8.23) json (>= 1.8, < 3) - simplecov (~> 0.14.1) + simplecov (~> 0.16.1) term-ansicolor (~> 1.3) - thor (~> 0.19.4) + thor (>= 0.19.4, < 2.0) tins (~> 1.6) declarative (0.0.10) declarative-option (0.1.0) - docile (1.1.5) - domain_name (0.5.20180417) + digest-crc (0.4.1) + docile (1.3.2) + domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - dotenv (2.4.0) - emoji_regex (0.1.1) + dotenv (2.7.5) + emoji_regex (1.0.1) escape (0.0.4) - excon (0.62.0) - faraday (0.15.2) + excon (0.69.1) + faraday (0.17.1) multipart-post (>= 1.2, < 3) faraday-cookie_jar (0.0.6) faraday (>= 0.7.4) http-cookie (~> 1.0.0) - faraday_middleware (0.12.2) + faraday_middleware (0.13.1) faraday (>= 0.7.4, < 1.0) - fastimage (2.1.3) - fastlane (2.97.0) + fastimage (2.1.7) + fastlane (2.137.0) CFPropertyList (>= 2.3, < 4.0.0) addressable (>= 2.3, < 3.0.0) babosa (>= 1.0.2, < 2.0.0) - bundler (>= 1.12.0, < 2.0.0) + bundler (>= 1.12.0, < 3.0.0) colored commander-fastlane (>= 4.4.6, < 5.0.0) dotenv (>= 2.1.1, < 3.0.0) - emoji_regex (~> 0.1) + emoji_regex (>= 0.1, < 2.0) excon (>= 0.45.0, < 1.0.0) - faraday (~> 0.9) + faraday (~> 0.17) faraday-cookie_jar (~> 0.0.6) - faraday_middleware (~> 0.9) + faraday_middleware (~> 0.13.1) fastimage (>= 2.1.0, < 3.0.0) gh_inspector (>= 1.1.2, < 2.0.0) - google-api-client (>= 0.21.2, < 0.22.0) + google-api-client (>= 0.21.2, < 0.24.0) + google-cloud-storage (>= 1.15.0, < 2.0.0) highline (>= 1.7.2, < 2.0.0) json (< 3.0.0) - mini_magick (~> 4.5.1) - multi_json + jwt (~> 2.1.0) + mini_magick (>= 4.9.4, < 5.0.0) multi_xml (~> 0.5) multipart-post (~> 2.0.0) plist (>= 3.1.0, < 4.0.0) public_suffix (~> 2.0.0) - rubyzip (>= 1.2.1, < 2.0.0) + rubyzip (>= 1.3.0, < 2.0.0) security (= 0.1.3) simctl (~> 1.6.3) slack-notifier (>= 2.0.0, < 3.0.0) - terminal-notifier (>= 1.6.2, < 2.0.0) + terminal-notifier (>= 2.0.0, < 3.0.0) terminal-table (>= 1.4.5, < 2.0.0) tty-screen (>= 0.6.3, < 1.0.0) tty-spinner (>= 0.8.0, < 1.0.0) word_wrap (~> 1.0.0) - xcodeproj (>= 1.5.7, < 2.0.0) - xcpretty (>= 0.2.4, < 1.0.0) + xcodeproj (>= 1.8.1, < 2.0.0) + xcpretty (~> 0.3.0) xcpretty-travis-formatter (>= 0.0.3) - fourflusher (2.0.1) + fourflusher (2.3.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) - google-api-client (0.21.2) + google-api-client (0.23.9) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.5, < 0.7.0) httpclient (>= 2.8.1, < 3.0) mime-types (~> 3.0) representable (~> 3.0) retriable (>= 2.0, < 4.0) - googleauth (0.6.2) + signet (~> 0.9) + google-cloud-core (1.4.1) + google-cloud-env (~> 1.0) + google-cloud-env (1.3.0) + faraday (~> 0.11) + google-cloud-storage (1.16.0) + digest-crc (~> 0.4) + google-api-client (~> 0.23) + google-cloud-core (~> 1.2) + googleauth (>= 0.6.2, < 0.10.0) + googleauth (0.6.7) faraday (~> 0.12) jwt (>= 1.4, < 3.0) - logging (~> 2.0) - memoist (~> 0.12) + memoist (~> 0.16) multi_json (~> 1.11) - os (~> 0.9) + os (>= 0.9, < 2.0) signet (~> 0.7) highline (1.7.10) http-cookie (1.0.3) @@ -134,31 +154,27 @@ GEM httpclient (2.8.3) i18n (0.9.5) concurrent-ruby (~> 1.0) - json (2.1.0) + json (2.2.0) jwt (2.1.0) - little-plugger (1.1.4) - logging (2.2.2) - little-plugger (~> 1.1) - multi_json (~> 1.10) - memoist (0.16.0) - mime-types (3.1) + memoist (0.16.1) + mime-types (3.3) mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_magick (4.5.1) - mini_portile2 (2.3.0) - minitest (5.11.3) - molinillo (0.6.5) - multi_json (1.13.1) + mime-types-data (3.2019.1009) + mini_magick (4.9.5) + mini_portile2 (2.4.0) + minitest (5.13.0) + molinillo (0.6.6) + multi_json (1.14.1) multi_xml (0.6.0) multipart-post (2.0.0) - nanaimo (0.2.5) + nanaimo (0.2.6) nap (1.1.0) naturally (2.2.0) netrc (0.11.0) - nokogiri (1.8.2) - mini_portile2 (~> 2.3.0) - os (0.9.6) - plist (3.4.0) + nokogiri (1.10.5) + mini_portile2 (~> 2.4.0) + os (1.0.1) + plist (3.5.0) public_suffix (2.0.5) representable (3.0.4) declarative (< 0.1.0) @@ -166,59 +182,59 @@ GEM uber (< 0.2.0) retriable (3.1.2) rouge (2.0.7) - ruby-macho (1.2.0) - rubyzip (1.2.1) + ruby-macho (1.4.0) + rubyzip (1.3.0) security (0.1.3) - signet (0.8.1) + signet (0.12.0) addressable (~> 2.3) faraday (~> 0.9) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) - simctl (1.6.4) + simctl (1.6.6) CFPropertyList naturally - simplecov (0.14.1) - docile (~> 1.1.0) + simplecov (0.16.1) + docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) slack-notifier (2.3.2) - slather (2.4.5) - CFPropertyList (~> 2.2) - activesupport (>= 4.0.2) - clamp (~> 0.6) - nokogiri (~> 1.8.2) - xcodeproj (~> 1.4) - term-ansicolor (1.6.0) + slather (2.4.7) + CFPropertyList (>= 2.2, < 4) + activesupport (>= 4.0.2, < 5) + clamp (~> 1.3) + nokogiri (~> 1.8) + xcodeproj (~> 1.7) + term-ansicolor (1.7.1) tins (~> 1.0) - terminal-notifier (1.8.0) + terminal-notifier (2.0.0) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) - thor (0.19.4) + thor (0.20.3) thread_safe (0.3.6) - tins (1.16.3) - tty-cursor (0.5.0) - tty-screen (0.6.4) - tty-spinner (0.8.0) - tty-cursor (>= 0.5.0) + tins (1.22.2) + tty-cursor (0.7.0) + tty-screen (0.7.0) + tty-spinner (0.9.1) + tty-cursor (~> 0.7) tzinfo (1.2.5) thread_safe (~> 0.1) uber (0.1.0) unf (0.1.4) unf_ext - unf_ext (0.0.7.5) - unicode-display_width (1.4.0) + unf_ext (0.0.7.6) + unicode-display_width (1.6.0) word_wrap (1.0.0) - xcode-install (2.4.1) + xcode-install (2.6.3) claide (>= 0.9.1, < 1.1.0) fastlane (>= 2.1.0, < 3.0.0) - xcodeproj (1.5.9) + xcodeproj (1.13.0) CFPropertyList (>= 2.3.3, < 4.0) - atomos (~> 0.1.2) + atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) - nanaimo (~> 0.2.5) - xcpretty (0.2.8) + nanaimo (~> 0.2.6) + xcpretty (0.3.0) rouge (~> 2.0.7) xcpretty-travis-formatter (1.0.0) xcpretty (~> 0.2, >= 0.0.7) @@ -227,12 +243,13 @@ PLATFORMS ruby DEPENDENCIES - CFPropertyList (= 2.3.6) + CFPropertyList cocoapods + cocoapods-binary coveralls fastlane slather xcode-install BUNDLED WITH - 1.16.1 + 2.0.2 diff --git a/Podfile b/Podfile index cdc5e33..60add0d 100644 --- a/Podfile +++ b/Podfile @@ -1,28 +1,22 @@ -source 'https://github.com/cocoapods/specs.git' platform :ios, '9.0' + +#plugin 'cocoapods-binary' + inhibit_all_warnings! use_frameworks! target 'AMRouter' do pod 'CocoaLumberjack', '~>3.4.2' - + target 'AMRouterTests' do inherit! :search_paths -# pod 'AMRouter', :path => './' - pod 'Quick', :git => 'https://github.com/Quick/Quick.git' - pod 'Nimble', :git => 'https://github.com/Quick/Nimble.git' + pod 'AMRouter', :path => './' + pod 'OCMock', :git => 'https://github.com/erikdoe/ocmock.git' + + pod 'Quick' + pod 'Nimble' end end - -post_install do |installer| - installer.pods_project.targets.each do |target| - target.build_configurations.each do |config| - config.build_settings['SWIFT_VERSION'] = '4.1' - config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = '$(inherited)' - end - end -end - diff --git a/Podfile.lock b/Podfile.lock index 58bd55b..57a5734 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,47 +1,47 @@ PODS: + - AMRouter (0.4.0): + - CocoaLumberjack (~> 3.4.2) - CocoaLumberjack (3.4.2): - CocoaLumberjack/Default (= 3.4.2) - CocoaLumberjack/Extensions (= 3.4.2) - CocoaLumberjack/Default (3.4.2) - CocoaLumberjack/Extensions (3.4.2): - CocoaLumberjack/Default - - Nimble (7.1.2) + - Nimble (8.0.4) - OCMock (3.4.1) - - Quick (1.3.0) + - Quick (2.2.0) DEPENDENCIES: - - CocoaLumberjack - - Nimble (from `https://github.com/Quick/Nimble.git`) + - AMRouter (from `./`) + - CocoaLumberjack (~> 3.4.2) + - Nimble - OCMock (from `https://github.com/erikdoe/ocmock.git`) - - Quick (from `https://github.com/Quick/Quick.git`) + - Quick + +SPEC REPOS: + trunk: + - CocoaLumberjack + - Nimble + - Quick EXTERNAL SOURCES: - Nimble: - :git: https://github.com/Quick/Nimble.git + AMRouter: + :path: "./" OCMock: :git: https://github.com/erikdoe/ocmock.git - Quick: - :git: https://github.com/Quick/Quick.git CHECKOUT OPTIONS: - Nimble: - :commit: 24e9b37f298c77a488d6ab63ea36e890fe0902f7 - :git: https://github.com/Quick/Nimble.git OCMock: :commit: b9867f830a7a011bf2cd6d5a14840bb68216a11e :git: https://github.com/erikdoe/ocmock.git - Quick: - :commit: 84ad2ad643382513ca34f0f2427e76cbe2be2f83 - :git: https://github.com/Quick/Quick.git SPEC CHECKSUMS: + AMRouter: e915b7fef5b4e9e358a2566bca890fa440e63ca2 CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd - Nimble: 4475e230ee4219b6c1e39044086c71249c6a039e + Nimble: 18d5360282923225d62b09d781f63abc1a0111fc OCMock: 2cd0716969bab32a2283ff3a46fd26a8c8b4c5e3 - Quick: 37db81a2d4473d9f369136032768c341a2e0c03c - -PODFILE CHECKSUM: 35b9f396d3af09fa71df891429aa07a525eea8f5 + Quick: 7fb19e13be07b5dfb3b90d4f9824c855a11af40e -COCOAPODS: 1.5.3 +PODFILE CHECKSUM: 728902c59af4fa70fde58e055f2d1be5a733ca5f -COCOAPODS DEPLOY: 0.0.11 +COCOAPODS: 1.8.4 From 14abc005dc5c241badd589659b32d03f3477f07c Mon Sep 17 00:00:00 2001 From: archmagees Date: Thu, 28 Nov 2019 22:03:33 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E2=98=91=EF=B8=8F=20Fix=20potential=20secu?= =?UTF-8?q?rity=20vulnerabilities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 💚 Fix security alerts in GitHub repo page. --- Gemfile | 1 - Gemfile.lock | 1 - Podfile | 2 +- Podfile.lock | 16 +++++----------- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index d982c48..1aa577a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ -source 'https://rubygems.org' gem 'cocoapods' gem 'cocoapods-binary' gem 'fastlane' diff --git a/Gemfile.lock b/Gemfile.lock index 48e96ff..29d2890 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,4 @@ GEM - remote: https://rubygems.org/ specs: CFPropertyList (3.0.1) activesupport (4.2.11.1) diff --git a/Podfile b/Podfile index 60add0d..016c537 100644 --- a/Podfile +++ b/Podfile @@ -13,7 +13,7 @@ target 'AMRouter' do inherit! :search_paths pod 'AMRouter', :path => './' - pod 'OCMock', :git => 'https://github.com/erikdoe/ocmock.git' + pod 'OCMock' pod 'Quick' pod 'Nimble' diff --git a/Podfile.lock b/Podfile.lock index 57a5734..cb375ff 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -8,40 +8,34 @@ PODS: - CocoaLumberjack/Extensions (3.4.2): - CocoaLumberjack/Default - Nimble (8.0.4) - - OCMock (3.4.1) + - OCMock (3.5) - Quick (2.2.0) DEPENDENCIES: - AMRouter (from `./`) - CocoaLumberjack (~> 3.4.2) - Nimble - - OCMock (from `https://github.com/erikdoe/ocmock.git`) + - OCMock - Quick SPEC REPOS: trunk: - CocoaLumberjack - Nimble + - OCMock - Quick EXTERNAL SOURCES: AMRouter: :path: "./" - OCMock: - :git: https://github.com/erikdoe/ocmock.git - -CHECKOUT OPTIONS: - OCMock: - :commit: b9867f830a7a011bf2cd6d5a14840bb68216a11e - :git: https://github.com/erikdoe/ocmock.git SPEC CHECKSUMS: AMRouter: e915b7fef5b4e9e358a2566bca890fa440e63ca2 CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd Nimble: 18d5360282923225d62b09d781f63abc1a0111fc - OCMock: 2cd0716969bab32a2283ff3a46fd26a8c8b4c5e3 + OCMock: 4ab4577fc941af31f4a0398f6e7e230cf21fc72a Quick: 7fb19e13be07b5dfb3b90d4f9824c855a11af40e -PODFILE CHECKSUM: 728902c59af4fa70fde58e055f2d1be5a733ca5f +PODFILE CHECKSUM: 8b6ff0f38111c5f739834f27d979992d37fb45d8 COCOAPODS: 1.8.4