unittest_test.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>script.aculo.us Unit test file</title>
  6. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  7. <script src="../../lib/prototype.js" type="text/javascript"></script>
  8. <script src="../../src/scriptaculous.js" type="text/javascript"></script>
  9. <script src="../../src/unittest.js" type="text/javascript"></script>
  10. <link rel="stylesheet" href="../test.css" type="text/css" />
  11. <style type="text/css" media="screen">
  12. /* <![CDATA[ */
  13. #testcss1 { font-size:11px; color: #f00; }
  14. #testcss2 { font-size:12px; color: #0f0; display: none; }
  15. /* ]]> */
  16. </style>
  17. </head>
  18. <body>
  19. <h1>script.aculo.us Unit test file</h1>
  20. <p>
  21. This is a preliminary version mostly for testing the unittest library.
  22. </p>
  23. <!-- Log output -->
  24. <div id="testlog"> </div>
  25. <!-- Test elements follow -->
  26. <div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>
  27. <div id="test_2"> <span> </span>
  28. <div><div></div> </div><span> </span>
  29. </div>
  30. <ul id="tlist"><li id="tlist_1">x1</li><li id="tlist_2">x2</li></ul>
  31. <ul id="tlist2"><li class="a" id="tlist2_1">x1</li><li id="tlist2_2">x2</li></ul>
  32. <div id="testmoveby" style="background-color:#333;width:100px;">XXXX</div>
  33. <div id="testcss1">testcss1<span id="testcss1_span" style="display:none;">blah</span></div><div id="testcss2">testcss1</div>
  34. <!-- Tests follow -->
  35. <script type="text/javascript" language="javascript" charset="utf-8">
  36. // <![CDATA[
  37. var testObj = {
  38. isNice: function(){
  39. return true;
  40. },
  41. isBroken: function(){
  42. return false;
  43. }
  44. }
  45. new Test.Unit.Runner({
  46. testAssertEqual: function() { with(this) {
  47. assertEqual(0, 0);
  48. assertEqual(0, 0, "test");
  49. assertEqual(0,'0');
  50. assertEqual(65.0, 65);
  51. assertEqual("a", "a");
  52. assertEqual("a", "a", "test");
  53. assertNotEqual(0, 1);
  54. assertNotEqual("a","b");
  55. assertNotEqual({},{});
  56. assertNotEqual([],[]);
  57. assertNotEqual([],{});
  58. }},
  59. testAssertRespondsTo: function() { with(this) {
  60. assertRespondsTo('isNice', testObj);
  61. assertRespondsTo('isBroken', testObj);
  62. }},
  63. testAssertIndentical: function() { with(this) {
  64. assertIdentical(0, 0);
  65. assertIdentical(0, 0, "test");
  66. assertIdentical(1, 1);
  67. assertIdentical('a', 'a');
  68. assertIdentical('a', 'a', "test");
  69. assertIdentical('', '');
  70. assertIdentical(undefined, undefined);
  71. assertIdentical(null, null);
  72. assertIdentical(true, true);
  73. assertIdentical(false, false);
  74. var obj = {a:'b'};
  75. assertIdentical(obj, obj);
  76. assertNotIdentical({1:2,3:4},{1:2,3:4});
  77. assertIdentical(1, 1.0); // both are typeof == 'number'
  78. assertNotIdentical(1, '1');
  79. assertNotIdentical(1, '1.0');
  80. }},
  81. testAssertMatch: function() { with(this) {
  82. assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg');
  83. assertMatch(/Fuc/, 'Thomas Fuchs');
  84. assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95');
  85. assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330');
  86. assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16');
  87. assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM');
  88. }},
  89. testAssertInstanceOf: function() { with(this) {
  90. assertInstanceOf(Effect.Opacity, new Effect.Opacity('testcss1',{sync:true}));
  91. assertNotInstanceOf(String, new Effect.Opacity('testcss1',{sync:true}));
  92. // note: fails with firefox 1.0.X (bug, fixed in Deer Park)
  93. assertNotInstanceOf(Effect.Parallel, new Effect.Opacity('testcss1',{sync:true}), "(note: fails with firefox 1.0.X, fixed in Deer Park)");
  94. }},
  95. testAssertReturns: function() { with(this) {
  96. assertReturnsTrue('isNice',testObj);
  97. assertReturnsFalse('isBroken',testObj);
  98. assertReturnsTrue('nice',testObj);
  99. assertReturnsFalse('broken',testObj);
  100. }},
  101. testAssertVisible: function() { with(this) {
  102. assertVisible('testcss1');
  103. assertNotVisible('testcss1_span');
  104. assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari.");
  105. Element.hide('testcss1');
  106. assertNotVisible('testcss1');
  107. assertNotVisible('testcss1_span');
  108. Element.show('testcss1');
  109. assertVisible('testcss1');
  110. assertNotVisible('testcss1_span');
  111. Element.show('testcss1_span');
  112. assertVisible('testcss1_span');
  113. Element.hide('testcss1');
  114. assertNotVisible('testcss1_span'); // hidden by parent
  115. }}
  116. }, "testlog");
  117. // ]]>
  118. </script>
  119. </body>
  120. </html>