mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-26 13:37:03 +00:00
84 lines
2.4 KiB
Plaintext
84 lines
2.4 KiB
Plaintext
import <Foundation/CPString.j>
|
|
|
|
@implementation CPStringTest : OJTestCase
|
|
|
|
|
|
- (void)testStringByReplacingOccurrencesOfStringWithString
|
|
{
|
|
var expectedString = @"hello world. A new world!";
|
|
var dummyString = @"hello woold. A new woold!";
|
|
var actualString = [dummyString stringByReplacingOccurrencesOfString:@"woold" withString:@"world"];
|
|
[self assertTrue:(expectedString === actualString)
|
|
message:"stringByAppendingFormat: expected:" + expectedString + " actual:" + actualString];
|
|
|
|
|
|
|
|
}
|
|
- (void)testStringByAppendingFormat
|
|
{
|
|
var format = @"%d X %d = %d";
|
|
var expectedString = "2 X 3 = 6";
|
|
var dummyString = @"";
|
|
var actualString = [dummyString stringByAppendingFormat:format ,2 ,3 ,6];
|
|
[self assertTrue:(expectedString === actualString)
|
|
message:"stringByAppendingFormat: expected:" + expectedString + " actual:" + actualString];
|
|
|
|
}
|
|
- (void)testBoolValue
|
|
{
|
|
var testStrings = [
|
|
[" 090", YES],
|
|
[" YES", YES],
|
|
[" true", YES],
|
|
[" True", YES],
|
|
[" tTR", YES],
|
|
[" +98", YES],
|
|
[" -98", YES],
|
|
[" +08", YES],
|
|
[" -98", YES],
|
|
[" NO", NO],
|
|
[" -N00", NO],
|
|
[" 00", NO],
|
|
[" -00", NO]
|
|
];
|
|
|
|
for (var i = 0; i < testStrings.length; i++)
|
|
[self assert:[testStrings[i][0] boolValue] equals:testStrings[i][1]];
|
|
}
|
|
|
|
- (void)testCapitalizedString
|
|
{
|
|
var testStrings = [
|
|
["", ""],
|
|
["hElLo wOrLd", "Hello World"],
|
|
[" monkey-Cow", " Monkey-cow"],
|
|
["tHe QuicK bRowN-Fox JumPed_Over +the LaZy%dog", "The Quick Brown-fox Jumped_over +the Lazy%dog"]
|
|
];
|
|
|
|
for (var i = 0; i < testStrings.length; i++)
|
|
[self assert:[testStrings[i][0] capitalizedString] equals:testStrings[i][1]];
|
|
}
|
|
|
|
- (void)testStringByDeletingLastPathComponent
|
|
{
|
|
var testStrings = [
|
|
["/tmp/scratch.tiff", "/tmp"],
|
|
["/tmp/lock/", "/tmp"],
|
|
["/tmp/", "/"],
|
|
["/tmp", "/"],
|
|
["/", "/"],
|
|
["scratch.tiff", ""],
|
|
["a/b/c/d//////", "a/b/c"],
|
|
["a/b/././././c/d/./././", "a/b/././././c/d/./."],
|
|
[@"a/b/././././d////", "a/b/./././."],
|
|
[@"~/a", "~"],
|
|
[@"~/a/", "~"],
|
|
[@"../../", ".."]
|
|
];
|
|
|
|
for (var i = 0; i < testStrings.length; i++)
|
|
[self assert:[testStrings[i][0] stringByDeletingLastPathComponent] equals:testStrings[i][1]];
|
|
}
|
|
|
|
@end
|