/tools/drillbit/Resources/tests/API-Types/API-Types.js

https://github.com/drslump/titanium_desktop · JavaScript · 600 lines · 547 code · 47 blank · 6 comment · 4 complexity · 1dcbb4f1ecec405d4867d1d450bcbcf5 MD5 · raw file

  1. describe("Bytes, KObject, KList, etc",{
  2. test_core_types_harness: function()
  3. {
  4. value_of(Titanium.API.createKObject).should_be_function();
  5. value_of(Titanium.API.createKMethod).should_be_function();
  6. value_of(Titanium.API.createKList).should_be_function();
  7. value_of(Titanium.API.createBytes).should_be_function();
  8. },
  9. test_empty_kobject: function()
  10. {
  11. var count_properties = function(o) { var n = 0; for (x in o) { n++; } return n; };
  12. var o = Titanium.API.createKObject();
  13. // There should be no properties showing for a blank KObject
  14. value_of(count_properties(o)).should_be(0);
  15. // Yet there are some hidden methods that should be there
  16. value_of(o.equals).should_be_function();
  17. value_of(o.toString).should_be_function();
  18. value_of(o.equals(o)).should_be_true();
  19. var other = Object();
  20. value_of(o.equals(other)).should_be_false();
  21. other = Titanium.API.createKObject();
  22. value_of(o.equals(other)).should_be_false();
  23. value_of(o.toString()).should_be_string();
  24. o.property_one = "Foo!";
  25. value_of(o.property_one).should_be("Foo!");
  26. value_of(count_properties(o)).should_be(1);
  27. o.property_one = 123;
  28. value_of(o.property_one).should_be(123);
  29. value_of(count_properties(o)).should_be(1);
  30. o.property_one = o;
  31. value_of(o.equals(o.property_one)).should_be_true();
  32. value_of(count_properties(o)).should_be(1);
  33. o.property_two = "Foo2!";
  34. value_of(o.property_two).should_be("Foo2!");
  35. value_of(count_properties(o)).should_be(2);
  36. },
  37. test_wrapped_kobject: function()
  38. {
  39. var count_properties = function(o) { var n = 0; for (x in o) { n++; } return n; };
  40. var o = Object();
  41. o.property_one = "blahblah";
  42. var ko = Titanium.API.createKObject(o);
  43. value_of(count_properties(ko)).should_be(1);
  44. value_of(count_properties(o)).should_be(1);
  45. value_of(ko.property_one).should_be("blahblah");
  46. value_of(o.property_one).should_be("blahblah");
  47. value_of(ko['property_one']).should_be("blahblah");
  48. value_of(o['property_one']).should_be("blahblah");
  49. o[' weird property name '] = "oh noes";
  50. value_of(o[' weird property name ']).should_be("oh noes");
  51. value_of(ko[' weird property name ']).should_be("oh noes");
  52. },
  53. test_empty_klist: function()
  54. {
  55. var l = Titanium.API.createKList();
  56. value_of(l.length).should_be_number();
  57. value_of(l.equals).should_be_function();
  58. value_of(l.toString).should_be_function();
  59. value_of(l.length).should_be(0);
  60. value_of(l.pop).should_be_function();
  61. value_of(l.push).should_be_function();
  62. value_of(l.reverse).should_be_function();
  63. value_of(l.shift).should_be_function();
  64. value_of(l.sort).should_be_function();
  65. value_of(l.splice).should_be_function();
  66. value_of(l.unshift).should_be_function();
  67. value_of(l.concat).should_be_function();
  68. value_of(l.join).should_be_function();
  69. value_of(l.slice).should_be_function();
  70. },
  71. test_modifying_klist: function()
  72. {
  73. var l = Titanium.API.createKList();
  74. value_of(l.length).should_be(0);
  75. l.push(123);
  76. value_of(l.length).should_be(1);
  77. value_of(l[0]).should_be(123);
  78. l.push("abc");
  79. value_of(l.length).should_be(2);
  80. value_of(l[1]).should_be("abc");
  81. var popped = l.pop();
  82. value_of(popped).should_be("abc");
  83. value_of(l.length).should_be(1);
  84. value_of(l[0]).should_be(123);
  85. l.length = 3;
  86. value_of(l.length).should_be(3);
  87. value_of(l[0]).should_be(123);
  88. value_of(l[1]).should_be(undefined);
  89. value_of(l[2]).should_be(undefined);
  90. l[2] = "blah";
  91. value_of(l[0]).should_be(123);
  92. value_of(l[1]).should_be(undefined);
  93. value_of(l[2]).should_be("blah");
  94. l.length = 1;
  95. l.push(l);
  96. value_of(l.length).should_be(2);
  97. value_of(l[1].equals(l)).should_be_true();
  98. popped = l.pop();
  99. value_of(popped.equals(l)).should_be_true();
  100. l[20] = "blah";
  101. value_of(l.length).should_be(21);
  102. l.length = 0;
  103. value_of(l.length).should_be(0);
  104. },
  105. test_wrapped_klist: function()
  106. {
  107. var mylist = [1, 2, 3];
  108. var l = Titanium.API.createKList(mylist);
  109. value_of(l.length).should_be_number();
  110. value_of(l.equals).should_be_function();
  111. value_of(l.toString).should_be_function();
  112. value_of(l.length).should_be(3);
  113. value_of(l.pop).should_be_function();
  114. value_of(l.push).should_be_function();
  115. value_of(l.reverse).should_be_function();
  116. value_of(l.shift).should_be_function();
  117. value_of(l.sort).should_be_function();
  118. value_of(l.splice).should_be_function();
  119. value_of(l.unshift).should_be_function();
  120. value_of(l.concat).should_be_function();
  121. value_of(l.join).should_be_function();
  122. value_of(l.slice).should_be_function();
  123. value_of(l.length).should_be(3);
  124. value_of(mylist.length).should_be(3);
  125. var popped = l.pop();
  126. value_of(popped).should_be(3);
  127. value_of(l.length).should_be(2);
  128. value_of(mylist.length).should_be(2);
  129. var popped = l.pop();
  130. value_of(popped).should_be(2);
  131. value_of(l.length).should_be(1);
  132. value_of(mylist.length).should_be(1);
  133. var popped = l.pop();
  134. value_of(popped).should_be(1);
  135. value_of(l.length).should_be(0);
  136. value_of(mylist.length).should_be(0);
  137. l.push(123);
  138. value_of(l.length).should_be(1);
  139. value_of(l[0]).should_be(123);
  140. l.push("abc");
  141. value_of(l.length).should_be(2);
  142. value_of(l[1]).should_be("abc");
  143. var popped = l.pop();
  144. value_of(popped).should_be("abc");
  145. value_of(l.length).should_be(1);
  146. value_of(l[0]).should_be(123);
  147. l.length = 3;
  148. value_of(l.length).should_be(3);
  149. value_of(l[0]).should_be(123);
  150. value_of(l[1]).should_be(undefined);
  151. value_of(l[2]).should_be(undefined);
  152. l[2] = "blah";
  153. value_of(l[0]).should_be(123);
  154. value_of(l[1]).should_be(undefined);
  155. value_of(l[2]).should_be("blah");
  156. l.length = 1;
  157. l.push(l);
  158. value_of(l.length).should_be(2);
  159. value_of(l[1].equals(l)).should_be_true();
  160. popped = l.pop();
  161. value_of(popped.equals(l)).should_be_true();
  162. l[20] = "blah";
  163. value_of(l.length).should_be(21);
  164. l.length = 0;
  165. value_of(l.length).should_be(0);
  166. },
  167. test_kmethod_closure: function()
  168. {
  169. var variable = "uno";
  170. var other_variable = "yes";
  171. var myfunction = function()
  172. {
  173. other_variable = "no";
  174. return variable;
  175. }
  176. variable = "dos";
  177. var f = Titanium.API.createKMethod(myfunction);
  178. var result = f();
  179. value_of(result).should_be("dos");
  180. value_of(other_variable).should_be("no");
  181. },
  182. test_kmethod_closure_superduper_as_async: function(callback)
  183. {
  184. var variable = "uno";
  185. var other_variable = "yes";
  186. var myfunction = function()
  187. {
  188. other_variable = "no";
  189. return variable;
  190. };
  191. var myfunction2 = function()
  192. {
  193. return myfunction;
  194. };
  195. setTimeout(function()
  196. {
  197. variable = "dos";
  198. var f = Titanium.API.createKMethod(myfunction2());
  199. var result = f();
  200. if (result !== "dos")
  201. {
  202. callback.failed("Closure FAIL");
  203. }
  204. if (other_variable !== "no")
  205. {
  206. callback.failed("Closure FAIL2");
  207. }
  208. callback.passed();
  209. }, 50);
  210. },
  211. test_basic_empty_blob: function()
  212. {
  213. var b1 = Titanium.API.createBytes();
  214. value_of(b1).should_be_object();
  215. value_of(b1.length).should_be_number();
  216. value_of(b1.toString).should_be_function();
  217. value_of(b1.indexOf).should_be_function();
  218. value_of(b1.lastIndexOf).should_be_function();
  219. value_of(b1.charAt).should_be_function();
  220. value_of(b1.split).should_be_function();
  221. value_of(b1.substring).should_be_function();
  222. value_of(b1.substr).should_be_function();
  223. value_of(b1.toLowerCase).should_be_function();
  224. value_of(b1.toUpperCase).should_be_function();
  225. value_of(b1.length).should_be(0);
  226. value_of(b1.toString()).should_be_string();
  227. value_of(b1.toString()).should_be("");
  228. },
  229. test_basic_blob: function()
  230. {
  231. var b1 = Titanium.API.createBytes("abcdefgA");
  232. value_of(b1).should_be_object();
  233. value_of(b1.length).should_be_number();
  234. value_of(b1.toString).should_be_function();
  235. value_of(b1.indexOf).should_be_function();
  236. value_of(b1.lastIndexOf).should_be_function();
  237. value_of(b1.charAt).should_be_function();
  238. value_of(b1.split).should_be_function();
  239. value_of(b1.substring).should_be_function();
  240. value_of(b1.substr).should_be_function();
  241. value_of(b1.toLowerCase).should_be_function();
  242. value_of(b1.toUpperCase).should_be_function();
  243. value_of(b1.length).should_be(8);
  244. value_of(b1.toString()).should_be_string();
  245. value_of(b1.toString()).should_be("abcdefgA");
  246. },
  247. test_blob_indexof: function()
  248. {
  249. // must conform to behavior:
  250. // https://developer.mozilla.org/en/core_javascript_1.5_reference/global_objects/string/chara://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/indexOf
  251. var b1 = Titanium.API.createBytes("abcdefgA");
  252. value_of(b1.indexOf).should_be_function();
  253. value_of(b1.indexOf("a")).should_be(0);
  254. value_of(b1.indexOf("b")).should_be(1);
  255. value_of(b1.indexOf("c")).should_be(2);
  256. value_of(b1.indexOf("g")).should_be(6);
  257. value_of(b1.indexOf("A")).should_be(7);
  258. value_of(b1.indexOf("Z")).should_be(-1);
  259. value_of(b1.indexOf("*")).should_be(-1);
  260. value_of(b1.indexOf("B")).should_be(-1);
  261. value_of(b1.indexOf("abc")).should_be(0);
  262. value_of(b1.indexOf("bcd")).should_be(1);
  263. value_of(b1.indexOf("cd")).should_be(2);
  264. value_of(b1.indexOf("def")).should_be(3);
  265. value_of(b1.indexOf("defe")).should_be(-1);
  266. value_of(b1.indexOf("fgA")).should_be(5);
  267. value_of(b1.indexOf("a", -100)).should_be(0);
  268. value_of(b1.indexOf("b", -100)).should_be(1);
  269. value_of(b1.indexOf("c", 0)).should_be(2);
  270. value_of(b1.indexOf("c", 2)).should_be(2);
  271. value_of(b1.indexOf("c", 3)).should_be(-1);
  272. value_of(b1.indexOf("g", 2)).should_be(6);
  273. value_of(b1.indexOf("g", 7)).should_be(-1);
  274. value_of(b1.indexOf("A", 8)).should_be(-1);
  275. value_of(b1.indexOf("Z", 8)).should_be(-1);
  276. value_of(b1.indexOf("abc", 0)).should_be(0);
  277. value_of(b1.indexOf("abc", 1)).should_be(-1);
  278. value_of(b1.indexOf("bcd", 0)).should_be(1);
  279. value_of(b1.indexOf("bcd", 30)).should_be(-1);
  280. value_of(b1.indexOf("defe", 1)).should_be(-1);
  281. var b2 = Titanium.API.createBytes("");
  282. value_of(b2.indexOf).should_be_function();
  283. value_of(b2.indexOf("a")).should_be(-1);
  284. value_of(b2.indexOf("b")).should_be(-1);
  285. value_of(b2.indexOf("c")).should_be(-1);
  286. value_of(b2.indexOf("g")).should_be(-1);
  287. value_of(b2.indexOf("A")).should_be(-1);
  288. value_of(b2.indexOf("Z")).should_be(-1);
  289. value_of(b2.indexOf("*")).should_be(-1);
  290. value_of(b2.indexOf("B")).should_be(-1);
  291. value_of(b2.indexOf("abc")).should_be(-1);
  292. value_of(b2.indexOf("bcd")).should_be(-1);
  293. value_of(b2.indexOf("cd")).should_be(-1);
  294. value_of(b2.indexOf("def")).should_be(-1);
  295. value_of(b2.indexOf("defe")).should_be(-1);
  296. value_of(b2.indexOf("fgA")).should_be(-1);
  297. value_of(b2.indexOf("a", -100)).should_be(-1);
  298. value_of(b2.indexOf("b", -100)).should_be(-1);
  299. value_of(b2.indexOf("c", 0)).should_be(-1);
  300. value_of(b2.indexOf("c", 2)).should_be(-1);
  301. value_of(b2.indexOf("c", 3)).should_be(-1);
  302. value_of(b2.indexOf("g", 2)).should_be(-1);
  303. value_of(b2.indexOf("g", 7)).should_be(-1);
  304. value_of(b2.indexOf("A", 8)).should_be(-1);
  305. value_of(b2.indexOf("Z", 8)).should_be(-1);
  306. value_of(b2.indexOf("abc", 0)).should_be(-1);
  307. value_of(b2.indexOf("abc", 1)).should_be(-1);
  308. value_of(b2.indexOf("bcd", 0)).should_be(-1);
  309. value_of(b2.indexOf("bcd", 30)).should_be(-1);
  310. value_of(b2.indexOf("defe", 1)).should_be(-1);
  311. },
  312. test_blob_lastindexof: function()
  313. {
  314. // must conform to behavior:
  315. // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/lastIndexOf
  316. var b1 = Titanium.API.createBytes("abcdefgA");
  317. value_of(b1.lastIndexOf).should_be_function();
  318. value_of(b1.lastIndexOf("a")).should_be(0);
  319. value_of(b1.lastIndexOf("b")).should_be(1);
  320. value_of(b1.lastIndexOf("c")).should_be(2);
  321. value_of(b1.lastIndexOf("g")).should_be(6);
  322. value_of(b1.lastIndexOf("A")).should_be(7);
  323. value_of(b1.lastIndexOf("Z")).should_be(-1);
  324. value_of(b1.lastIndexOf("*")).should_be(-1);
  325. value_of(b1.lastIndexOf("B")).should_be(-1);
  326. value_of(b1.lastIndexOf("abc")).should_be(0);
  327. value_of(b1.lastIndexOf("bcd")).should_be(1);
  328. value_of(b1.lastIndexOf("cd")).should_be(2);
  329. value_of(b1.lastIndexOf("def")).should_be(3);
  330. value_of(b1.lastIndexOf("defe")).should_be(-1);
  331. value_of(b1.lastIndexOf("fgA")).should_be(5);
  332. value_of(b1.lastIndexOf("a", -100)).should_be(0);
  333. value_of(b1.lastIndexOf("b", -100)).should_be(-1);
  334. value_of(b1.lastIndexOf("a", 100)).should_be(0);
  335. value_of(b1.lastIndexOf("b", 100)).should_be(1);
  336. value_of(b1.lastIndexOf("c", 0)).should_be(-1);
  337. value_of(b1.lastIndexOf("c", 2)).should_be(2);
  338. value_of(b1.lastIndexOf("c", 3)).should_be(2);
  339. value_of(b1.lastIndexOf("g", 1)).should_be(-1);
  340. value_of(b1.lastIndexOf("g", 2)).should_be(-1);
  341. value_of(b1.lastIndexOf("g", 7)).should_be(6);
  342. value_of(b1.lastIndexOf("A", 8)).should_be(7);
  343. value_of(b1.lastIndexOf("Z", 8)).should_be(-1);
  344. value_of(b1.lastIndexOf("abc", 0)).should_be(0);
  345. value_of(b1.lastIndexOf("abc", 1)).should_be(0);
  346. value_of(b1.lastIndexOf("bcd", 0)).should_be(-1);
  347. value_of(b1.lastIndexOf("bcd", 30)).should_be(1);
  348. value_of(b1.lastIndexOf("defe", 1)).should_be(-1);
  349. var b2 = Titanium.API.createBytes("");
  350. value_of(b2.lastIndexOf).should_be_function();
  351. value_of(b2.lastIndexOf("a")).should_be(-1);
  352. value_of(b2.lastIndexOf("b")).should_be(-1);
  353. value_of(b2.lastIndexOf("c")).should_be(-1);
  354. value_of(b2.lastIndexOf("g")).should_be(-1);
  355. value_of(b2.lastIndexOf("A")).should_be(-1);
  356. value_of(b2.lastIndexOf("Z")).should_be(-1);
  357. value_of(b2.lastIndexOf("*")).should_be(-1);
  358. value_of(b2.lastIndexOf("B")).should_be(-1);
  359. value_of(b2.lastIndexOf("abc")).should_be(-1);
  360. value_of(b2.lastIndexOf("bcd")).should_be(-1);
  361. value_of(b2.lastIndexOf("cd")).should_be(-1);
  362. value_of(b2.lastIndexOf("def")).should_be(-1);
  363. value_of(b2.lastIndexOf("defe")).should_be(-1);
  364. value_of(b2.lastIndexOf("fgA")).should_be(-1);
  365. value_of(b2.lastIndexOf("a", -100)).should_be(-1);
  366. value_of(b2.lastIndexOf("b", -100)).should_be(-1);
  367. value_of(b2.lastIndexOf("c", 0)).should_be(-1);
  368. value_of(b2.lastIndexOf("c", 2)).should_be(-1);
  369. value_of(b2.lastIndexOf("c", 3)).should_be(-1);
  370. value_of(b2.lastIndexOf("g", 2)).should_be(-1);
  371. value_of(b2.lastIndexOf("g", 7)).should_be(-1);
  372. value_of(b2.lastIndexOf("A", 8)).should_be(-1);
  373. value_of(b2.lastIndexOf("Z", 8)).should_be(-1);
  374. value_of(b2.lastIndexOf("abc", 0)).should_be(-1);
  375. value_of(b2.lastIndexOf("abc", 1)).should_be(-1);
  376. value_of(b2.lastIndexOf("bcd", 0)).should_be(-1);
  377. value_of(b2.lastIndexOf("bcd", 30)).should_be(-1);
  378. value_of(b2.lastIndexOf("defe", 1)).should_be(-1);
  379. var b3 = Titanium.API.createBytes("abcdefgAadef");
  380. value_of(b3.lastIndexOf).should_be_function();
  381. value_of(b3.lastIndexOf("a")).should_be(8);
  382. value_of(b3.lastIndexOf("b")).should_be(1);
  383. value_of(b3.lastIndexOf("c")).should_be(2);
  384. value_of(b3.lastIndexOf("g")).should_be(6);
  385. value_of(b3.lastIndexOf("A")).should_be(7);
  386. value_of(b3.lastIndexOf("Z")).should_be(-1);
  387. value_of(b3.lastIndexOf("*")).should_be(-1);
  388. value_of(b3.lastIndexOf("B")).should_be(-1);
  389. value_of(b3.lastIndexOf("abc")).should_be(0);
  390. value_of(b3.lastIndexOf("bcd")).should_be(1);
  391. value_of(b3.lastIndexOf("cd")).should_be(2);
  392. value_of(b3.lastIndexOf("def")).should_be(9);
  393. value_of(b3.lastIndexOf("def", 30)).should_be(9);
  394. value_of(b3.lastIndexOf("defe")).should_be(-1);
  395. value_of(b3.lastIndexOf("fgA")).should_be(5);
  396. value_of(b3.lastIndexOf("a", 100)).should_be(8);
  397. value_of(b3.lastIndexOf("b", 100)).should_be(1);
  398. value_of(b3.lastIndexOf("a", -100)).should_be(0);
  399. value_of(b3.lastIndexOf("b", -100)).should_be(-1);
  400. value_of(b3.lastIndexOf("c", 0)).should_be(-1);
  401. value_of(b3.lastIndexOf("c", 2)).should_be(2);
  402. value_of(b3.lastIndexOf("c", 3)).should_be(2);
  403. value_of(b3.lastIndexOf("g", 2)).should_be(-1);
  404. value_of(b3.lastIndexOf("g", 7)).should_be(6);
  405. value_of(b3.lastIndexOf("A", 8)).should_be(7);
  406. value_of(b3.lastIndexOf("Z", 8)).should_be(-1);
  407. value_of(b3.lastIndexOf("abc", 0)).should_be(0);
  408. value_of(b3.lastIndexOf("abc", 1)).should_be(0);
  409. value_of(b3.lastIndexOf("bcd", 0)).should_be(-1);
  410. value_of(b3.lastIndexOf("bcd", 30)).should_be(1);
  411. value_of(b3.lastIndexOf("defe", 1)).should_be(-1);
  412. },
  413. test_blob_charat: function()
  414. {
  415. var b1 = Titanium.API.createBytes("abcdefg");
  416. value_of(b1.charAt(-100)).should_be("");
  417. value_of(b1.charAt(-1)).should_be("");
  418. value_of(b1.charAt(0)).should_be("a");
  419. value_of(b1.charAt(1)).should_be("b");
  420. value_of(b1.charAt(2)).should_be("c");
  421. value_of(b1.charAt(3)).should_be("d");
  422. value_of(b1.charAt(4)).should_be("e");
  423. value_of(b1.charAt(5)).should_be("f");
  424. value_of(b1.charAt(6)).should_be("g");
  425. value_of(b1.charAt(7)).should_be("");
  426. value_of(b1.charAt(700)).should_be("");
  427. var b2 = Titanium.API.createBytes("");
  428. value_of(b2.charAt(-100)).should_be("");
  429. value_of(b2.charAt(-1)).should_be("");
  430. value_of(b2.charAt(0)).should_be("");
  431. value_of(b2.charAt(1)).should_be("");
  432. value_of(b2.charAt(2)).should_be("");
  433. value_of(b2.charAt(3)).should_be("");
  434. value_of(b2.charAt(4)).should_be("");
  435. value_of(b2.charAt(5)).should_be("");
  436. value_of(b2.charAt(6)).should_be("");
  437. value_of(b2.charAt(7)).should_be("");
  438. value_of(b2.charAt(700)).should_be("");
  439. },
  440. test_blob_split: function()
  441. {
  442. var b1 = Titanium.API.createBytes("abcdefg");
  443. var b1s = b1.split();
  444. value_of(b1s).should_be_object();
  445. value_of(b1s.length).should_be(1);
  446. value_of(b1s[0]).should_be("abcdefg");
  447. var b2 = Titanium.API.createBytes("");
  448. var b2s = b2.split();
  449. value_of(b2s.length).should_be(1);
  450. value_of(b2s[0]).should_be("");
  451. var b3 = Titanium.API.createBytes("abcdefg");
  452. var b3s = b3.split(",");
  453. value_of(b3s).should_be_object();
  454. value_of(b3s.length).should_be(1);
  455. value_of(b3s[0]).should_be("abcdefg");
  456. var b4 = Titanium.API.createBytes("ab,cdefg");
  457. var b4s = b4.split(",");
  458. value_of(b4s).should_be_object();
  459. value_of(b4s.length).should_be(2);
  460. value_of(b4s[0]).should_be("ab");
  461. value_of(b4s[1]).should_be("cdefg");
  462. var b5 = Titanium.API.createBytes(",ab,cdefg,,");
  463. var b5s = b5.split(",");
  464. value_of(b5s).should_be_object();
  465. value_of(b5s.length).should_be(5);
  466. value_of(b5s[0]).should_be("");
  467. value_of(b5s[1]).should_be("ab");
  468. value_of(b5s[2]).should_be("cdefg");
  469. value_of(b5s[3]).should_be("");
  470. value_of(b5s[4]).should_be("");
  471. var b6 = Titanium.API.createBytes(",ab,cdefg,");
  472. var b6s = b6.split(",", 2);
  473. value_of(b6s).should_be_object();
  474. value_of(b6s.length).should_be(2);
  475. value_of(b6s[0]).should_be("");
  476. value_of(b6s[1]).should_be("ab");
  477. var b7 = Titanium.API.createBytes("abc,def,ghi");
  478. var b7s = b7.split(",", 0);
  479. value_of(b7s).should_be_object();
  480. value_of(b7s.length).should_be(0);
  481. var b8 = Titanium.API.createBytes("abcde");
  482. var b8s = b8.split("");
  483. value_of(b8s).should_be_object();
  484. value_of(b8s.length).should_be(5);
  485. value_of(b8s[0]).should_be('a');
  486. value_of(b8s[1]).should_be('b');
  487. value_of(b8s[2]).should_be('c');
  488. value_of(b8s[3]).should_be('d');
  489. value_of(b8s[4]).should_be('e');
  490. },
  491. test_blob_substr: function()
  492. {
  493. var blob = Titanium.API.createBytes("abcdefghij");
  494. value_of(blob.substr).should_be_function();
  495. value_of(blob.substr(1,2)).should_be("bc");
  496. value_of(blob.substr(-3,2)).should_be("hi");
  497. value_of(blob.substr(-3)).should_be("hij");
  498. value_of(blob.substr(1)).should_be("bcdefghij");
  499. value_of(blob.substr(-20,2)).should_be("ab");
  500. value_of(blob.substr(20,2)).should_be("");
  501. value_of(blob.substr(1,-2)).should_be("");
  502. value_of(blob.substr(1,0)).should_be("");
  503. },
  504. test_blob_substring: function()
  505. {
  506. var blob = Titanium.API.createBytes("Mozilla");
  507. value_of(blob.substring).should_be_function();
  508. value_of(blob.substring(3,0)).should_be("Moz");
  509. value_of(blob.substring(0,3)).should_be("Moz");
  510. value_of(blob.substring(-10,3)).should_be("Moz");
  511. value_of(blob.substring(4,7)).should_be("lla");
  512. value_of(blob.substring(7,4)).should_be("lla");
  513. value_of(blob.substring(0,6)).should_be("Mozill");
  514. value_of(blob.substring(6,0)).should_be("Mozill");
  515. value_of(blob.substring(0,7)).should_be("Mozilla");
  516. value_of(blob.substring(0,10)).should_be("Mozilla");
  517. value_of(blob.substring(7,0)).should_be("Mozilla");
  518. value_of(blob.substring(10,0)).should_be("Mozilla");
  519. },
  520. test_blob_tolowercase: function()
  521. {
  522. var blob = Titanium.API.createBytes("Mozilla123!?");
  523. value_of(blob.toLowerCase).should_be_function();
  524. value_of(blob.toLowerCase()).should_be("mozilla123!?");
  525. blob = Titanium.API.createBytes("mOZILLA123!?");
  526. value_of(blob.toLowerCase()).should_be("mozilla123!?");
  527. blob = Titanium.API.createBytes("mO ZILLA123!?");
  528. value_of(blob.toLowerCase()).should_be("mo zilla123!?");
  529. blob = Titanium.API.createBytes("1234567890-=!@#$%^&*()_+");
  530. value_of(blob.toLowerCase()).should_be("1234567890-=!@#$%^&*()_+");
  531. },
  532. test_blob_touppercase: function()
  533. {
  534. var blob = Titanium.API.createBytes("Mozilla123!?");
  535. value_of(blob.toUpperCase).should_be_function();
  536. value_of(blob.toUpperCase()).should_be("MOZILLA123!?");
  537. blob = Titanium.API.createBytes("mOZILLA123!?");
  538. value_of(blob.toUpperCase()).should_be("MOZILLA123!?");
  539. blob = Titanium.API.createBytes("mO ZILLA123!?");
  540. value_of(blob.toUpperCase()).should_be("MO ZILLA123!?");
  541. blob = Titanium.API.createBytes("1234567890-=!@#$%^&*()_+");
  542. value_of(blob.toUpperCase()).should_be("1234567890-=!@#$%^&*()_+");
  543. },
  544. test_blob_concat: function()
  545. {
  546. var blob = Titanium.API.createBytes("Moz");
  547. var blob2 = Titanium.API.createBytes("illa");
  548. value_of(blob.concat).should_be_function();
  549. value_of(blob.concat("illa")).should_be("Mozilla");
  550. value_of(blob.concat("illa", " 123", "456")).should_be("Mozilla 123456");
  551. value_of(blob.concat(blob2)).should_be("Mozilla");
  552. }
  553. });