-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:venmo/VENCalculatorInputView
- Loading branch information
Showing
7 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
PODS: | ||
- Expecta (0.2.3) | ||
- Expecta (0.2.4) | ||
- OCMock (3.0.2) | ||
- Specta (0.2.1) | ||
|
||
DEPENDENCIES: | ||
- Expecta (~> 0.2.2) | ||
- OCMock (~> 3.0.0) | ||
- Specta (~> 0.2.1) | ||
|
||
SPEC CHECKSUMS: | ||
Expecta: 578e0c29df79a96a159187599e2def686ef6a66c | ||
Expecta: 112bcafa2304ee0f3c5e586505f24555a47b25d5 | ||
OCMock: b9836ab89d8d5e66cbe6333f93857037c310ee62 | ||
Specta: 9141310f46b1f68b676650ff2854e1ed0b74163a | ||
|
||
COCOAPODS: 0.33.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
@interface UITextField (VENCalculatorInputView) | ||
|
||
- (NSRange)selectedNSRange; | ||
|
||
@end |
19 changes: 19 additions & 0 deletions
19
VENCalculatorInputView/UITextField+VENCalculatorInputView.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#import "UITextField+VENCalculatorInputView.h" | ||
|
||
@implementation UITextField (VENCalculatorInputView) | ||
|
||
- (NSRange)selectedNSRange | ||
{ | ||
UITextPosition *beginning = self.beginningOfDocument; | ||
|
||
UITextRange *selectedRange = self.selectedTextRange; | ||
UITextPosition *selectionStart = selectedRange.start; | ||
UITextPosition *selectionEnd = selectedRange.end; | ||
|
||
NSInteger location = [self offsetFromPosition:beginning toPosition:selectionStart]; | ||
NSInteger length = [self offsetFromPosition:selectionStart toPosition:selectionEnd]; | ||
|
||
return NSMakeRange(location, length); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
VENCalculatorInputViewTests/UITextField+VENCalculatorInputViewSpec.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#define EXP_SHORTHAND | ||
#import <Expecta/Expecta.h> | ||
#import <Specta/Specta.h> | ||
#import <OCMock/OCMock.h> | ||
|
||
#import "UITextField+VENCalculatorInputView.h" | ||
|
||
SpecBegin(UITextRange_VENCalculatorInputView) | ||
|
||
describe(@"selectedNSRange", ^{ | ||
|
||
it(@"should get UITextField's selectedText in an NSRange", ^{ | ||
id mockBeginningTextPosition = OCMClassMock([UITextPosition class]); | ||
id mockSelectionStartTextPosition = OCMClassMock([UITextPosition class]); | ||
id mockSelectionEndTextPosition = OCMClassMock([UITextPosition class]); | ||
|
||
id mockTextField = OCMClassMock([UITextField class]); | ||
id mockSelectedTextRange = OCMClassMock([UITextRange class]); | ||
|
||
OCMStub([mockTextField beginningOfDocument]).andReturn(mockBeginningTextPosition); | ||
OCMStub([mockTextField selectedTextRange]).andReturn(mockSelectedTextRange); | ||
OCMStub([(UITextRange *)mockSelectedTextRange start]).andReturn(mockSelectionStartTextPosition); | ||
OCMStub([(UITextRange *)mockSelectedTextRange end]).andReturn(mockSelectionEndTextPosition); | ||
|
||
[[mockTextField expect] offsetFromPosition:mockBeginningTextPosition toPosition:mockSelectionStartTextPosition]; | ||
[[mockTextField expect] offsetFromPosition:mockSelectionStartTextPosition toPosition:mockSelectionEndTextPosition]; | ||
|
||
[mockTextField selectedNSRange]; | ||
}); | ||
}); | ||
|
||
SpecEnd |