PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/js/src/tests/ecma_2/RegExp/properties-002.js

https://bitbucket.org/soko/mozilla-central
JavaScript | 161 lines | 71 code | 31 blank | 59 comment | 5 complexity | a940e0805b2a46250048fc2c62c9648e MD5 | raw file
Possible License(s): GPL-2.0, JSON, 0BSD, LGPL-3.0, AGPL-1.0, MIT, MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-2.1, Apache-2.0
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is JavaScript Engine testing utilities.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communication Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. /**
  38. * File Name: RegExp/properties-002.js
  39. * ECMA Section: 15.7.6.js
  40. * Description: Based on ECMA 2 Draft 7 February 1999
  41. *
  42. * Author: christine@netscape.com
  43. * Date: 19 February 1999
  44. */
  45. //-----------------------------------------------------------------------------
  46. var SECTION = "RegExp/properties-002.js";
  47. var VERSION = "ECMA_2";
  48. var TITLE = "Properties of RegExp Instances";
  49. var BUGNUMBER ="124339";
  50. startTest();
  51. re_1 = /\cA?/g;
  52. re_1.lastIndex = Math.pow(2,31);
  53. AddRegExpCases( re_1, "\\cA?", true, false, false, Math.pow(2,31) );
  54. re_2 = /\w*/i;
  55. re_2.lastIndex = Math.pow(2,32) -1;
  56. AddRegExpCases( re_2, "\\w*", false, true, false, Math.pow(2,32)-1 );
  57. re_3 = /\*{0,80}/m;
  58. re_3.lastIndex = Math.pow(2,31) -1;
  59. AddRegExpCases( re_3, "\\*{0,80}", false, false, true, Math.pow(2,31) -1 );
  60. re_4 = /^./gim;
  61. re_4.lastIndex = Math.pow(2,30) -1;
  62. AddRegExpCases( re_4, "^.", true, true, true, Math.pow(2,30) -1 );
  63. re_5 = /\B/;
  64. re_5.lastIndex = Math.pow(2,30);
  65. AddRegExpCases( re_5, "\\B", false, false, false, Math.pow(2,30) );
  66. /*
  67. * Brendan: "need to test cases Math.pow(2,32) and greater to see
  68. * whether they round-trip." Reason: thanks to the work done in
  69. * http://bugzilla.mozilla.org/show_bug.cgi?id=124339, lastIndex
  70. * is now stored as a double instead of a uint32_t (unsigned integer).
  71. *
  72. * Note 2^32 -1 is the upper bound for uint32's, but doubles can go
  73. * all the way up to Number.MAX_VALUE. So that's why we need cases
  74. * between those two numbers.
  75. *
  76. */
  77. re_6 = /\B/;
  78. re_6.lastIndex = Math.pow(2,32);
  79. AddRegExpCases( re_6, "\\B", false, false, false, Math.pow(2,32) );
  80. re_7 = /\B/;
  81. re_7.lastIndex = Math.pow(2,32) + 1;
  82. AddRegExpCases( re_7, "\\B", false, false, false, Math.pow(2,32) + 1 );
  83. re_8 = /\B/;
  84. re_8.lastIndex = Math.pow(2,32) * 2;
  85. AddRegExpCases( re_8, "\\B", false, false, false, Math.pow(2,32) * 2 );
  86. re_9 = /\B/;
  87. re_9.lastIndex = Math.pow(2,40);
  88. AddRegExpCases( re_9, "\\B", false, false, false, Math.pow(2,40) );
  89. re_10 = /\B/;
  90. re_10.lastIndex = Number.MAX_VALUE;
  91. AddRegExpCases( re_10, "\\B", false, false, false, Number.MAX_VALUE );
  92. //-----------------------------------------------------------------------------
  93. test();
  94. //-----------------------------------------------------------------------------
  95. function AddRegExpCases( re, s, g, i, m, l ){
  96. AddTestCase( re + ".test == RegExp.prototype.test",
  97. true,
  98. re.test == RegExp.prototype.test );
  99. AddTestCase( re + ".toString == RegExp.prototype.toString",
  100. true,
  101. re.toString == RegExp.prototype.toString );
  102. AddTestCase( re + ".contructor == RegExp.prototype.constructor",
  103. true,
  104. re.constructor == RegExp.prototype.constructor );
  105. AddTestCase( re + ".compile == RegExp.prototype.compile",
  106. true,
  107. re.compile == RegExp.prototype.compile );
  108. AddTestCase( re + ".exec == RegExp.prototype.exec",
  109. true,
  110. re.exec == RegExp.prototype.exec );
  111. // properties
  112. AddTestCase( re + ".source",
  113. s,
  114. re.source );
  115. AddTestCase( re + ".toString()",
  116. "/" + s +"/" + (g?"g":"") + (i?"i":"") +(m?"m":""),
  117. re.toString() );
  118. AddTestCase( re + ".global",
  119. g,
  120. re.global );
  121. AddTestCase( re + ".ignoreCase",
  122. i,
  123. re.ignoreCase );
  124. AddTestCase( re + ".multiline",
  125. m,
  126. re.multiline);
  127. AddTestCase( re + ".lastIndex",
  128. l,
  129. re.lastIndex );
  130. }