length2.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function write(v) { WScript.Echo(v + ""); }
  6. var errorCount = 0;
  7. function check(scen, exp) {
  8. var res = eval(scen);
  9. if ( res === exp ) {
  10. //write("Passed " + scen + " : " + exp);
  11. } else {
  12. write("Failed " + scen + " Expected:" + exp + ". Got:" + res);
  13. errorCount++;
  14. }
  15. }
  16. // global
  17. var globalList = [
  18. ["eval",1],
  19. ["parseInt",2],
  20. ["parseFloat",1],
  21. ["isNaN",1],
  22. ["isFinite",1],
  23. ["decodeURI",1],
  24. ["encodeURI",1],
  25. ["decodeURIComponent",1],
  26. ["encodeURIComponent",1],
  27. ["Object",1],
  28. ["Function",1],
  29. ["Array",1],
  30. ["String",1],
  31. ["Boolean",1],
  32. ["Number",1],
  33. ["Date",7],
  34. ["RegExp",2],
  35. ["Error",1],
  36. ["EvalError",1],
  37. ["RangeError",1],
  38. ["ReferenceError",1],
  39. ["SyntaxError",1],
  40. ["TypeError",1],
  41. ["URIError",1]
  42. ]
  43. // Object
  44. var objList = [
  45. ["constructor",1],
  46. ["toString",0],
  47. ["toLocaleString",0],
  48. ["valueOf",0],
  49. ["hasOwnProperty",1] ,
  50. ["isPrototypeOf",1] ,
  51. ["propertyIsEnumerable",1]
  52. ]
  53. // Function
  54. var funcList = [
  55. ["constructor",1],
  56. ["toString",0],
  57. ["apply",2 ],
  58. ["call", 1]
  59. ]
  60. // Array
  61. var arrList = [
  62. // FuncName, length
  63. ["constructor",1],
  64. ["toString",0],
  65. ["toLocaleString", 0],
  66. ["concat", 1],
  67. ["join",1],
  68. ["pop",0],
  69. ["push",1],
  70. ["reverse",0],
  71. ["shift",0],
  72. ["slice",2],
  73. ["sort",1],
  74. ["splice",2],
  75. ["unshift",1]
  76. ];
  77. // String
  78. var stringList = [
  79. ["constructor",1],
  80. ["toString",0],
  81. ["valueOf",0],
  82. ["charAt",1],
  83. ["charCodeAt",1],
  84. ["concat",1],
  85. ["indexOf",1],
  86. ["lastIndexOf",1],
  87. ["localeCompare",1],
  88. ["match",1],
  89. ["replace",2],
  90. ["search",1],
  91. ["slice",2],
  92. ["split",2],
  93. ["substring",2],
  94. ["toLowerCase",0],
  95. ["toLocaleLowerCase",0],
  96. ["toUpperCase",0],
  97. ["toLocaleUpperCase",0],
  98. // not in ECMA spec
  99. ["anchor",1],
  100. ["big",0],
  101. ["blink",0],
  102. ["bold",0],
  103. ["fixed",0],
  104. ["fontcolor",1],
  105. ["fontsize",1],
  106. ["italics",0],
  107. ["link",1],
  108. ["small",0],
  109. ["strike",0],
  110. ["sub",0],
  111. ["sup",0],
  112. ["substr",2]
  113. ]
  114. var stringList2 = [
  115. ["fromCharCode", 1]
  116. ];
  117. // Boolean
  118. var boolList = [
  119. ["constructor",1],
  120. ["toString",0],
  121. ["valueOf",0]
  122. ]
  123. //Number
  124. var numberList = [
  125. ["constructor",1],
  126. ["toString",1],
  127. ["toLocaleString",0],
  128. ["valueOf",0],
  129. ["toFixed",1],
  130. ["toExponential",1],
  131. ["toPrecision",1]
  132. ]
  133. // Math object is a single object - 18
  134. var mathList = [
  135. ["abs",1],
  136. ["acos",1],
  137. ["asin",1],
  138. ["atan",1],
  139. ["atan2",2],
  140. ["ceil",1],
  141. ["cos",1],
  142. ["exp",1],
  143. ["floor",1],
  144. ["log",1],
  145. ["max",2],
  146. ["min",2],
  147. ["pow",2],
  148. ["random",0],
  149. ["round",1],
  150. ["sin",1],
  151. ["sqrt",1],
  152. ["tan",1]
  153. ]
  154. // Date Prototype object
  155. var dateList = [
  156. ["constructor",7],
  157. ["toString",0],
  158. ["toDateString",0],
  159. ["toTimeString",0],
  160. ["toLocaleString",0],
  161. ["toLocaleDateString",0],
  162. ["valueOf",0],
  163. ["getTime",0],
  164. ["getFullYear",0],
  165. ["getUTCFullYear",0],
  166. ["getMonth",0],
  167. ["getUTCMonth",0],
  168. ["getDate",0],
  169. ["getUTCDate",0],
  170. ["getDay",0],
  171. ["getUTCDay",0],
  172. ["getHours",0],
  173. ["getUTCHours",0],
  174. ["getMinutes",0],
  175. ["getUTCMinutes",0],
  176. ["getSeconds",0],
  177. ["getUTCSeconds",0],
  178. ["getMilliseconds",0],
  179. ["getUTCMilliseconds",0],
  180. ["getTimezoneOffset",0],
  181. ["setTime",1],
  182. ["setMilliseconds",1],
  183. ["setUTCMilliseconds",1],
  184. ["setSeconds",2],
  185. ["setUTCSeconds",2],
  186. ["setMinutes",3],
  187. ["setUTCMinutes",3],
  188. ["setHours",4],
  189. ["setUTCHours",4],
  190. ["setDate",1],
  191. ["setUTCDate",1],
  192. ["setMonth",2],
  193. ["setUTCMonth",2],
  194. ["setFullYear",3],
  195. ["setUTCFullYear",3],
  196. ["toUTCString",0],
  197. ["toGMTString",0],
  198. ["toLocaleTimeString",0 ],
  199. ["toUTCString",0],
  200. ["setYear",1],
  201. ["getYear",0]
  202. ]
  203. // static date functions
  204. var dateList2 = [
  205. ["parse",1],
  206. ["UTC",7]
  207. ]
  208. // RegExp object
  209. var regxpList = [
  210. ["constructor",2],
  211. ["exec",1],
  212. ["test",1],
  213. ["toString",0],
  214. // not in ECMA spec
  215. ["compile",2]
  216. ]
  217. // Error object
  218. var errorList = [
  219. ["constructor",1],
  220. ["name",5],
  221. ["message",0],
  222. ["toString",0]
  223. ]
  224. function TestLength(list, str) {
  225. for (var i=0; i<list.length; i++) {
  226. var fname = list[i][0];
  227. check(str+fname+".length", list[i][1]);
  228. }
  229. }
  230. TestLength(globalList,"");
  231. TestLength(objList, "Object.prototype.");
  232. TestLength(funcList, "Function.prototype.");
  233. TestLength(arrList, "Array.prototype.");
  234. TestLength(stringList, "String.prototype.");
  235. TestLength(stringList2, "String.");
  236. TestLength(boolList, "Boolean.prototype.");
  237. TestLength(numberList, "Number.prototype.");
  238. TestLength(mathList, "Math.");
  239. TestLength(dateList, "Date.prototype.");
  240. TestLength(dateList2,"Date.");
  241. TestLength(regxpList, "RegExp.prototype.");
  242. TestLength(errorList, "Error.prototype.");
  243. if ( errorCount > 0 ) {
  244. write(errorCount + " Test(s) Failed");
  245. } else {
  246. write("All tests passed");
  247. }