/tests/auto/qscriptjstestsuite/tests/ecma/Expressions/11.13.2-2.js

https://bitbucket.org/ultra_iter/qt-vtl · JavaScript · 253 lines · 130 code · 39 blank · 84 comment · 0 complexity · 816cef6c535fdf039cfe0d8472b61540 MD5 · raw file

  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 Mozilla Communicator client code, released
  16. * March 31, 1998.
  17. *
  18. * The Initial Developer of the Original Code is
  19. * Netscape Communications Corporation.
  20. * Portions created by the Initial Developer are Copyright (C) 1998
  21. * the Initial Developer. All Rights Reserved.
  22. *
  23. * Contributor(s):
  24. *
  25. * Alternatively, the contents of this file may be used under the terms of
  26. * either the GNU General Public License Version 2 or later (the "GPL"), or
  27. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. * in which case the provisions of the GPL or the LGPL are applicable instead
  29. * of those above. If you wish to allow use of your version of this file only
  30. * under the terms of either the GPL or the LGPL, and not to allow others to
  31. * use your version of this file under the terms of the MPL, indicate your
  32. * decision by deleting the provisions above and replace them with the notice
  33. * and other provisions required by the GPL or the LGPL. If you do not delete
  34. * the provisions above, a recipient may use your version of this file under
  35. * the terms of any one of the MPL, the GPL or the LGPL.
  36. *
  37. * ***** END LICENSE BLOCK ***** */
  38. gTestfile = '11.13.2-2.js';
  39. /**
  40. File Name: 11.13.2-2js
  41. ECMA Section: 11.13.2 Compound Assignment: /=
  42. Description:
  43. *= /= %= += -= <<= >>= >>>= &= ^= |=
  44. 11.13.2 Compound assignment ( op= )
  45. The production AssignmentExpression :
  46. LeftHandSideExpression @ = AssignmentExpression, where @ represents one of
  47. the operators indicated above, is evaluated as follows:
  48. 1. Evaluate LeftHandSideExpression.
  49. 2. Call GetValue(Result(1)).
  50. 3. Evaluate AssignmentExpression.
  51. 4. Call GetValue(Result(3)).
  52. 5. Apply operator @ to Result(2) and Result(4).
  53. 6. Call PutValue(Result(1), Result(5)).
  54. 7. Return Result(5).
  55. Author: christine@netscape.com
  56. Date: 12 november 1997
  57. */
  58. var SECTION = "11.13.2-2";
  59. var VERSION = "ECMA_1";
  60. startTest();
  61. writeHeaderToLog( SECTION + " Compound Assignment: /=");
  62. // NaN cases
  63. new TestCase( SECTION,
  64. "VAR1 = NaN; VAR2=1; VAR1 /= VAR2",
  65. Number.NaN,
  66. eval("VAR1 = Number.NaN; VAR2=1; VAR1 /= VAR2") );
  67. new TestCase( SECTION,
  68. "VAR1 = NaN; VAR2=1; VAR1 /= VAR2; VAR1",
  69. Number.NaN,
  70. eval("VAR1 = Number.NaN; VAR2=1; VAR1 /= VAR2; VAR1") );
  71. new TestCase( SECTION,
  72. "VAR1 = NaN; VAR2=0; VAR1 /= VAR2",
  73. Number.NaN,
  74. eval("VAR1 = Number.NaN; VAR2=0; VAR1 /= VAR2") );
  75. new TestCase( SECTION,
  76. "VAR1 = NaN; VAR2=0; VAR1 /= VAR2; VAR1",
  77. Number.NaN,
  78. eval("VAR1 = Number.NaN; VAR2=0; VAR1 /= VAR2; VAR1") );
  79. new TestCase( SECTION,
  80. "VAR1 = 0; VAR2=NaN; VAR1 /= VAR2",
  81. Number.NaN,
  82. eval("VAR1 = 0; VAR2=Number.NaN; VAR1 /= VAR2") );
  83. new TestCase( SECTION,
  84. "VAR1 = 0; VAR2=NaN; VAR1 /= VAR2; VAR1",
  85. Number.NaN,
  86. eval("VAR1 = 0; VAR2=Number.NaN; VAR1 /= VAR2; VAR1") );
  87. // number cases
  88. new TestCase( SECTION,
  89. "VAR1 = 0; VAR2=1; VAR1 /= VAR2",
  90. 0,
  91. eval("VAR1 = 0; VAR2=1; VAR1 /= VAR2") );
  92. new TestCase( SECTION,
  93. "VAR1 = 0; VAR2=1; VAR1 /= VAR2;VAR1",
  94. 0,
  95. eval("VAR1 = 0; VAR2=1; VAR1 /= VAR2;VAR1") );
  96. new TestCase( SECTION,
  97. "VAR1 = 0xFF; VAR2 = 0xA, VAR1 /= VAR2",
  98. 25.5,
  99. eval("VAR1 = 0XFF; VAR2 = 0XA, VAR1 /= VAR2") );
  100. // special division cases
  101. new TestCase( SECTION,
  102. "VAR1 = 0; VAR2= Infinity; VAR1 /= VAR2",
  103. 0,
  104. eval("VAR1 = 0; VAR2 = Number.POSITIVE_INFINITY; VAR1 /= VAR2; VAR1") );
  105. new TestCase( SECTION,
  106. "VAR1 = -0; VAR2= Infinity; VAR1 /= VAR2",
  107. 0,
  108. eval("VAR1 = -0; VAR2 = Number.POSITIVE_INFINITY; VAR1 /= VAR2; VAR1") );
  109. new TestCase( SECTION,
  110. "VAR1 = -0; VAR2= -Infinity; VAR1 /= VAR2",
  111. 0,
  112. eval("VAR1 = -0; VAR2 = Number.NEGATIVE_INFINITY; VAR1 /= VAR2; VAR1") );
  113. new TestCase( SECTION,
  114. "VAR1 = 0; VAR2= -Infinity; VAR1 /= VAR2",
  115. 0,
  116. eval("VAR1 = 0; VAR2 = Number.NEGATIVE_INFINITY; VAR1 /= VAR2; VAR1") );
  117. new TestCase( SECTION,
  118. "VAR1 = 0; VAR2= Infinity; VAR2 /= VAR1",
  119. Number.POSITIVE_INFINITY,
  120. eval("VAR1 = 0; VAR2 = Number.POSITIVE_INFINITY; VAR2 /= VAR1; VAR2") );
  121. new TestCase( SECTION,
  122. "VAR1 = -0; VAR2= Infinity; VAR2 /= VAR1",
  123. Number.NEGATIVE_INFINITY,
  124. eval("VAR1 = -0; VAR2 = Number.POSITIVE_INFINITY; VAR2 /= VAR1; VAR2") );
  125. new TestCase( SECTION,
  126. "VAR1 = -0; VAR2= -Infinity; VAR2 /= VAR1",
  127. Number.POSITIVE_INFINITY,
  128. eval("VAR1 = -0; VAR2 = Number.NEGATIVE_INFINITY; VAR2 /= VAR1; VAR2") );
  129. new TestCase( SECTION,
  130. "VAR1 = 0; VAR2= -Infinity; VAR2 /= VAR1",
  131. Number.NEGATIVE_INFINITY,
  132. eval("VAR1 = 0; VAR2 = Number.NEGATIVE_INFINITY; VAR2 /= VAR1; VAR2") );
  133. new TestCase( SECTION,
  134. "VAR1 = Infinity; VAR2= Infinity; VAR1 /= VAR2",
  135. Number.NaN,
  136. eval("VAR1 = Number.POSITIVE_INFINITY; VAR2 = Number.POSITIVE_INFINITY; VAR1 /= VAR2; VAR1") );
  137. new TestCase( SECTION,
  138. "VAR1 = Infinity; VAR2= -Infinity; VAR1 /= VAR2",
  139. Number.NaN,
  140. eval("VAR1 = Number.POSITIVE_INFINITY; VAR2 = Number.NEGATIVE_INFINITY; VAR1 /= VAR2; VAR1") );
  141. new TestCase( SECTION,
  142. "VAR1 =-Infinity; VAR2= Infinity; VAR1 /= VAR2",
  143. Number.NaN,
  144. eval("VAR1 = Number.NEGATIVE_INFINITY; VAR2 = Number.POSITIVE_INFINITY; VAR1 /= VAR2; VAR1") );
  145. new TestCase( SECTION,
  146. "VAR1 =-Infinity; VAR2=-Infinity; VAR1 /= VAR2",
  147. Number.NaN,
  148. eval("VAR1 = Number.NEGATIVE_INFINITY; VAR2 = Number.NEGATIVE_INFINITY; VAR1 /= VAR2; VAR1") );
  149. new TestCase( SECTION,
  150. "VAR1 = 0; VAR2= 0; VAR1 /= VAR2",
  151. Number.NaN,
  152. eval("VAR1 = 0; VAR2 = 0; VAR1 /= VAR2; VAR1") );
  153. new TestCase( SECTION,
  154. "VAR1 = 0; VAR2= -0; VAR1 /= VAR2",
  155. Number.NaN,
  156. eval("VAR1 = 0; VAR2 = -0; VAR1 /= VAR2; VAR1") );
  157. new TestCase( SECTION,
  158. "VAR1 = -0; VAR2= 0; VAR1 /= VAR2",
  159. Number.NaN,
  160. eval("VAR1 = -0; VAR2 = 0; VAR1 /= VAR2; VAR1") );
  161. new TestCase( SECTION,
  162. "VAR1 = -0; VAR2= -0; VAR1 /= VAR2",
  163. Number.NaN,
  164. eval("VAR1 = -0; VAR2 = -0; VAR1 /= VAR2; VAR1") );
  165. new TestCase( SECTION,
  166. "VAR1 = 1; VAR2= 0; VAR1 /= VAR2",
  167. Number.POSITIVE_INFINITY,
  168. eval("VAR1 = 1; VAR2 = 0; VAR1 /= VAR2; VAR1") );
  169. new TestCase( SECTION,
  170. "VAR1 = 1; VAR2= -0; VAR1 /= VAR2",
  171. Number.NEGATIVE_INFINITY,
  172. eval("VAR1 = 1; VAR2 = -0; VAR1 /= VAR2; VAR1") );
  173. new TestCase( SECTION,
  174. "VAR1 = -1; VAR2= 0; VAR1 /= VAR2",
  175. Number.NEGATIVE_INFINITY,
  176. eval("VAR1 = -1; VAR2 = 0; VAR1 /= VAR2; VAR1") );
  177. new TestCase( SECTION,
  178. "VAR1 = -1; VAR2= -0; VAR1 /= VAR2",
  179. Number.POSITIVE_INFINITY,
  180. eval("VAR1 = -1; VAR2 = -0; VAR1 /= VAR2; VAR1") );
  181. // string cases
  182. new TestCase( SECTION,
  183. "VAR1 = 1000; VAR2 = '10', VAR1 /= VAR2; VAR1",
  184. 100,
  185. eval("VAR1 = 1000; VAR2 = '10', VAR1 /= VAR2; VAR1") );
  186. new TestCase( SECTION,
  187. "VAR1 = '1000'; VAR2 = 10, VAR1 /= VAR2; VAR1",
  188. 100,
  189. eval("VAR1 = '1000'; VAR2 = 10, VAR1 /= VAR2; VAR1") );
  190. /*
  191. new TestCase( SECTION, "VAR1 = 10; VAR2 = '0XFF', VAR1 /= VAR2", 2550, eval("VAR1 = 10; VAR2 = '0XFF', VAR1 /= VAR2") );
  192. new TestCase( SECTION, "VAR1 = '0xFF'; VAR2 = 0xA, VAR1 /= VAR2", 2550, eval("VAR1 = '0XFF'; VAR2 = 0XA, VAR1 /= VAR2") );
  193. new TestCase( SECTION, "VAR1 = '10'; VAR2 = '255', VAR1 /= VAR2", 2550, eval("VAR1 = '10'; VAR2 = '255', VAR1 /= VAR2") );
  194. new TestCase( SECTION, "VAR1 = '10'; VAR2 = '0XFF', VAR1 /= VAR2", 2550, eval("VAR1 = '10'; VAR2 = '0XFF', VAR1 /= VAR2") );
  195. new TestCase( SECTION, "VAR1 = '0xFF'; VAR2 = 0xA, VAR1 /= VAR2", 2550, eval("VAR1 = '0XFF'; VAR2 = 0XA, VAR1 /= VAR2") );
  196. // boolean cases
  197. new TestCase( SECTION, "VAR1 = true; VAR2 = false; VAR1 /= VAR2", 0, eval("VAR1 = true; VAR2 = false; VAR1 /= VAR2") );
  198. new TestCase( SECTION, "VAR1 = true; VAR2 = true; VAR1 /= VAR2", 1, eval("VAR1 = true; VAR2 = true; VAR1 /= VAR2") );
  199. // object cases
  200. new TestCase( SECTION, "VAR1 = new Boolean(true); VAR2 = 10; VAR1 /= VAR2;VAR1", 10, eval("VAR1 = new Boolean(true); VAR2 = 10; VAR1 /= VAR2; VAR1") );
  201. new TestCase( SECTION, "VAR1 = new Number(11); VAR2 = 10; VAR1 /= VAR2; VAR1", 110, eval("VAR1 = new Number(11); VAR2 = 10; VAR1 /= VAR2; VAR1") );
  202. new TestCase( SECTION, "VAR1 = new Number(11); VAR2 = new Number(10); VAR1 /= VAR2", 110, eval("VAR1 = new Number(11); VAR2 = new Number(10); VAR1 /= VAR2") );
  203. new TestCase( SECTION, "VAR1 = new String('15'); VAR2 = new String('0xF'); VAR1 /= VAR2", 255, eval("VAR1 = String('15'); VAR2 = new String('0xF'); VAR1 /= VAR2") );
  204. */
  205. test();