string-search-test262.test.ts 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*
  2. * Portions adapted from Test262 at revision 250f204f23a9249ff204be2baec29600faae7b75:
  3. * - test/built-ins/String/prototype/split/call-split-l-0-instance-is-string-hello.js
  4. * - test/built-ins/String/prototype/split/call-split-l-1-instance-is-string-hello.js
  5. * - test/built-ins/String/prototype/split/call-split-l-2-instance-is-string-hello.js
  6. * - test/built-ins/String/prototype/split/call-split-l-3-instance-is-string-hello.js
  7. * - test/built-ins/String/prototype/split/call-split-l-4-instance-is-string-hello.js
  8. * - test/built-ins/String/prototype/split/call-split-l-na-n-instance-is-string-hello.js
  9. * - test/built-ins/String/prototype/split/call-split-l-instance-is-string-hello.js
  10. * - test/built-ins/String/prototype/split/call-split-ll-instance-is-string-hello.js
  11. * - test/built-ins/String/prototype/split/call-split-h-instance-is-string-hello.js
  12. * - test/built-ins/String/prototype/split/call-split-hello-instance-is-string-hello.js
  13. * - test/built-ins/String/prototype/split/call-split-hellothere-instance-is-string-hello.js
  14. * - test/built-ins/String/prototype/split/call-split-o-instance-is-string-hello.js
  15. * - test/built-ins/String/prototype/split/call-split-x-instance-is-string-hello.js
  16. * - test/built-ins/String/prototype/split/call-split-x-instance-is-empty-string.js
  17. * - test/built-ins/String/prototype/split/call-split-4-instance-is-string-one-1-two-2-four-4.js
  18. * - test/built-ins/String/prototype/split/call-split-on-instance-is-string-one-1-two-2-four-4.js
  19. * - test/built-ins/String/prototype/split/call-split-instance-is-string-one-two-three-four-five.js
  20. * - test/built-ins/String/prototype/split/call-split-instance-is-string-one-two-three.js
  21. * - test/built-ins/String/prototype/split/call-split-instance-is-string.js
  22. * - test/built-ins/String/prototype/split/instance-is-string-one-two-three-four-five.js
  23. * - test/built-ins/String/prototype/split/instance-is-string.js
  24. * - test/built-ins/String/prototype/split/separator-colon-instance-is-string-one-1-two-2-four-4.js
  25. * - test/built-ins/String/prototype/split/separator-comma-instance-is-string-one-two-three-four-five.js
  26. * - test/built-ins/String/prototype/split/separator-empty-string-instance-is-string.js
  27. * - test/built-ins/String/prototype/split/call-split-without-arguments-and-instance-is-empty-string.js
  28. * - test/built-ins/String/prototype/split/separator-undef.js
  29. * - test/built-ins/String/prototype/slice/S15.5.4.13_A1_T6.js
  30. * - test/built-ins/String/prototype/slice/S15.5.4.13_A1_T14.js
  31. * - test/built-ins/String/prototype/slice/S15.5.4.13_A2_T1.js
  32. * - test/built-ins/String/prototype/slice/S15.5.4.13_A2_T2.js
  33. * - test/built-ins/String/prototype/slice/S15.5.4.13_A2_T3.js
  34. * - test/built-ins/String/prototype/slice/S15.5.4.13_A2_T4.js
  35. * - test/built-ins/String/prototype/slice/S15.5.4.13_A2_T5.js
  36. * - test/built-ins/String/prototype/slice/S15.5.4.13_A2_T6.js
  37. * - test/built-ins/String/prototype/slice/S15.5.4.13_A2_T7.js
  38. * - test/built-ins/String/prototype/slice/S15.5.4.13_A2_T8.js
  39. * - test/built-ins/String/prototype/slice/S15.5.4.13_A2_T9.js
  40. * - test/built-ins/String/prototype/substring/S15.5.4.15_A1_T6.js
  41. * - test/built-ins/String/prototype/substring/S15.5.4.15_A1_T14.js
  42. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T1.js
  43. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T2.js
  44. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T3.js
  45. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T4.js
  46. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T5.js
  47. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T6.js
  48. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T7.js
  49. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T8.js
  50. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T9.js
  51. * - test/built-ins/String/prototype/substring/S15.5.4.15_A2_T10.js
  52. * - test/built-ins/String/prototype/includes/String.prototype.includes_FailMissingLetter.js
  53. * - test/built-ins/String/prototype/includes/String.prototype.includes_SuccessNoLocation.js
  54. * - test/built-ins/String/prototype/includes/String.prototype.includes_FailBadLocation.js
  55. * - test/built-ins/String/prototype/includes/String.prototype.includes_FailLocation.js
  56. * - test/built-ins/String/prototype/includes/String.prototype.includes_Success.js
  57. * - test/built-ins/String/prototype/includes/searchstring-found-with-position.js
  58. * - test/built-ins/String/prototype/includes/searchstring-found-without-position.js
  59. * - test/built-ins/String/prototype/includes/searchstring-not-found-with-position.js
  60. * - test/built-ins/String/prototype/includes/searchstring-not-found-without-position.js
  61. * - test/built-ins/String/prototype/includes/return-false-with-out-of-bounds-position.js
  62. * - test/built-ins/String/prototype/includes/return-true-if-searchstring-is-empty.js
  63. * - test/built-ins/String/prototype/includes/coerced-values-of-position.js
  64. * - test/built-ins/String/prototype/startsWith/searchstring-found-with-position.js
  65. * - test/built-ins/String/prototype/startsWith/searchstring-found-without-position.js
  66. * - test/built-ins/String/prototype/startsWith/searchstring-not-found-with-position.js
  67. * - test/built-ins/String/prototype/startsWith/searchstring-not-found-without-position.js
  68. * - test/built-ins/String/prototype/startsWith/out-of-bounds-position.js
  69. * - test/built-ins/String/prototype/startsWith/return-true-if-searchstring-is-empty.js
  70. * - test/built-ins/String/prototype/startsWith/coerced-values-of-position.js
  71. * - test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success.js
  72. * - test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_2.js
  73. * - test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_3.js
  74. * - test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_4.js
  75. * - test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail.js
  76. * - test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail_2.js
  77. * - test/built-ins/String/prototype/endsWith/searchstring-found-with-position.js
  78. * - test/built-ins/String/prototype/endsWith/searchstring-found-without-position.js
  79. * - test/built-ins/String/prototype/endsWith/searchstring-not-found-with-position.js
  80. * - test/built-ins/String/prototype/endsWith/searchstring-not-found-without-position.js
  81. * - test/built-ins/String/prototype/endsWith/return-false-if-search-start-is-less-than-zero.js
  82. * - test/built-ins/String/prototype/endsWith/return-true-if-searchstring-is-empty.js
  83. * - test/built-ins/String/prototype/endsWith/coerced-values-of-position.js
  84. * - test/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T1.js
  85. * - test/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T2.js
  86. * - test/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T3.js
  87. * - test/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T4.js
  88. * - test/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T1.js
  89. * - test/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T3.js
  90. * - test/built-ins/String/prototype/indexOf/position-tointeger.js
  91. * - test/built-ins/String/prototype/indexOf/searchstring-tostring.js
  92. * - test/built-ins/String/prototype/lastIndexOf/not-a-substring.js
  93. *
  94. * Copyright 2009 the Sputnik authors. All rights reserved.
  95. * Copyright (c) 2014 Ryan Lewis. All rights reserved.
  96. * Copyright (C) 2015 the V8 project authors. All rights reserved.
  97. * Copyright (C) 2016 the V8 project authors. All rights reserved.
  98. * Copyright (C) 2017 Josh Wolfe. All rights reserved.
  99. * Copyright (C) 2020 Leo Balter. All rights reserved.
  100. * Copyright (C) 2026 Garham Lee. All rights reserved.
  101. * Test262 portions are governed by the BSD license in LICENSE.test262.
  102. */
  103. import { describe, expect, test } from "bun:test"
  104. import { Effect } from "effect"
  105. import { CodeMode } from "../src/index.js"
  106. const value = async (code: string) => {
  107. const result = await Effect.runPromise(CodeMode.execute({ code, tools: {} }))
  108. if (!result.ok) throw new Error(`expected success, got ${result.error.kind}: ${result.error.message}`)
  109. return result.value
  110. }
  111. const cases = [
  112. {
  113. path: "test/built-ins/String/prototype/split/call-split-l-0-instance-is-string-hello.js",
  114. code: `const result = "hello".split("l", 0); return [result.length, result[0] === undefined]`,
  115. expected: [0, true],
  116. labels: [
  117. "The value of __split.length is expected to equal the value of __expected.length",
  118. "The value of __split[0] is expected to equal the value of __expected[0]",
  119. ],
  120. },
  121. {
  122. path: "test/built-ins/String/prototype/split/call-split-l-1-instance-is-string-hello.js",
  123. code: `const result = "hello".split("l", 1); return [result.length, result[0]]`,
  124. expected: [1, "he"],
  125. labels: [
  126. "The value of __split.length is expected to equal the value of __expected.length",
  127. "The value of __split[0] is expected to equal the value of __expected[0]",
  128. ],
  129. },
  130. {
  131. path: "test/built-ins/String/prototype/split/call-split-l-2-instance-is-string-hello.js",
  132. code: `const result = "hello".split("l", 2); return [result.length, result[0], result[1]]`,
  133. expected: [2, "he", ""],
  134. labels: [
  135. "The value of __split.length is expected to equal the value of __expected.length",
  136. "The value of __split[index] is expected to equal the value of __expected[index]",
  137. "The value of __split[index] is expected to equal the value of __expected[index]",
  138. ],
  139. },
  140. {
  141. path: "test/built-ins/String/prototype/split/call-split-l-3-instance-is-string-hello.js",
  142. code: `const result = "hello".split("l", 3); return [result.length, result[0], result[1], result[2]]`,
  143. expected: [3, "he", "", "o"],
  144. labels: [
  145. "The value of __split.length is expected to equal the value of __expected.length",
  146. "The value of __split[index] is expected to equal the value of __expected[index]",
  147. "The value of __split[index] is expected to equal the value of __expected[index]",
  148. "The value of __split[index] is expected to equal the value of __expected[index]",
  149. ],
  150. },
  151. {
  152. path: "test/built-ins/String/prototype/split/call-split-l-4-instance-is-string-hello.js",
  153. code: `const result = "hello".split("l", 4); return [result.length, result[0], result[1], result[2]]`,
  154. expected: [3, "he", "", "o"],
  155. labels: [
  156. "The value of __split.length is expected to equal the value of __expected.length",
  157. "The value of __split[index] is expected to equal the value of __expected[index]",
  158. "The value of __split[index] is expected to equal the value of __expected[index]",
  159. "The value of __split[index] is expected to equal the value of __expected[index]",
  160. ],
  161. },
  162. {
  163. path: "test/built-ins/String/prototype/split/call-split-l-na-n-instance-is-string-hello.js",
  164. code: `const result = "hello".split("l", NaN); return [result.length, result[0] === undefined]`,
  165. expected: [0, true],
  166. labels: [
  167. "The value of __split.length is expected to equal the value of __expected.length",
  168. "The value of __split[0] is expected to equal the value of __expected[0]",
  169. ],
  170. },
  171. {
  172. path: "test/built-ins/String/prototype/split/call-split-l-instance-is-string-hello.js",
  173. code: `const result = "hello".split("l"); return [result.length, result[0], result[1], result[2]]`,
  174. expected: [3, "he", "", "o"],
  175. labels: [
  176. "The value of __split.length is 3",
  177. 'The value of __split[0] is "he"',
  178. 'The value of __split[1] is ""',
  179. 'The value of __split[2] is "o"',
  180. ],
  181. },
  182. {
  183. path: "test/built-ins/String/prototype/split/call-split-ll-instance-is-string-hello.js",
  184. code: `const result = "hello".split("ll"); return [result.length, result[0], result[1]]`,
  185. expected: [2, "he", "o"],
  186. labels: ["The value of __split.length is 2", 'The value of __split[0] is "he"', 'The value of __split[1] is "o"'],
  187. },
  188. {
  189. path: "test/built-ins/String/prototype/split/call-split-h-instance-is-string-hello.js",
  190. code: `const result = "hello".split("h"); return [result.length, result[0], result[1]]`,
  191. expected: [2, "", "ello"],
  192. labels: ["The value of __split.length is 2", 'The value of __split[0] is ""', 'The value of __split[1] is "ello"'],
  193. },
  194. {
  195. path: "test/built-ins/String/prototype/split/call-split-hello-instance-is-string-hello.js",
  196. code: `const result = "hello".split("hello"); return [result.length, result[0], result[1]]`,
  197. expected: [2, "", ""],
  198. labels: ["The value of __split.length is 2", 'The value of __split[0] is ""', 'The value of __split[1] is ""'],
  199. },
  200. {
  201. path: "test/built-ins/String/prototype/split/call-split-hellothere-instance-is-string-hello.js",
  202. code: `const result = "hello".split("hellothere"); return [result.length, result[0]]`,
  203. expected: [1, "hello"],
  204. labels: ["The value of __split.length is 1", 'The value of __split[0] is "hello"'],
  205. },
  206. {
  207. path: "test/built-ins/String/prototype/split/call-split-o-instance-is-string-hello.js",
  208. code: `const result = "hello".split("o"); return [result.length, result[0], result[1]]`,
  209. expected: [2, "hell", ""],
  210. labels: ["The value of __split.length is 2", 'The value of __split[0] is "hell"', 'The value of __split[1] is ""'],
  211. },
  212. {
  213. path: "test/built-ins/String/prototype/split/call-split-x-instance-is-string-hello.js",
  214. code: `const result = "hello".split("x"); return [result.length, result[0]]`,
  215. expected: [1, "hello"],
  216. labels: ["The value of __split.length is 1", 'The value of __split[0] is "hello"'],
  217. },
  218. {
  219. path: "test/built-ins/String/prototype/split/call-split-x-instance-is-empty-string.js",
  220. code: `const result = "".split("x"); return [result.length, result[0]]`,
  221. expected: [1, ""],
  222. labels: ["The value of __split.length is 1", 'The value of __split[0] is ""'],
  223. },
  224. {
  225. path: "test/built-ins/String/prototype/split/call-split-4-instance-is-string-one-1-two-2-four-4.js",
  226. code: `const result = "one-1 two-2 four-4".split("-4"); return [result.length, result[0], result[1]]`,
  227. expected: [2, "one-1 two-2 four", ""],
  228. labels: [
  229. "The value of __split.length is 2",
  230. 'The value of __split[0] is "one-1 two-2 four"',
  231. 'The value of __split[1] is ""',
  232. ],
  233. },
  234. {
  235. path: "test/built-ins/String/prototype/split/call-split-on-instance-is-string-one-1-two-2-four-4.js",
  236. code: `const result = "one-1 two-2 four-4".split("on"); return [result.length, result[0], result[1]]`,
  237. expected: [2, "", "e-1 two-2 four-4"],
  238. labels: [
  239. "The value of __split.length is 2",
  240. 'The value of __split[0] is ""',
  241. 'The value of __split[1] is "e-1 two-2 four-4"',
  242. ],
  243. },
  244. {
  245. path: "test/built-ins/String/prototype/split/call-split-instance-is-string-one-two-three-four-five.js",
  246. code: `const result = "one two three four five".split(" "); return [result.length, ...result]`,
  247. expected: [5, "one", "two", "three", "four", "five"],
  248. labels: [
  249. "The value of __split.length is 5", 'The value of __split[0] is "one"', 'The value of __split[1] is "two"',
  250. 'The value of __split[2] is "three"', 'The value of __split[3] is "four"', 'The value of __split[4] is "five"',
  251. ],
  252. },
  253. {
  254. path: "test/built-ins/String/prototype/split/call-split-instance-is-string-one-two-three.js",
  255. code: `const result = "one two three".split(""); return [result[0], result[1], result[11], result[12]]`,
  256. expected: ["o", "n", "e", "e"],
  257. labels: [
  258. 'The value of __split[0] is "o"', 'The value of __split[1] is "n"',
  259. 'The value of __split[11] is "e"', 'The value of __split[12] is "e"',
  260. ],
  261. },
  262. {
  263. path: "test/built-ins/String/prototype/split/call-split-instance-is-string.js",
  264. code: `const result = " ".split(" "); return [result.length, result[0], result[1]]`,
  265. expected: [2, "", ""],
  266. labels: ["The value of __split.length is 2", 'The value of __split[0] is ""', 'The value of __split[1] is ""'],
  267. },
  268. {
  269. path: "test/built-ins/String/prototype/split/instance-is-string-one-two-three-four-five.js",
  270. code: `const result = "one,two,three,four,five".split(); return [result.length, result[0]]`,
  271. expected: [1, "one,two,three,four,five"],
  272. labels: ["The value of __split.length is 1", 'The value of __split[0] is "one,two,three,four,five"'],
  273. },
  274. {
  275. path: "test/built-ins/String/prototype/split/instance-is-string.js",
  276. code: `const result = " ".split(); return [result.length, result[0]]`,
  277. expected: [1, " "],
  278. labels: ["The value of __split.length is 1", 'The value of __split[0] is " "'],
  279. },
  280. {
  281. path: "test/built-ins/String/prototype/split/separator-colon-instance-is-string-one-1-two-2-four-4.js",
  282. code: `const result = "one-1,two-2,four-4".split(":"); return [result.length, result[0]]`,
  283. expected: [1, "one-1,two-2,four-4"],
  284. labels: ["The value of __split.length is 1", 'The value of __split[0] is "one-1,two-2,four-4"'],
  285. },
  286. {
  287. path: "test/built-ins/String/prototype/split/separator-comma-instance-is-string-one-two-three-four-five.js",
  288. code: `const result = "one,two,three,four,five".split(","); return [result.length, ...result]`,
  289. expected: [5, "one", "two", "three", "four", "five"],
  290. labels: [
  291. "The value of __split.length is 5",
  292. 'The value of __split[0] is "one"',
  293. 'The value of __split[1] is "two"',
  294. 'The value of __split[2] is "three"',
  295. 'The value of __split[3] is "four"',
  296. 'The value of __split[4] is "five"',
  297. ],
  298. },
  299. {
  300. path: "test/built-ins/String/prototype/split/separator-empty-string-instance-is-string.js",
  301. code: `const result = " ".split(""); return [result.length, result[0]]`,
  302. expected: [1, " "],
  303. labels: ["The value of __split.length is 1", 'The value of __split[0] is " "'],
  304. },
  305. {
  306. path: "test/built-ins/String/prototype/split/call-split-without-arguments-and-instance-is-empty-string.js",
  307. code: `const result = "".split(); return [result.length, result[0]]`,
  308. expected: [1, ""],
  309. labels: ["The value of __split.length is 1", 'The value of __split[0] is ""'],
  310. },
  311. {
  312. path: "test/built-ins/String/prototype/split/separator-undef.js",
  313. code: `const result = "undefined is not a function".split(); return [Array.isArray(result), result.length, result[0]]`,
  314. expected: [true, 1, "undefined is not a function"],
  315. labels: ["implicit separator, result is array", "implicit separator, result.length", "implicit separator, [0] is the same string"],
  316. },
  317. {
  318. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A1_T6.js",
  319. code: `return ["undefined".slice(undefined, 3)]`,
  320. expected: ["und"],
  321. labels: ['#1: new String("undefined").slice(x,3) === "und"'],
  322. },
  323. {
  324. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A1_T14.js",
  325. code: `return ["report".slice(undefined)]`,
  326. expected: ["report"],
  327. labels: ['#1: "report".slice(function(){}()) === "report"'],
  328. },
  329. {
  330. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A2_T1.js",
  331. code: `return [typeof "this is a string object".slice()]`,
  332. expected: ["string"],
  333. labels: ['#1: typeof __string.slice() === "string"'],
  334. },
  335. {
  336. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A2_T2.js",
  337. code: `return ["this is a string object".slice(NaN, Infinity)]`,
  338. expected: ["this is a string object"],
  339. labels: ['#1: __string.slice(NaN, Infinity) === "this is a string object"'],
  340. },
  341. {
  342. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A2_T3.js",
  343. code: `return ["".slice(1, 0)]`,
  344. expected: [""],
  345. labels: ['#1: __string.slice(1,0) === ""'],
  346. },
  347. {
  348. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A2_T4.js",
  349. code: `return ["this is a string object".slice(Infinity, NaN)]`,
  350. expected: [""],
  351. labels: ['#1: __string.slice(Infinity, NaN) === ""'],
  352. },
  353. {
  354. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A2_T5.js",
  355. code: `return ["this is a string object".slice(Infinity, Infinity)]`,
  356. expected: [""],
  357. labels: ['#1: __string.slice(Infinity, Infinity) === ""'],
  358. },
  359. {
  360. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A2_T6.js",
  361. code: `return ["this is a string object".slice(-0.01, 0)]`,
  362. expected: [""],
  363. labels: ['#1: __string.slice(-0.01,0) === ""'],
  364. },
  365. {
  366. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A2_T7.js",
  367. code: `const text = "this is a string object"; return [text.slice(text.length, text.length)]`,
  368. expected: [""],
  369. labels: ['#1: __string.slice(__string.length, __string.length) === ""'],
  370. },
  371. {
  372. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A2_T8.js",
  373. code: `const text = "this is a string object"; return [text.slice(text.length + 1, 0)]`,
  374. expected: [""],
  375. labels: ['#1: __string.slice(__string.length+1, 0) === ""'],
  376. },
  377. {
  378. path: "test/built-ins/String/prototype/slice/S15.5.4.13_A2_T9.js",
  379. code: `return ["this is a string object".slice(-Infinity, -Infinity)]`,
  380. expected: [""],
  381. labels: ['#1: __string.slice(-Infinity, -Infinity) === ""'],
  382. },
  383. {
  384. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A1_T6.js",
  385. code: `return ["undefined".substring(undefined, 3)]`,
  386. expected: ["und"],
  387. labels: ['#1: new String("undefined").substring(x,3) === "und"'],
  388. },
  389. {
  390. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A1_T14.js",
  391. code: `return ["report".substring(undefined)]`,
  392. expected: ["report"],
  393. labels: ['#1: "report".substring(function(){}()) === "report"'],
  394. },
  395. {
  396. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T1.js",
  397. code: `return [typeof "this is a string object".substring()]`,
  398. expected: ["string"],
  399. labels: ['#1: typeof __string.substring() === "string"'],
  400. },
  401. {
  402. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T2.js",
  403. code: `return ["this is a string object".substring(NaN, Infinity)]`,
  404. expected: ["this is a string object"],
  405. labels: ['#1: __string.substring(NaN, Infinity) === "this is a string object"'],
  406. },
  407. {
  408. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T3.js",
  409. code: `return ["".substring(1, 0)]`,
  410. expected: [""],
  411. labels: ['#1: __string.substring(1,0) === ""'],
  412. },
  413. {
  414. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T4.js",
  415. code: `return ["this is a string object".substring(Infinity, NaN)]`,
  416. expected: ["this is a string object"],
  417. labels: ['#1: __string.substring(Infinity, NaN) === "this is a string object"'],
  418. },
  419. {
  420. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T5.js",
  421. code: `return ["this is a string object".substring(Infinity, Infinity)]`,
  422. expected: [""],
  423. labels: ['#1: __string.substring(Infinity, Infinity) === ""'],
  424. },
  425. {
  426. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T6.js",
  427. code: `return ["this is a string object".substring(-0.01, 0)]`,
  428. expected: [""],
  429. labels: ['#1: __string.substring(-0.01,0) === ""'],
  430. },
  431. {
  432. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T7.js",
  433. code: `const text = "this is a string object"; return [text.substring(text.length, text.length)]`,
  434. expected: [""],
  435. labels: ['#1: __string.substring(__string.length, __string.length) === ""'],
  436. },
  437. {
  438. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T8.js",
  439. code: `const text = "this is a string object"; return [text.substring(text.length + 1, 0)]`,
  440. expected: ["this is a string object"],
  441. labels: ['#1: __string.substring(__string.length+1, 0) === "this is a string object"'],
  442. },
  443. {
  444. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T9.js",
  445. code: `return ["this is a string object".substring(-Infinity, -Infinity)]`,
  446. expected: [""],
  447. labels: ['#1: __string.substring(-Infinity, -Infinity) === ""'],
  448. },
  449. {
  450. path: "test/built-ins/String/prototype/substring/S15.5.4.15_A2_T10.js",
  451. code: `return ["this_is_a_string object".substring(0, 8)]`,
  452. expected: ["this_is_"],
  453. labels: ['#1: __string.substring(0,8) === "this_is_"'],
  454. },
  455. {
  456. path: "test/built-ins/String/prototype/includes/String.prototype.includes_FailMissingLetter.js",
  457. code: `return ["word".includes("a", 0)]`, expected: [false], labels: ['"word".includes("a", 0)'],
  458. },
  459. {
  460. path: "test/built-ins/String/prototype/includes/String.prototype.includes_SuccessNoLocation.js",
  461. code: `return ["word".includes("w")]`, expected: [true], labels: ['"word".includes("w")'],
  462. },
  463. {
  464. path: "test/built-ins/String/prototype/includes/String.prototype.includes_FailBadLocation.js",
  465. code: `return ["word".includes("w", 5)]`, expected: [false], labels: ['"word".includes("w", 5)'],
  466. },
  467. {
  468. path: "test/built-ins/String/prototype/includes/String.prototype.includes_FailLocation.js",
  469. code: `return ["word".includes("o", 3)]`, expected: [false], labels: ['"word".includes("o", 3)'],
  470. },
  471. {
  472. path: "test/built-ins/String/prototype/includes/String.prototype.includes_Success.js",
  473. code: `return ["word".includes("w", 0)]`, expected: [true], labels: ['"word".includes("w", 0)'],
  474. },
  475. {
  476. path: "test/built-ins/String/prototype/includes/searchstring-found-with-position.js",
  477. code: `const text = "The future is cool!"; return [text.includes("The future", 0), text.includes(" is ", 1), text.includes("cool!", 10)]`,
  478. expected: [true, true, true],
  479. labels: [
  480. 'Returns true for str.includes("The future", 0)',
  481. 'Returns true for str.includes(" is ", 1)',
  482. 'Returns true for str.includes("cool!", 10)',
  483. ],
  484. },
  485. {
  486. path: "test/built-ins/String/prototype/includes/searchstring-found-without-position.js",
  487. code: `const text = "The future is cool!"; return [text.includes("The future"), text.includes("is cool!"), text.includes(text)]`,
  488. expected: [true, true, true],
  489. labels: [
  490. 'Returns true for str.includes("The future")',
  491. 'Returns true for str.includes("is cool!")',
  492. "Returns true for str.includes(str)",
  493. ],
  494. },
  495. {
  496. path: "test/built-ins/String/prototype/includes/searchstring-not-found-with-position.js",
  497. code: `const text = "The future is cool!"; return [text.includes("The future", 1), text.includes(text, 1)]`,
  498. expected: [false, false],
  499. labels: ['Returns false on str.includes("The future", 1)', "Returns false on str.includes(str, 1)"],
  500. },
  501. {
  502. path: "test/built-ins/String/prototype/includes/searchstring-not-found-without-position.js",
  503. code: `const text = "The future is cool!"; return [text.includes("Flash"), text.includes("FUTURE")]`,
  504. expected: [false, false], labels: ["Flash if not included", "includes is case sensitive"],
  505. },
  506. {
  507. path: "test/built-ins/String/prototype/includes/return-false-with-out-of-bounds-position.js",
  508. code: `const text = "The future is cool!"; return [
  509. text.includes("!", text.length + 1), text.includes("!", 100), text.includes("!", Infinity), text.includes("!", text.length),
  510. ]`,
  511. expected: [false, false, false, false],
  512. labels: [
  513. 'str.includes("!", str.length + 1) returns false', 'str.includes("!", 100) returns false',
  514. 'str.includes("!", Infinity) returns false', 'str.includes("!", str.length) returns false',
  515. ],
  516. },
  517. {
  518. path: "test/built-ins/String/prototype/includes/return-true-if-searchstring-is-empty.js",
  519. code: `const text = "The future is cool!"; return [text.includes("", text.length), text.includes(""), text.includes("", Infinity)]`,
  520. expected: [true, true, true],
  521. labels: ['str.includes("", str.length) returns true', 'str.includes("") returns true', 'str.includes("", Infinity) returns true'],
  522. },
  523. {
  524. path: "test/built-ins/String/prototype/includes/coerced-values-of-position.js",
  525. code: `const text = "The future is cool!"; return [
  526. text.includes("The future", NaN), text.includes("The future", undefined), text.includes("The future", 0.4),
  527. text.includes("The future", -1), text.includes("The future", 1.4),
  528. ]`,
  529. expected: [true, true, true, true, false],
  530. labels: ["NaN coerced to 0", "undefined coerced to 0", "0.4 coerced to 0", "negative position", "1.4 coerced to 1"],
  531. },
  532. {
  533. path: "test/built-ins/String/prototype/startsWith/searchstring-found-with-position.js",
  534. code: `const text = "The future is cool!"; return [text.startsWith("The future", 0), text.startsWith("future", 4), text.startsWith(" is cool!", 10)]`,
  535. expected: [true, true, true],
  536. labels: [
  537. 'str.startsWith("The future", 0) === true', 'str.startsWith("future", 4) === true',
  538. 'str.startsWith(" is cool!", 10) === true',
  539. ],
  540. },
  541. {
  542. path: "test/built-ins/String/prototype/startsWith/searchstring-found-without-position.js",
  543. code: `const text = "The future is cool!"; return [text.startsWith("The "), text.startsWith("The future"), text.startsWith(text)]`,
  544. expected: [true, true, true],
  545. labels: ['str.startsWith("The ") === true', 'str.startsWith("The future") === true', "str.startsWith(str) === true"],
  546. },
  547. {
  548. path: "test/built-ins/String/prototype/startsWith/searchstring-not-found-with-position.js",
  549. code: `const text = "The future is cool!"; return [text.startsWith("The future", 1), text.startsWith(text, 1)]`,
  550. expected: [false, false],
  551. labels: ['str.startsWith("The future", 1) === false', "str.startsWith(str, 1) === false"],
  552. },
  553. {
  554. path: "test/built-ins/String/prototype/startsWith/searchstring-not-found-without-position.js",
  555. code: `const text = "The future is cool!"; return [text.startsWith("Flash"), text.startsWith("THE FUTURE"), text.startsWith("future is cool!")]`,
  556. expected: [false, false, false],
  557. labels: ['str.startsWith("Flash") === false', "startsWith is case sensitive", 'str.startsWith("future is cool!") === false'],
  558. },
  559. {
  560. path: "test/built-ins/String/prototype/startsWith/out-of-bounds-position.js",
  561. code: `const text = "The future is cool!"; return [
  562. text.startsWith("!", text.length), text.startsWith("!", 100), text.startsWith("!", Infinity),
  563. text.startsWith("The future", -1), text.startsWith("The future", -Infinity),
  564. ]`,
  565. expected: [false, false, false, true, true],
  566. labels: [
  567. 'str.startsWith("!", str.length) returns false', 'str.startsWith("!", 100) returns false',
  568. 'str.startsWith("!", Infinity) returns false', "position argument < 0 will search from the start of the string (-1)",
  569. "position argument < 0 will search from the start of the string (-Infinity)",
  570. ],
  571. },
  572. {
  573. path: "test/built-ins/String/prototype/startsWith/return-true-if-searchstring-is-empty.js",
  574. code: `const text = "The future is cool!"; return [text.startsWith(""), text.startsWith("", text.length), text.startsWith("", Infinity)]`,
  575. expected: [true, true, true],
  576. labels: ['str.startsWith("") returns true', 'str.startsWith("", str.length) returns true', 'str.startsWith("", Infinity) returns true'],
  577. },
  578. {
  579. path: "test/built-ins/String/prototype/startsWith/coerced-values-of-position.js",
  580. code: `const text = "The future is cool!"; return [
  581. text.startsWith("The future", NaN), text.startsWith("The future", undefined),
  582. text.startsWith("The future", 0.4), text.startsWith("The future", 1.4),
  583. ]`,
  584. expected: [true, true, true, false],
  585. labels: ["NaN coerced to 0", "undefined coerced to 0", "0.4 coerced to 0", "1.4 coerced to 1"],
  586. },
  587. {
  588. path: "test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success.js",
  589. code: `return ["word".endsWith("d")]`, expected: [true], labels: ['"word".endsWith("d")'],
  590. },
  591. {
  592. path: "test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_2.js",
  593. code: `return ["word".endsWith("d", 4)]`, expected: [true], labels: ['"word".endsWith("d", 4)'],
  594. },
  595. {
  596. path: "test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_3.js",
  597. code: `return ["word".endsWith("d", 25)]`, expected: [true], labels: ['"word".endsWith("d", 25)'],
  598. },
  599. {
  600. path: "test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_4.js",
  601. code: `return ["word".endsWith("r", 3)]`, expected: [true], labels: ['"word".endsWith("r", 3)'],
  602. },
  603. {
  604. path: "test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail.js",
  605. code: `return ["word".endsWith("r")]`, expected: [false], labels: ['"word".endsWith("r")'],
  606. },
  607. {
  608. path: "test/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail_2.js",
  609. code: `return ["word".endsWith("d", 3)]`, expected: [false], labels: ['"word".endsWith("d", 3)'],
  610. },
  611. {
  612. path: "test/built-ins/String/prototype/endsWith/searchstring-found-with-position.js",
  613. code: `const text = "The future is cool!"; return [text.endsWith("The future", 10), text.endsWith("future", 10), text.endsWith(" is cool!", text.length)]`,
  614. expected: [true, true, true],
  615. labels: [
  616. 'str.endsWith("The future", 10) === true', 'str.endsWith("future", 10) === true',
  617. 'str.endsWith(" is cool!", str.length) === true',
  618. ],
  619. },
  620. {
  621. path: "test/built-ins/String/prototype/endsWith/searchstring-found-without-position.js",
  622. code: `const text = "The future is cool!"; return [text.endsWith("cool!"), text.endsWith("!"), text.endsWith(text)]`,
  623. expected: [true, true, true],
  624. labels: ['str.endsWith("cool!") === true', 'str.endsWith("!") === true', "str.endsWith(str) === true"],
  625. },
  626. {
  627. path: "test/built-ins/String/prototype/endsWith/searchstring-not-found-with-position.js",
  628. code: `const text = "The future is cool!"; return [text.endsWith("is cool!", text.length - 1), text.endsWith("!", 1)]`,
  629. expected: [false, false],
  630. labels: ['str.endsWith("is cool!", str.length - 1) === false', 'str.endsWith("!", 1) === false'],
  631. },
  632. {
  633. path: "test/built-ins/String/prototype/endsWith/searchstring-not-found-without-position.js",
  634. code: `const text = "The future is cool!"; return [text.endsWith("is Flash!"), text.endsWith("IS COOL!"), text.endsWith("The future")]`,
  635. expected: [false, false, false],
  636. labels: ['str.endsWith("is Flash!") === false', "endsWith is case sensitive", 'str.endsWith("The future") === false'],
  637. },
  638. {
  639. path: "test/built-ins/String/prototype/endsWith/return-false-if-search-start-is-less-than-zero.js",
  640. code: `return ["web".endsWith("w", 0), "Bob".endsWith(" Bob")]`,
  641. expected: [false, false],
  642. labels: ['"web".endsWith("w", 0) returns false', '"Bob".endsWith(" Bob") returns false'],
  643. },
  644. {
  645. path: "test/built-ins/String/prototype/endsWith/return-true-if-searchstring-is-empty.js",
  646. code: `const text = "The future is cool!"; return [
  647. text.endsWith(""), text.endsWith("", text.length), text.endsWith("", Infinity),
  648. text.endsWith("", -1), text.endsWith("", -Infinity),
  649. ]`,
  650. expected: [true, true, true, true, true],
  651. labels: [
  652. 'str.endsWith("") returns true', 'str.endsWith("", str.length) returns true', 'str.endsWith("", Infinity) returns true',
  653. 'str.endsWith("", -1) returns true', 'str.endsWith("", -Infinity) returns true',
  654. ],
  655. },
  656. {
  657. path: "test/built-ins/String/prototype/endsWith/coerced-values-of-position.js",
  658. code: `const text = "The future is cool!"; return [
  659. text.endsWith("", NaN), text.endsWith("", undefined), text.endsWith("The future", 10.4),
  660. ]`,
  661. expected: [true, true, true],
  662. labels: ["NaN coerced to 0", "undefined coerced to 0", "10.4 coerced to 10"],
  663. },
  664. {
  665. path: "test/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T1.js",
  666. code: `return ["abcd".indexOf("abcdab")]`, expected: [-1], labels: ['#1: "abcd".indexOf("abcdab")===-1'],
  667. },
  668. {
  669. path: "test/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T2.js",
  670. code: `return ["abcd".indexOf("abcdab", 0)]`, expected: [-1], labels: ['#1: "abcd".indexOf("abcdab",0)===-1'],
  671. },
  672. {
  673. path: "test/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T3.js",
  674. code: `return ["abcd".indexOf("abcdab", 99)]`, expected: [-1], labels: ['#1: "abcd".indexOf("abcdab",99)===-1'],
  675. },
  676. {
  677. path: "test/built-ins/String/prototype/indexOf/S15.5.4.7_A2_T4.js",
  678. code: `return ["abcd".indexOf("abcdab", NaN)]`, expected: [-1], labels: ['#1: "abcd".indexOf("abcdab",NaN)===-1'],
  679. },
  680. {
  681. path: "test/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T1.js",
  682. code: `return ["$$abcdabcd".indexOf("ab", NaN)]`, expected: [2], labels: ['#1: "$$abcdabcd".indexOf("ab",NaN)===2'],
  683. },
  684. {
  685. path: "test/built-ins/String/prototype/indexOf/S15.5.4.7_A3_T3.js",
  686. code: `return ["$$abcdabcd".indexOf("ab", -Infinity)]`, expected: [2], labels: ['#1: "$$abcdabcd".indexOf("ab", function(){return -Infinity;}())===2'],
  687. },
  688. {
  689. path: "test/built-ins/String/prototype/indexOf/position-tointeger.js",
  690. code: `return [
  691. "aaaa".indexOf("aa", 0), "aaaa".indexOf("aa", 1), "aaaa".indexOf("aa", -0.9),
  692. "aaaa".indexOf("aa", 0.9), "aaaa".indexOf("aa", 1.9), "aaaa".indexOf("aa", NaN),
  693. "aaaa".indexOf("aa", Infinity), "aaaa".indexOf("aa", undefined),
  694. "aaaa".indexOf("aa", 2), "aaaa".indexOf("aa", 2.9),
  695. ]`,
  696. expected: [0, 1, 0, 0, 1, 0, -1, 0, 2, 2],
  697. labels: [
  698. "position 0", "position 1", "ToInteger: truncate towards 0 (-0.9)", "ToInteger: truncate towards 0 (0.9)",
  699. "ToInteger: truncate towards 0 (1.9)", "ToInteger: NaN => 0", "position Infinity",
  700. "ToInteger: undefined => NaN => 0", "position 2", "ToInteger: truncate towards 0 (2.9)",
  701. ],
  702. },
  703. {
  704. path: "test/built-ins/String/prototype/indexOf/searchstring-tostring.js",
  705. code: `return ["foo".indexOf(""), "__foo__".indexOf("foo")]`,
  706. expected: [0, 2], labels: ['"foo".indexOf("")', '"__foo__".indexOf("foo")'],
  707. },
  708. {
  709. path: "test/built-ins/String/prototype/lastIndexOf/not-a-substring.js",
  710. code: `return ["abc".lastIndexOf("d")]`,
  711. expected: [-1],
  712. labels: ["String.prototype.lastIndexOf returns -1 when searchString is shorter than this and searchString is not a substring of this."],
  713. },
  714. ] as const
  715. describe("Test262-adapted String search and extraction behavior", () => {
  716. for (const item of cases) {
  717. test(item.path, async () => {
  718. const actual = await value(item.code)
  719. if (!Array.isArray(actual)) throw new Error(`expected assertion values for ${item.path}`)
  720. expect(actual.length, "adapted assertion count").toBe(item.expected.length)
  721. item.expected.forEach((expected, index) => expect(actual[index], item.labels[index]!).toEqual(expected))
  722. })
  723. }
  724. })