You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.test.session.addTest('Array', {
  8. name: 'Global Array Decorators',
  9. planned: 17,
  10. setUp: function(){
  11. this.Cls = Ext.extend(Object, {});
  12. },
  13. // 12
  14. test_indexOf: function(){
  15. Y.Assert.areEqual(-1, [].indexOf(1), 'Test with an empty array');
  16. Y.Assert.areEqual(-1, [0, 1, 2].indexOf(3), 'Test with numbers where the item should not exist');
  17. Y.Assert.areEqual(1, [0, 1, 2].indexOf(1), 'Test with numbers where the item should exist');
  18. Y.Assert.areEqual(3, [0, 3, 2, 1, 4, 5, 6, 7, 1, 2].indexOf(1), 'Test with numbers where the item exists a number of times');
  19. Y.Assert.areEqual(-1, ['x', 'y', 'z'].indexOf('X'), 'Test with strings where the item should not exist');
  20. Y.Assert.areEqual(0, ['a', 'x', 'y', 'z'].indexOf('a'), 'Test with strings where the item should exist');
  21. Y.Assert.areEqual(-1, [0, 1, 2].indexOf('1'), 'Test to ensure type coercion doesn\'t occur');
  22. var c1 = new this.Cls(),
  23. c2 = new this.Cls(),
  24. c3 = new this.Cls(),
  25. c4 = new this.Cls();
  26. Y.Assert.areEqual(-1, [c1, c2, c3, c4].indexOf(new this.Cls()), 'Test with object instances, item should not exist');
  27. Y.Assert.areEqual(2, [c1, c2, c3, c4].indexOf(c3), 'Test with object instances, item should exist');
  28. //test the from parameter
  29. Y.Assert.areEqual(-1, [1, 2, 3, 4, 5].indexOf(1, 3), 'Test where the item exists past the from parameter');
  30. Y.Assert.areEqual(-1, [1, 2, 3, 4, 5].indexOf(1, 50), 'Test where the item exists, but the index is greater than the array');
  31. Y.Assert.areEqual(7, [1, 2, 3, 4, 5, 6, 7, 3].indexOf(3, 4), 'Test where the item more than once, the from should refer to the second item');
  32. },
  33. // 5
  34. test_remove: function(){
  35. var arr = [];
  36. arr.remove(1);
  37. Y.ArrayAssert.isEmpty(arr, 'Test with an empty array');
  38. arr = [1, 2, 3];
  39. arr.remove(1);
  40. Y.ArrayAssert.itemsAreEqual([2, 3], arr, 'Test with a simple removal');
  41. arr = [1, 2, 3, 1];
  42. arr.remove(1);
  43. Y.ArrayAssert.itemsAreEqual([2, 3, 1], arr, 'Test where the item exists more than once');
  44. arr = [1, 2, 3, 4];
  45. arr.remove(100);
  46. Y.ArrayAssert.itemsAreEqual([1, 2, 3, 4], arr, 'Test where the item doesn\'t exist');
  47. var c1 = new this.Cls(),
  48. c2 = new this.Cls(),
  49. c3 = new this.Cls();
  50. arr = [c1, c2, c3];
  51. arr.remove(c2);
  52. Y.ArrayAssert.itemsAreEqual([c1, c3], arr, 'Test with object instances');
  53. }
  54. });