string-search-test262.test.ts 41 KB

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