/Tests/Foundation/CPStringTest.j

http://github.com/cacaodev/cappuccino · Unknown · 582 lines · 494 code · 88 blank · 0 comment · 0 complexity · 5014ff6740b36ea988c97bee2ccd9030 MD5 · raw file

  1. @import <Foundation/CPString.j>
  2. @import <Foundation/CPCharacterSet.j>
  3. @implementation CPStringTest : OJTestCase
  4. - (void)testStringByReplacingOccurrencesOfStringWithString
  5. {
  6. var expectedString = @"hello world. A new world!",
  7. dummyString = @"hello woold. A new woold!",
  8. actualString = [dummyString stringByReplacingOccurrencesOfString:@"woold" withString:@"world"];
  9. [self assertTrue:(expectedString === actualString)
  10. message:"stringByAppendingFormat: expected:" + expectedString + " actual:" + actualString];
  11. }
  12. - (void)testStringByReplacingWithRegexCharacters
  13. {
  14. var stringToTest = "${foo} {foo}",
  15. result = [stringToTest stringByReplacingOccurrencesOfString:"${foo}" withString:"BAR"];
  16. [self assert:result equals:"BAR {foo}"];
  17. }
  18. - (void)testStringByAppendingFormat
  19. {
  20. var format = @"%d X %d = %d",
  21. expectedString = "2 X 3 = 6",
  22. dummyString = @"",
  23. actualString = [dummyString stringByAppendingFormat:format, 2, 3, 6];
  24. [self assertTrue:(expectedString === actualString)
  25. message:"stringByAppendingFormat: expected:" + expectedString + " actual:" + actualString];
  26. }
  27. - (void)testStringWithString
  28. {
  29. var original = [[CPString alloc] initWithString:"str"],
  30. copy = [CPString stringWithString:original];
  31. [self assertTrue:(original == copy) message:"Contents should be equal"];
  32. }
  33. - (void)testInitWithString
  34. {
  35. var str = [[CPString alloc] initWithString:"str"];
  36. [self assert:"str" equals:str];
  37. }
  38. - (void)testInitWithFormat
  39. {
  40. // this could be really big
  41. var str = [[CPString alloc] initWithFormat:"%s", "str"];
  42. [self assert:"str" equals:str];
  43. str = [[CPString alloc] initWithFormat:"%d", 42];
  44. [self assert:"42" equals:str];
  45. str = [[CPString alloc] initWithFormat:"%f", 42.2];
  46. [self assert:"42.2" equals:str];
  47. }
  48. - (void)testStringWithFormat
  49. {
  50. // this could be equally big
  51. var str = [CPString stringWithFormat:"%s", "str"];
  52. [self assert:"str" equals:str];
  53. str = [CPString stringWithFormat:"%d", 42];
  54. [self assert:"42" equals:str];
  55. str = [CPString stringWithFormat:"%f", 42.2];
  56. [self assert:"42.2" equals:str];
  57. }
  58. - (void)testLength
  59. {
  60. [self assert:0 equals:["" length]];
  61. [self assert:1 equals:["a" length]];
  62. [self assert:5 equals:["abcde" length]];
  63. [self assert:3 equals:["日本語" length]];
  64. }
  65. - (void)testCharacterAtIndex
  66. {
  67. [self assert:"a" equals:["abcd" characterAtIndex:0]];
  68. [self assert:"b" equals:["abcd" characterAtIndex:1]];
  69. [self assert:"d" equals:["abcd" characterAtIndex:3]];
  70. [self assert:"語" equals:["日本語" characterAtIndex:2]];
  71. }
  72. - (void)testStringByAppendingSting
  73. {
  74. [self assert:"onetwo" equals:["one" stringByAppendingString:"two"]];
  75. }
  76. - (void)testStringByPaddingToLength
  77. {
  78. [self assert:"onebcd"
  79. equals:["one" stringByPaddingToLength:6
  80. withString:"abcdefg"
  81. startingAtIndex:1]];
  82. }
  83. - (void)testComponentsSeparatedByString
  84. {
  85. [self assert:["arash", "francisco", "ross", "tom"]
  86. equals:["arash.francisco.ross.tom" componentsSeparatedByString:"."]];
  87. }
  88. - (void)testSubstringFromIndex
  89. {
  90. [self assert:"abcd" equals:["abcd" substringFromIndex:0]];
  91. [self assert:"bcd" equals:["abcd" substringFromIndex:1]];
  92. [self assert:"" equals:["abcd" substringFromIndex:4]];
  93. }
  94. - (void)testSubstringWithRange
  95. {
  96. [self assert:"bcd" equals:["abcde" substringWithRange:CPMakeRange(1,3)]];
  97. [self assert:"abcde" equals:["abcde" substringWithRange:CPMakeRange(0,5)]];
  98. [self assert:"" equals:["abcde" substringWithRange:CPMakeRange(1,0)]];
  99. }
  100. - (void)testSubstringToIndex
  101. {
  102. [self assert:"abcd" equals:["abcd" substringToIndex:4]];
  103. [self assert:"abc" equals:["abcd" substringToIndex:3]];
  104. [self assert:"" equals:["abcd" substringToIndex:0]];
  105. var sawException = false;
  106. try
  107. {
  108. [@"abcd" substringToIndex:5];
  109. }
  110. catch (anException)
  111. {
  112. sawException = true;
  113. [self assert:CPRangeException equals:[anException name]];
  114. }
  115. [self assertTrue:sawException message:"expected CPRangeException"];
  116. }
  117. - (void)testBoolValue
  118. {
  119. var testStrings = [
  120. [" 090", YES],
  121. [" YES", YES],
  122. [" true", YES],
  123. [" True", YES],
  124. [" tTR", YES],
  125. [" +98", YES],
  126. [" -98", YES],
  127. [" +08", YES],
  128. [" -98", YES],
  129. [" NO", NO],
  130. [" -N00", NO],
  131. [" 00", NO],
  132. [" -00", NO],
  133. [" -+001", NO],
  134. ];
  135. for (var i = 0; i < testStrings.length; i++)
  136. [self assert:[testStrings[i][0] boolValue] equals:testStrings[i][1]];
  137. }
  138. - (void)testCommonPrefixWithString
  139. {
  140. var testStringsCase = [
  141. ["Hello", "Helicopter", "Hel"],
  142. ["Tester", "Taser", "T"],
  143. ["Abcd", "Abcd", "Abcd"],
  144. ["A long string", "A longer string", "A long"]
  145. ];
  146. var testStringsCaseless = [
  147. ["hElLo", "HeLiCoPtEr", "hEl"],
  148. ["tEsTeR", "TaSeR", "t"],
  149. ["aBcD", "AbCd", "aBcD"],
  150. ["a LoNg StRiNg", "A lOnGeR sTrInG", "a LoNg"]
  151. ];
  152. for (var i = 0; i < testStringsCase.length; i++)
  153. [self assert: [testStringsCase[i][0] commonPrefixWithString:testStringsCase[i][1]]
  154. equals: testStringsCase[i][2]];
  155. for (var i = 0; i < testStringsCaseless.length; i++)
  156. [self assert: [testStringsCaseless[i][0] commonPrefixWithString: testStringsCaseless[i][1]
  157. options: CPCaseInsensitiveSearch]
  158. equals: testStringsCaseless[i][2]];
  159. }
  160. - (void)testCapitalizedString
  161. {
  162. var testStrings = [
  163. ["", ""],
  164. ["hElLo wOrLd", "Hello World"],
  165. [" monkey-Cow", " Monkey-cow"],
  166. ["tHe QuicK bRowN-Fox JumPed_Over +the LaZy%dog", "The Quick Brown-fox Jumped_over +the Lazy%dog"]
  167. ];
  168. for (var i = 0; i < testStrings.length; i++)
  169. [self assert:[testStrings[i][0] capitalizedString] equals:testStrings[i][1]];
  170. }
  171. - (void)testUppercaseString
  172. {
  173. var str = "This is a test";
  174. [self assert:[str uppercaseString] equals:"THIS IS A TEST"];
  175. }
  176. - (void)testLowercaseString
  177. {
  178. var str = "This Is A TEST";
  179. [self assert:"this is a test" equals:[str lowercaseString]];
  180. }
  181. - (void)testStringWithHash
  182. {
  183. [self assert:"000000" equals:[CPString stringWithHash:0]];
  184. [self assert:"000001" equals:[CPString stringWithHash:1]];
  185. [self assert:"00000a" equals:[CPString stringWithHash:10]];
  186. [self assert:"000010" equals:[CPString stringWithHash:16]];
  187. [self assert:"ffffff" equals:[CPString stringWithHash:16777215]];
  188. }
  189. - (void)testStringByAppendingPathComponent
  190. {
  191. var testStrings = [
  192. ["/tmp/", "scratch.tiff", "/tmp/scratch.tiff"],
  193. ["/tmp///", "scratch.tiff", "/tmp/scratch.tiff"],
  194. ["/tmp///", "///scratch.tiff", "/tmp/scratch.tiff"],
  195. ["/tmp", "scratch.tiff", "/tmp/scratch.tiff"],
  196. ["/tmp///", "scratch.tiff", "/tmp/scratch.tiff"],
  197. ["/tmp///", "///scratch.tiff", "/tmp/scratch.tiff"],
  198. ["/", "scratch.tiff", "/scratch.tiff"],
  199. ["", "scratch.tiff", "scratch.tiff"],
  200. ["", "", ""],
  201. ["", "/", ""],
  202. ["/", "/", "/"],
  203. ["/tmp", nil, "/tmp"],
  204. ["/tmp", "/", "/tmp"],
  205. ["/tmp/", "", "/tmp"]
  206. ];
  207. for (var i = 0; i < testStrings.length; i++)
  208. {
  209. var result = [testStrings[i][0] stringByAppendingPathComponent:testStrings[i][1]];
  210. [self assertTrue:result === testStrings[i][2] message:"Value <" + testStrings[i][0] + "> Adding <" + testStrings[i][1] + "> Expected <" + testStrings[i][2] + "> was <" + result + ">"];
  211. }
  212. }
  213. - (void)testStringByAppendingPathExtension
  214. {
  215. var testStrings = [
  216. ["/tmp/scratch.old", "tiff", "/tmp/scratch.old.tiff"],
  217. ["/tmp/scratch.", "tiff", "/tmp/scratch..tiff"],
  218. ["/tmp///", "tiff", "/tmp.tiff"],
  219. ["scratch", "tiff", "scratch.tiff"],
  220. ["/", "tiff", "/"],
  221. ["", "tiff", ""]
  222. ];
  223. for (var i = 0; i < testStrings.length; i++)
  224. {
  225. var result = [testStrings[i][0] stringByAppendingPathExtension:testStrings[i][1]];
  226. [self assertTrue:result === testStrings[i][2] message:"Value <" + testStrings[i][0] + "> Adding <" + testStrings[i][1] + "> Expected <" + testStrings[i][2] + "> was <" + result + ">"];
  227. }
  228. }
  229. - (void)testStringByDeletingLastPathComponent
  230. {
  231. var testStrings = [
  232. ["/tmp/scratch.tiff", "/tmp"],
  233. ["/tmp/lock/", "/tmp"],
  234. ["/tmp/", "/"],
  235. ["/tmp", "/"],
  236. ["/", "/"],
  237. ["scratch.tiff", ""],
  238. ["a/b/c/d//////", "a/b/c"],
  239. ["a/b/////////c/d//////", "a/b/c"],
  240. ["a/b/././././c/d/./././", "a/b/././././c/d/./."],
  241. [@"a/b/././././d////", "a/b/./././."],
  242. [@"~/a", "~"],
  243. [@"~/a/", "~"],
  244. [@"../../", ".."],
  245. [@"", ""]
  246. ];
  247. for (var i = 0; i < testStrings.length; i++)
  248. {
  249. var result = [testStrings[i][0] stringByDeletingLastPathComponent];
  250. [self assertTrue:result === testStrings[i][1] message:"Value <" + testStrings[i][0] + "> Expected <" + testStrings[i][1] + "> was <" + result + ">"];
  251. }
  252. }
  253. - (void)testPathWithComponents
  254. {
  255. var testStrings = [
  256. [["tmp", "scratch"], "tmp/scratch"],
  257. [["/", "tmp", "scratch"], "/tmp/scratch"],
  258. [["/", "tmp", "/", "scratch"], "/tmp/scratch"],
  259. [["/", "tmp", "scratch", "/"], "/tmp/scratch"],
  260. [["/", "tmp", "scratch", ""], "/tmp/scratch"],
  261. [["", "/tmp", "scratch", ""], "/tmp/scratch"],
  262. [["", "tmp", "scratch", ""], "tmp/scratch"],
  263. [["/"], "/"],
  264. [["/", "/", "/"], "/"],
  265. [["", "", ""], ""],
  266. [[""], ""]
  267. ];
  268. for (var i = 0; i < testStrings.length; i++)
  269. {
  270. var result = [CPString pathWithComponents:testStrings[i][0]];
  271. [self assertTrue:result === testStrings[i][1] message:"Value <" + testStrings[i][0] + "> Expected [" + testStrings[i][1] + "] was [" + result + "]"];
  272. }
  273. }
  274. - (void)testPathComponents
  275. {
  276. var testStrings = [
  277. ["tmp/scratch", ["tmp", "scratch"]],
  278. ["/tmp/scratch", ["/", "tmp", "scratch"]],
  279. ["/tmp/scratch/", ["/", "tmp", "scratch", "/"]],
  280. ["/tmp/", ["/", "tmp", "/"]],
  281. ["/////tmp/////scratch///", ["/", "tmp", "scratch", "/"]],
  282. ["scratch.tiff", ["scratch.tiff"]],
  283. ["/", ["/"]],
  284. ["", [""]]
  285. ];
  286. for (var i = 0; i < testStrings.length; i++)
  287. {
  288. var result = [testStrings[i][0] pathComponents];
  289. [self assertTrue:[result isEqualToArray:testStrings[i][1]] message:"Expected [" + testStrings[i][1] + "] was [" + result + "]"];
  290. }
  291. }
  292. - (void)testLastPathComponent
  293. {
  294. var testStrings = [
  295. ["/tmp/scratch.tiff", "scratch.tiff"],
  296. ["/tmp/scratch", "scratch"],
  297. ["/tmp/", "tmp"],
  298. ["scratch", "scratch"],
  299. ["/", "/"],
  300. ["", ""]
  301. ];
  302. for (var i = 0; i < testStrings.length; i++)
  303. [self assert:testStrings[i][1] equals:[testStrings[i][0] lastPathComponent]];
  304. }
  305. - (void)testPathExtension
  306. {
  307. var testStrings = [
  308. ["/tmp/scratch.tiff", "tiff"],
  309. ["scratch.png", "png"],
  310. ["/tmp/scratch..tiff", "tiff"],
  311. ["/tmp", ""],
  312. ["scratch", ""],
  313. ];
  314. for (var i = 0; i < testStrings.length; i++)
  315. [self assert:testStrings[i][1] equals:[testStrings[i][0] pathExtension]];
  316. }
  317. - (void)testStringByDeletingPathExtension
  318. {
  319. var testStrings = [
  320. ["/tmp/scratch.tiff", "/tmp/scratch"],
  321. ["scratch.png", "scratch"],
  322. ["/tmp/scratch..tiff", "/tmp/scratch."],
  323. ["/tmp", "/tmp"],
  324. [".tiff", ".tiff"],
  325. ["/", "/"],
  326. ];
  327. for (var i = 0; i < testStrings.length; i++)
  328. [self assert:testStrings[i][1] equals:[testStrings[i][0] stringByDeletingPathExtension]];
  329. }
  330. - (void)testHasPrefix
  331. {
  332. [self assertTrue: ["abc" hasPrefix:"a"]];
  333. [self assertTrue: ["abc" hasPrefix:"ab"]];
  334. [self assertTrue: ["abc" hasPrefix:"abc"]];
  335. [self assertFalse:["abc" hasPrefix:"abcd"]];
  336. [self assertFalse:["abc" hasPrefix:"dbc"]];
  337. [self assertFalse:["abc" hasPrefix:"bc"]];
  338. [self assertFalse:["abc" hasPrefix:"c"]];
  339. [self assertFalse:["abc" hasPrefix:""]];
  340. }
  341. - (void)testHasSuffix
  342. {
  343. [self assertTrue: ["abc" hasSuffix:"c"]];
  344. [self assertTrue: ["abc" hasSuffix:"bc"]];
  345. [self assertTrue: ["abc" hasSuffix:"abc"]];
  346. [self assertFalse:["abc" hasSuffix:"abcd"]];
  347. [self assertFalse:["abc" hasSuffix:"ab"]];
  348. [self assertFalse:["abc" hasSuffix:"b"]];
  349. [self assertFalse:["abc" hasSuffix:"cat"]];
  350. [self assertFalse:["abc" hasSuffix:""]];
  351. }
  352. - (void)testComponentsSeparatedByCharactersInSetEmptyString
  353. {
  354. [self assert:[""]
  355. equals:["" componentsSeparatedByCharactersInSet:[CPCharacterSet whitespaceCharacterSet]]];
  356. }
  357. - (void)testComponentsSeparatedByCharactersInSetStringWithoutCharactersFromSet
  358. {
  359. [self assert:["Abradab"]
  360. equals:["Abradab" componentsSeparatedByCharactersInSet:[CPCharacterSet whitespaceCharacterSet]]];
  361. }
  362. - (void)testComponentsSeparatedByCharactersInSet
  363. {
  364. [self assert:["Baku", "baku", "to", "jest", "", "skład."]
  365. equals:["Baku baku to jest skład." componentsSeparatedByCharactersInSet:[CPCharacterSet whitespaceCharacterSet]]];
  366. }
  367. - (void)testComponentsSeparatedByCharactersInSetLeadingAndTrailingCharacterFromSet
  368. {
  369. [self assert:["", "Test", ""]
  370. equals:[" Test " componentsSeparatedByCharactersInSet:[CPCharacterSet whitespaceCharacterSet]]];
  371. }
  372. - (void)testComponentsSeparatedByCharactersExceptionRaiseOnNilSeparator
  373. {
  374. try
  375. {
  376. [[CPString string] componentsSeparatedByCharactersInSet:nil];
  377. [self assert:false];
  378. }
  379. catch (anException)
  380. {
  381. [self assert:[anException name] equals:CPInvalidArgumentException];
  382. [self assert:[anException reason] equals:@"componentsSeparatedByCharactersInSet: the separator can't be 'nil'"];
  383. }
  384. }
  385. - (void)testIsEqual
  386. {
  387. var str = "s";
  388. [self assert:str equals:[CPString stringWithString:str]];
  389. [self assert:str equals:[str copy]];
  390. [self assert:[str copy] equals:str];
  391. [self assert:[str copy] equals:[str copy]];
  392. }
  393. - (void)testRangeOfString
  394. {
  395. // Based on the Cocoa "String Programming Guide" example.
  396. var searchString = @"age",
  397. beginsTest = @"Agencies",
  398. prefixRange = [beginsTest rangeOfString:searchString options:(CPCaseInsensitiveSearch)];
  399. [self assert:0 equals:prefixRange.location message:@"forward search for age (location)"];
  400. [self assert:3 equals:prefixRange.length message:@"forward search for age (length)"];
  401. var endsTest = @"BRICOLAGE",
  402. suffixRange = [endsTest rangeOfString:searchString options:(CPCaseInsensitiveSearch | CPBackwardsSearch)];
  403. [self assert:6 equals:suffixRange.location message:@"backwards search for age (location)"];
  404. [self assert:3 equals:suffixRange.length message:@"backwards search for age (length)"];
  405. }
  406. - (void)testRangeOfString_Anchored_Backwards
  407. {
  408. var endsTest = @"AGEBRICOLAGE",
  409. unAnchoredSuffixRange = [endsTest rangeOfString:@"LAG" options:(CPCaseInsensitiveSearch | CPBackwardsSearch)],
  410. anchoredSuffixRange = [endsTest rangeOfString:@"LAG" options:(CPAnchoredSearch | CPCaseInsensitiveSearch | CPBackwardsSearch)];
  411. [self assert:8 equals:unAnchoredSuffixRange.location message:"backwards search for LAG"];
  412. [self assert:CPNotFound equals:anchoredSuffixRange.location message:"anchored backwards search for LAG"];
  413. anchoredSuffixRange = [endsTest rangeOfString:@"AGE" options:(CPAnchoredSearch | CPCaseInsensitiveSearch | CPBackwardsSearch)];
  414. [self assert:9 equals:anchoredSuffixRange.location message:"anchored backwards search for AGE"];
  415. anchoredSuffixRange = [endsTest rangeOfString:endsTest options:(CPAnchoredSearch | CPCaseInsensitiveSearch | CPBackwardsSearch)];
  416. [self assert:0 equals:anchoredSuffixRange.location message:"anchored backwards search for whole string (location)"];
  417. [self assert:endsTest.length equals:anchoredSuffixRange.length message:"anchored backwards search for whole string (length)"];
  418. anchoredSuffixRange = [endsTest rangeOfString:@"" options:(CPAnchoredSearch | CPCaseInsensitiveSearch | CPBackwardsSearch)];
  419. [self assert:CPNotFound equals:anchoredSuffixRange.location message:"anchored backwards search for nothing (location)"];
  420. [self assert:0 equals:anchoredSuffixRange.length message:"anchored backwards search for nothing (length)"];
  421. }
  422. - (void)testRangeOfString_options_range
  423. {
  424. var testString = @"In another life you would have made a excellent criminal.",
  425. hitRange;
  426. hitRange = [testString rangeOfString:@"life" options:0 range:CPMakeRange(0, testString.length)];
  427. [self assert:11 equals:hitRange.location message:@"search for 'life' in full range (location)"];
  428. [self assert:4 equals:hitRange.length message:@"search for 'life' in full range (position)"];
  429. hitRange = [testString rangeOfString:@"i" options:0 range:CPMakeRange(0, testString.length)];
  430. [self assert:12 equals:hitRange.location message:@"search for 'i' in full range (location)"];
  431. [self assert:1 equals:hitRange.length message:@"search for 'i' in full range (position)"];
  432. hitRange = [testString rangeOfString:@"i" options:0 range:CPMakeRange(10, 20)];
  433. [self assert:12 equals:hitRange.location message:@"search for 'i' in partial range (location)"];
  434. [self assert:1 equals:hitRange.length message:@"search for 'i' in partial range (position)"];
  435. var sawException = false;
  436. try
  437. {
  438. hitRange = [testString rangeOfString:@"i" options:0 range:CPMakeRange(50, 60)];
  439. }
  440. catch (anException)
  441. {
  442. sawException = true;
  443. [self assert:CPRangeException equals:[anException name]];
  444. }
  445. [self assertTrue:sawException message:"expected CPRangeException"];
  446. }
  447. - (void)testStringByTrimmingCharactersInSet
  448. {
  449. var startOneString = @".This is a test startOne",
  450. startManyString = @".,.This is a test startMany",
  451. endOneString = @"This is a test endOne.",
  452. endManyString = @"This is a test endMany.,.",
  453. bothOneString = @".This is a test bothOne,",
  454. bothManyString = @".,,This is a test bothMany..,",
  455. noneString = @"This is a test none",
  456. set = [CPCharacterSet characterSetWithCharactersInString:@".,"];
  457. [self assert:"This is a test startOne" equals:[startOneString stringByTrimmingCharactersInSet:set]];
  458. [self assert:"This is a test startMany" equals:[startManyString stringByTrimmingCharactersInSet:set]];
  459. [self assert:"This is a test endOne" equals:[endOneString stringByTrimmingCharactersInSet:set]];
  460. [self assert:"This is a test endMany" equals:[endManyString stringByTrimmingCharactersInSet:set]];
  461. [self assert:"This is a test bothOne" equals:[bothOneString stringByTrimmingCharactersInSet:set]];
  462. [self assert:"This is a test bothMany" equals:[bothManyString stringByTrimmingCharactersInSet:set]];
  463. [self assert:"This is a test none" equals:[noneString stringByTrimmingCharactersInSet:set]];
  464. }
  465. - (void)testStringByTrimmingWhitespace
  466. {
  467. var startOneString = @" This is a test startOne",
  468. startManyString = @" This is a test startMany",
  469. endOneString = @"This is a test endOne ",
  470. endManyString = @"This is a test endMany ",
  471. bothOneString = @" This is a test bothOne ",
  472. bothManyString = @" This is a test bothMany ",
  473. noneString = @"This is a test none",
  474. set = [CPCharacterSet characterSetWithCharactersInString:@" "];
  475. [self assert:"This is a test startOne" equals:[startOneString stringByTrimmingCharactersInSet:set]];
  476. [self assert:"This is a test startMany" equals:[startManyString stringByTrimmingCharactersInSet:set]];
  477. [self assert:"This is a test endOne" equals:[endOneString stringByTrimmingCharactersInSet:set]];
  478. [self assert:"This is a test endMany" equals:[endManyString stringByTrimmingCharactersInSet:set]];
  479. [self assert:"This is a test bothOne" equals:[bothOneString stringByTrimmingCharactersInSet:set]];
  480. [self assert:"This is a test bothMany" equals:[bothManyString stringByTrimmingCharactersInSet:set]];
  481. [self assert:"This is a test none" equals:[noneString stringByTrimmingCharactersInSet:set]];
  482. }
  483. - (void)testCompareWithNil
  484. {
  485. [self assert:CPOrderedDescending equals:[@"Objective-J" compare:nil]];
  486. [self assertThrows:function () { [@"Objective-J" compare:[CPNull null]] }];
  487. }
  488. - (void)testStripDiacritics
  489. {
  490. [self assert:[@"áa ée íi óo úu" stripDiacritics] equals:@"aa ee ii oo uu"];
  491. [self assert:[@"ÁA ÉE ÍI ÓO ÚU" stripDiacritics] equals:@"AA EE II OO UU"];
  492. [self assert:[@"Å Ã Ê í ö û" stripDiacritics] equals:@"A A E i o u"];
  493. }
  494. @end