std.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. if (!dojo._hasResource["dojox.lang.tests.std"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dojox.lang.tests.std"] = true;
  6. dojo.provide("dojox.lang.tests.std");
  7. dojo.require("dojox.lang.functional");
  8. (function() {
  9. var df = dojox.lang.functional, v, isOdd = "%2";
  10. tests.register("dojox.lang.tests.std", [function testFilter1(t) {
  11. t.assertEqual(df.filter([1, 2, 3], isOdd), [1, 3]);
  12. }, function testFilter2(t) {
  13. t.assertEqual(df.filter([1, 2, 3], "%2==0"), [2]);
  14. },
  15. function testForEach(t) {
  16. t.assertEqual((v = [], df.forEach([1, 2, 3],
  17. function(x) {
  18. v.push(x);
  19. }), v), [1, 2, 3]);
  20. },
  21. function testMap(t) {
  22. t.assertEqual(df.map([1, 2, 3], "+3"), [4, 5, 6]);
  23. },
  24. function testEvery1(t) {
  25. t.assertFalse(df.every([1, 2, 3], isOdd));
  26. }, function testEvery2(t) {
  27. t.assertTrue(df.every([1, 3, 5], isOdd));
  28. },
  29. function testSome1(t) {
  30. t.assertFalse(df.some([2, 4, 6], isOdd));
  31. }, function testSome2(t) {
  32. t.assertTrue(df.some([1, 2, 3], isOdd));
  33. },
  34. function testReduce1(t) {
  35. t.assertEqual(df.reduce([4, 2, 1], "x-y"), 1);
  36. }, function testReduce2(t) {
  37. t.assertEqual(df.reduce([4, 2, 1], "x-y", 8), 1);
  38. },
  39. function testReduceRight1(t) {
  40. t.assertEqual(df.reduceRight([4, 2, 1], "x-y"), -5);
  41. }, function testReduceRight2(t) {
  42. t.assertEqual(df.reduceRight([4, 2, 1], "x-y", 8),
  43. 1);
  44. }]);
  45. })();
  46. }