-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method to make Base64 SHA1 digest from string. Tests.
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 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
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,62 @@ | ||
// | ||
// NSString+PKAdditionsSpec.m | ||
// NSString+PKAdditions Spec | ||
// | ||
// Created by Pavel Kunc on 04/11/2013. | ||
// | ||
|
||
#import "Kiwi.h" | ||
#import "NSString+PKAdditions.h" | ||
|
||
SPEC_BEGIN(NSString_PKAdditionsSpec) | ||
|
||
describe(@"pk_stringByReplacingNumericHTMLEntities", ^{ | ||
|
||
context(@"when given string without any HTML entities", ^{ | ||
it(@"should return the unchanged string", ^{ | ||
NSString *original = @"Lorem ipsum..."; | ||
[[[original pk_stringByReplacingNumericHTMLEntities] should] equal:original]; | ||
}); | ||
}); | ||
|
||
context(@"when given empty string", ^{ | ||
it(@"should return empty string", ^{ | ||
[[[@"" pk_stringByReplacingNumericHTMLEntities] should] equal:@""]; | ||
}); | ||
}); | ||
|
||
|
||
// http://www.fileformat.info/info/unicode/char/2018/index.htm | ||
// http://www.fileformat.info/info/unicode/char/2019/index.htm | ||
context(@"when given string with HTML entities", ^{ | ||
it(@"should return the string with all entities converted to characters", ^{ | ||
NSString *original = @"Lorem ‘ipsum’..."; | ||
NSString *result = @"Lorem ‘ipsum’..."; | ||
[[[original pk_stringByReplacingNumericHTMLEntities] should] equal:result]; | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe(@"pk_SHA1_Base64", ^{ | ||
|
||
context(@"when string is empty", ^{ | ||
it(@"should return SHA1 special value for empty string", ^{ | ||
// Digest::SHA1.hexdigest('') => "da39a3ee5e6b4b0d3255bfef95601890afd80709" | ||
// Digest::SHA1.base64digest('') => "2jmj7l5rSw0yVb/vlWAYkK/YBwk=" | ||
[[[@"" pk_SHA1_Base64] should] equal:@"2jmj7l5rSw0yVb/vlWAYkK/YBwk="]; | ||
}); | ||
}); | ||
|
||
context(@"when string is not empty", ^{ | ||
it(@"should return Base64 representation of the SHA1 of the string", ^{ | ||
NSString *string = @"abcdefghijklmnopqrstuvwxyz"; | ||
NSString *hash = @"MtEMe4z5ZXDKBM438qGdhCQNOok="; | ||
[[[string pk_SHA1_Base64] should] equal:hash]; | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
SPEC_END | ||
|