1 // ♓🌟 Piscēs ∷ string.test.js
2 // ====================================================================
4 // Copyright © 2022–2023 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
19 } from "./dev-deps.js";
23 canonicalNumericIndexString
,
30 getFirstSubstringIndex
,
31 getLastSubstringIndex
,
38 splitOnAsciiWhitespace
,
58 stripAndCollapseAsciiWhitespace
,
59 stripLeadingAndTrailingAsciiWhitespace
,
65 describe("Matcher", () => {
66 it("[[Call]] throws an error", () => {
67 assertThrows(() => Matcher(""));
70 it("[[Construct]] accepts a string first argument", () => {
71 assert(new Matcher(""));
74 it("[[Construct]] accepts a unicode regular expression first argument", () => {
75 assert(new Matcher(/(?:)/u));
78 it("[[Construct]] throws with a non·unicode regular expression first argument", () => {
79 assertThrows(() => new Matcher(/(?:)/));
82 it("[[Construct]] creates a callable object", () => {
83 assertStrictEquals(typeof new Matcher(""), "function");
86 it("[[Construct]] creates a new Matcher", () => {
88 Object
.getPrototypeOf(new Matcher("")),
93 it("[[Construct]] creates an object which inherits from RegExp", () => {
94 assert(new Matcher("") instanceof RegExp
);
97 it("[[Construct]] throws when provided with a noncallable, non·null third argument", () => {
98 assertThrows(() => new Matcher("", undefined, "failure"));
101 describe(".length", () => {
102 it("[[Get]] returns the correct length", () => {
103 assertStrictEquals(Matcher
.length
, 1);
107 describe(".name", () => {
108 it("[[Get]] returns the correct name", () => {
109 assertStrictEquals(Matcher
.name
, "Matcher");
113 describe("::dotAll", () => {
114 it("[[Get]] returns true when the dotAll flag is present", () => {
115 assertStrictEquals(new Matcher(/(?:)/su).dotAll
, true);
118 it("[[Get]] returns false when the dotAll flag is not present", () => {
119 assertStrictEquals(new Matcher(/(?:)/u).dotAll
, false);
122 describe(".length", () => {
123 it("[[Get]] returns the correct length", () => {
125 Object
.getOwnPropertyDescriptor(
134 describe(".name", () => {
135 it("[[Get]] returns the correct name", () => {
137 Object
.getOwnPropertyDescriptor(
147 describe("::exec", () => {
148 it("[[Call]] returns the match object given a complete match", () => {
150 [...new Matcher(/.(?<wow>(?:.(?=.))*)(.)?/u).exec("success")],
151 ["success", "ucces", "s"],
155 /.(?<wow>(?:.(?=.))*)(.)?/u,
157 ($) => $ === "success",
159 ["success", "ucces", "s"],
163 it("[[Call]] calls the constraint if the match succeeds", () => {
164 const constraint
= spy((_
) => true);
165 const matcher
= new Matcher("(.).*", undefined, constraint
);
166 const result
= matcher
.exec({
171 assertEquals([...result
], ["etaoin", "e"]);
172 assertSpyCalls(constraint
, 1);
173 assertStrictEquals(constraint
.calls
[0].args
[0], "etaoin");
174 assertEquals([...constraint
.calls
[0].args
[1]], ["etaoin", "e"]);
175 assertStrictEquals(constraint
.calls
[0].args
[2], matcher
);
176 assertStrictEquals(constraint
.calls
[0].self
, undefined);
179 it("[[Call]] does not call the constraint if the match fails", () => {
180 const constraint
= spy((_
) => true);
181 const matcher
= new Matcher("", undefined, constraint
);
182 matcher
.exec("failure");
183 assertSpyCalls(constraint
, 0);
186 it("[[Call]] returns null given a partial match", () => {
187 assertStrictEquals(new Matcher("").exec("failure"), null);
190 it("[[Call]] returns null if the constraint fails", () => {
192 new Matcher(".*", undefined, () => false).exec(""),
197 describe(".length", () => {
198 it("[[Get]] returns the correct length", () => {
199 assertStrictEquals(Matcher
.prototype.exec
.length
, 1);
203 describe(".name", () => {
204 it("[[Get]] returns the correct name", () => {
205 assertStrictEquals(Matcher
.prototype.exec
.name
, "exec");
210 describe("::global", () => {
211 it("[[Get]] returns true when the global flag is present", () => {
212 assertStrictEquals(new Matcher(/(?:)/gu).global
, true);
215 it("[[Get]] returns false when the global flag is not present", () => {
216 assertStrictEquals(new Matcher(/(?:)/u).global
, false);
219 describe(".length", () => {
220 it("[[Get]] returns the correct length", () => {
222 Object
.getOwnPropertyDescriptor(
231 describe(".name", () => {
232 it("[[Get]] returns the correct name", () => {
234 Object
.getOwnPropertyDescriptor(
244 describe("::hasIndices", () => {
245 it("[[Get]] returns true when the hasIndices flag is present", () => {
246 assertStrictEquals(new Matcher(/(?:)/du).hasIndices
, true);
249 it("[[Get]] returns false when the hasIndices flag is not present", () => {
250 assertStrictEquals(new Matcher(/(?:)/u).hasIndices
, false);
253 describe(".length", () => {
254 it("[[Get]] returns the correct length", () => {
256 Object
.getOwnPropertyDescriptor(
265 describe(".name", () => {
266 it("[[Get]] returns the correct name", () => {
268 Object
.getOwnPropertyDescriptor(
278 describe("::ignoreCase", () => {
279 it("[[Get]] returns true when the ignoreCase flag is present", () => {
280 assertStrictEquals(new Matcher(/(?:)/iu).ignoreCase
, true);
283 it("[[Get]] returns false when the ignoreCase flag is not present", () => {
284 assertStrictEquals(new Matcher(/(?:)/u).ignoreCase
, false);
287 describe(".length", () => {
288 it("[[Get]] returns the correct length", () => {
290 Object
.getOwnPropertyDescriptor(
299 describe(".name", () => {
300 it("[[Get]] returns the correct name", () => {
302 Object
.getOwnPropertyDescriptor(
312 describe("::multiline", () => {
313 it("[[Get]] returns true when the multiline flag is present", () => {
314 assertStrictEquals(new Matcher(/(?:)/mu).multiline
, true);
317 it("[[Get]] returns false when the multiline flag is not present", () => {
318 assertStrictEquals(new Matcher(/(?:)/u).multiline
, false);
321 describe(".length", () => {
322 it("[[Get]] returns the correct length", () => {
324 Object
.getOwnPropertyDescriptor(
333 describe(".name", () => {
334 it("[[Get]] returns the correct name", () => {
336 Object
.getOwnPropertyDescriptor(
346 describe("::source", () => {
347 it("[[Get]] returns the RegExp source", () => {
348 assertStrictEquals(new Matcher("").source
, "(?:)");
349 assertStrictEquals(new Matcher(/.*/su).source
, ".*");
352 describe(".length", () => {
353 it("[[Get]] returns the correct length", () => {
355 Object
.getOwnPropertyDescriptor(
364 describe(".name", () => {
365 it("[[Get]] returns the correct name", () => {
367 Object
.getOwnPropertyDescriptor(
377 describe("::sticky", () => {
378 it("[[Get]] returns true when the sticky flag is present", () => {
379 assertStrictEquals(new Matcher(/(?:)/uy).sticky
, true);
382 it("[[Get]] returns false when the sticky flag is not present", () => {
383 assertStrictEquals(new Matcher(/(?:)/u).sticky
, false);
386 describe(".length", () => {
387 it("[[Get]] returns the correct length", () => {
389 Object
.getOwnPropertyDescriptor(
398 describe(".name", () => {
399 it("[[Get]] returns the correct name", () => {
401 Object
.getOwnPropertyDescriptor(
411 describe("::toString", () => {
412 it("[[Call]] returns the string source", () => {
413 assertStrictEquals(new Matcher(/(?:)/u).toString(), "/(?:)/u");
417 describe("::unicode", () => {
418 it("[[Get]] returns true when the unicode flag is present", () => {
419 assertStrictEquals(new Matcher(/(?:)/u).unicode
, true);
422 describe(".length", () => {
423 it("[[Get]] returns the correct length", () => {
425 Object
.getOwnPropertyDescriptor(
434 describe(".name", () => {
435 it("[[Get]] returns the correct name", () => {
437 Object
.getOwnPropertyDescriptor(
447 describe("~", () => {
448 it("[[Call]] returns true for a complete match", () => {
449 assertStrictEquals(new Matcher("")(""), true);
450 assertStrictEquals(new Matcher(/.*/su)("success\nyay"), true);
452 new Matcher(/.*/su, undefined, ($) => $ === "success")(
459 it("[[Call]] calls the constraint if the match succeeds", () => {
460 const constraint
= spy((_
) => true);
461 const matcher
= new Matcher("(.).*", undefined, constraint
);
463 assertSpyCalls(constraint
, 1);
464 assertStrictEquals(constraint
.calls
[0].args
[0], "etaoin");
465 assertEquals([...constraint
.calls
[0].args
[1]], ["etaoin", "e"]);
466 assertStrictEquals(constraint
.calls
[0].args
[2], matcher
);
467 assertStrictEquals(constraint
.calls
[0].self
, undefined);
470 it("[[Call]] does not call the constraint if the match fails", () => {
471 const constraint
= spy((_
) => true);
472 const matcher
= new Matcher("", undefined, constraint
);
474 assertSpyCalls(constraint
, 0);
477 it("[[Call]] returns false for a partial match", () => {
478 assertStrictEquals(new Matcher("")("failure"), false);
479 assertStrictEquals(new Matcher(/.*/u)("failure\nno"), false);
482 it("[[Call]] returns false if the constraint fails", () => {
484 new Matcher(".*", undefined, () => false)(""),
490 describe("~lastIndex", () => {
491 it("[[Get]] returns zero", () => {
492 assertStrictEquals(new Matcher("").lastIndex
, 0);
495 it("[[Set]] fails", () => {
496 assertThrows(() => (new Matcher("").lastIndex
= 1));
500 describe("~length", () => {
501 it("[[Get]] returns one", () => {
502 assertStrictEquals(new Matcher("").length
, 1);
506 describe("~name", () => {
507 it("[[Get]] wraps the stringified regular expression if no name was provided", () => {
508 assertStrictEquals(new Matcher("").name
, "Matcher(/(?:)/u)");
510 new Matcher(/.*/gsu).name
,
515 it("[[Get]] uses the provided name if one was provided", () => {
516 assertStrictEquals(new Matcher("", "success").name
, "success");
521 describe("asciiLowercase", () => {
522 it("[[Call]] lowercases (just) A·S·C·I·I letters", () => {
523 assertStrictEquals(asciiLowercase("aBſÆss FtɁɂß"), "abſÆss ftɁɂß");
526 it("[[Construct]] throws an error", () => {
527 assertThrows(() => new asciiLowercase(""));
530 describe(".length", () => {
531 it("[[Get]] returns the correct length", () => {
532 assertStrictEquals(asciiLowercase
.length
, 1);
536 describe(".name", () => {
537 it("[[Get]] returns the correct name", () => {
538 assertStrictEquals(asciiLowercase
.name
, "asciiLowercase");
543 describe("asciiUppercase", () => {
544 it("[[Call]] uppercases (just) A·S·C·I·I letters", () => {
545 assertStrictEquals(asciiUppercase("aBſÆss FtɁɂß"), "ABſÆSS FTɁɂß");
548 it("[[Construct]] throws an error", () => {
549 assertThrows(() => new asciiUppercase(""));
552 describe(".length", () => {
553 it("[[Get]] returns the correct length", () => {
554 assertStrictEquals(asciiUppercase
.length
, 1);
558 describe(".name", () => {
559 it("[[Get]] returns the correct name", () => {
560 assertStrictEquals(asciiUppercase
.name
, "asciiUppercase");
565 describe("canonicalNumericIndexString", () => {
566 it("[[Call]] returns undefined for nonstrings", () => {
567 assertStrictEquals(canonicalNumericIndexString(1), void {});
570 it("[[Call]] returns undefined for noncanonical strings", () => {
571 assertStrictEquals(canonicalNumericIndexString(""), void {});
572 assertStrictEquals(canonicalNumericIndexString("01"), void {});
574 canonicalNumericIndexString("9007199254740993"),
579 it('[[Call]] returns -0 for "-0"', () => {
580 assertStrictEquals(canonicalNumericIndexString("-0"), -0);
583 it("[[Call]] returns the corresponding number for canonical strings", () => {
584 assertStrictEquals(canonicalNumericIndexString("0"), 0);
585 assertStrictEquals(canonicalNumericIndexString("-0.25"), -0.25);
587 canonicalNumericIndexString("9007199254740992"),
590 assertStrictEquals(canonicalNumericIndexString("NaN"), 0 / 0);
591 assertStrictEquals(canonicalNumericIndexString("Infinity"), 1 / 0);
593 canonicalNumericIndexString("-Infinity"),
598 it("[[Construct]] throws an error", () => {
599 assertThrows(() => new canonicalNumericIndexString(""));
602 describe(".length", () => {
603 it("[[Get]] returns the correct length", () => {
604 assertStrictEquals(canonicalNumericIndexString
.length
, 1);
608 describe(".name", () => {
609 it("[[Get]] returns the correct name", () => {
611 canonicalNumericIndexString
.name
,
612 "canonicalNumericIndexString",
618 describe("characters", () => {
619 it("[[Call]] returns an iterable", () => {
621 typeof characters("")[Symbol
.iterator
],
626 it("[[Call]] returns an iterator", () => {
627 assertStrictEquals(typeof characters("").next
, "function");
630 it("[[Call]] returns a string character iterator", () => {
632 characters("")[Symbol
.toStringTag
],
633 "String Character Iterator",
637 it("[[Call]] iterates over the characters", () => {
639 ...characters("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
653 it("[[Construct]] throws an error", () => {
654 assertThrows(() => new characters(""));
657 describe(".length", () => {
658 it("[[Get]] returns the correct length", () => {
659 assertStrictEquals(characters
.length
, 1);
663 describe(".name", () => {
664 it("[[Get]] returns the correct name", () => {
665 assertStrictEquals(characters
.name
, "characters");
670 describe("codeUnits", () => {
671 it("[[Call]] returns an iterable", () => {
673 typeof codeUnits("")[Symbol
.iterator
],
678 it("[[Call]] returns an iterator", () => {
679 assertStrictEquals(typeof codeUnits("").next
, "function");
682 it("[[Call]] returns a string code unit iterator", () => {
684 codeUnits("")[Symbol
.toStringTag
],
685 "String Code Unit Iterator",
689 it("[[Call]] iterates over the code units", () => {
691 ...codeUnits("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
707 it("[[Construct]] throws an error", () => {
708 assertThrows(() => new codeUnits(""));
711 describe(".length", () => {
712 it("[[Get]] returns the correct length", () => {
713 assertStrictEquals(codeUnits
.length
, 1);
717 describe(".name", () => {
718 it("[[Get]] returns the correct name", () => {
719 assertStrictEquals(codeUnits
.name
, "codeUnits");
724 describe("codepoints", () => {
725 it("[[Call]] returns an iterable", () => {
727 typeof codepoints("")[Symbol
.iterator
],
732 it("[[Call]] returns an iterator", () => {
733 assertStrictEquals(typeof codepoints("").next
, "function");
736 it("[[Call]] returns a string codepoint iterator", () => {
738 codepoints("")[Symbol
.toStringTag
],
739 "String Codepoint Iterator",
743 it("[[Call]] iterates over the codepoints", () => {
745 ...codepoints("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
759 it("[[Construct]] throws an error", () => {
760 assertThrows(() => new codepoints(""));
763 describe(".length", () => {
764 it("[[Get]] returns the correct length", () => {
765 assertStrictEquals(codepoints
.length
, 1);
769 describe(".name", () => {
770 it("[[Get]] returns the correct name", () => {
771 assertStrictEquals(codepoints
.name
, "codepoints");
776 describe("getCharacter", () => {
777 it("[[Call]] returns the character at the provided position", () => {
778 assertStrictEquals(getCharacter("Ii🎙🆗☺", 4), "🆗");
781 it("[[Call]] returns a low surrogate if the provided position splits a character", () => {
782 assertStrictEquals(getCharacter("Ii🎙🆗☺", 5), "\uDD97");
785 it("[[Call]] returns undefined for an out‐of‐bounds index", () => {
786 assertStrictEquals(getCharacter("Ii🎙🆗☺", -1), undefined);
787 assertStrictEquals(getCharacter("Ii🎙🆗☺", 7), undefined);
790 it("[[Construct]] throws an error", () => {
791 assertThrows(() => new getCharacter("a", 0));
794 describe(".length", () => {
795 it("[[Get]] returns the correct length", () => {
796 assertStrictEquals(getCharacter
.length
, 2);
800 describe(".name", () => {
801 it("[[Get]] returns the correct name", () => {
802 assertStrictEquals(getCharacter
.name
, "getCharacter");
807 describe("getCodeUnit", () => {
808 it("[[Call]] returns the code unit at the provided position", () => {
809 assertStrictEquals(getCodeUnit("Ii🎙🆗☺", 4), 0xD83C);
812 it("[[Call]] returns a low surrogate if the provided position splits a character", () => {
813 assertStrictEquals(getCodeUnit("Ii🎙🆗☺", 5), 0xDD97);
816 it("[[Call]] returns undefined for an out‐of‐bounds index", () => {
817 assertStrictEquals(getCodeUnit("Ii🎙🆗☺", -1), undefined);
818 assertStrictEquals(getCodeUnit("Ii🎙🆗☺", 7), undefined);
821 it("[[Construct]] throws an error", () => {
822 assertThrows(() => new getCodeUnit("a", 0));
825 describe(".length", () => {
826 it("[[Get]] returns the correct length", () => {
827 assertStrictEquals(getCodeUnit
.length
, 2);
831 describe(".name", () => {
832 it("[[Get]] returns the correct name", () => {
833 assertStrictEquals(getCodeUnit
.name
, "getCodeUnit");
838 describe("getCodepoint", () => {
839 it("[[Call]] returns the character at the provided position", () => {
840 assertStrictEquals(getCodepoint("Ii🎙🆗☺", 4), 0x1F197);
843 it("[[Call]] returns a low surrogate if the provided position splits a character", () => {
844 assertStrictEquals(getCodepoint("Ii🎙🆗☺", 5), 0xDD97);
847 it("[[Call]] returns undefined for an out‐of‐bounds index", () => {
848 assertStrictEquals(getCodepoint("Ii🎙🆗☺", -1), undefined);
849 assertStrictEquals(getCodepoint("Ii🎙🆗☺", 7), undefined);
852 it("[[Construct]] throws an error", () => {
853 assertThrows(() => new getCodepoint("a", 0));
856 describe(".length", () => {
857 it("[[Get]] returns the correct length", () => {
858 assertStrictEquals(getCodepoint
.length
, 2);
862 describe(".name", () => {
863 it("[[Get]] returns the correct name", () => {
864 assertStrictEquals(getCodepoint
.name
, "getCodepoint");
869 describe("getFirstSubstringIndex", () => {
870 it("[[Call]] returns the index of the first match", () => {
871 assertStrictEquals(getFirstSubstringIndex("Ii🎙🆗☺🆗", "🆗"), 4);
874 it("[[Call]] returns −1 if no match is found", () => {
875 assertStrictEquals(getFirstSubstringIndex("Ii🎙🆗☺🆗", "🆗🆖"), -1);
878 it("[[Call]] returns 0 when provided with an empty string", () => {
879 assertStrictEquals(getFirstSubstringIndex("Ii🎙🆗☺🆗", ""), 0);
882 it("[[Construct]] throws an error", () => {
883 assertThrows(() => new getFirstSubstringIndex("", ""));
886 describe(".length", () => {
887 it("[[Get]] returns the correct length", () => {
888 assertStrictEquals(getFirstSubstringIndex
.length
, 2);
892 describe(".name", () => {
893 it("[[Get]] returns the correct name", () => {
895 getFirstSubstringIndex
.name
,
896 "getFirstSubstringIndex",
902 describe("getLastSubstringIndex", () => {
903 it("[[Call]] returns the index of the first match", () => {
904 assertStrictEquals(getLastSubstringIndex("Ii🎙🆗☺🆗", "🆗"), 7);
907 it("[[Call]] returns −1 if no match is found", () => {
908 assertStrictEquals(getLastSubstringIndex("Ii🎙🆗☺🆗", "🆖🆗"), -1);
911 it("[[Call]] returns the length when provided with an empty string", () => {
913 getLastSubstringIndex("Ii🎙🆗☺🆗", ""),
918 it("[[Construct]] throws an error", () => {
919 assertThrows(() => new getLastSubstringIndex("", ""));
922 describe(".length", () => {
923 it("[[Get]] returns the correct length", () => {
924 assertStrictEquals(getLastSubstringIndex
.length
, 2);
928 describe(".name", () => {
929 it("[[Get]] returns the correct name", () => {
931 getLastSubstringIndex
.name
,
932 "getLastSubstringIndex",
938 describe("isArrayIndexString", () => {
939 it("[[Call]] returns false for nonstrings", () => {
940 assertStrictEquals(isArrayIndexString(1), false);
943 it("[[Call]] returns false for noncanonical strings", () => {
944 assertStrictEquals(isArrayIndexString(""), false);
945 assertStrictEquals(isArrayIndexString("01"), false);
946 assertStrictEquals(isArrayIndexString("9007199254740993"), false);
949 it("[[Call]] returns false for nonfinite numbers", () => {
950 assertStrictEquals(isArrayIndexString("NaN"), false);
951 assertStrictEquals(isArrayIndexString("Infinity"), false);
952 assertStrictEquals(isArrayIndexString("-Infinity"), false);
955 it("[[Call]] returns false for negative numbers", () => {
956 assertStrictEquals(isArrayIndexString("-0"), false);
957 assertStrictEquals(isArrayIndexString("-1"), false);
960 it("[[Call]] returns false for nonintegers", () => {
961 assertStrictEquals(isArrayIndexString("0.25"), false);
962 assertStrictEquals(isArrayIndexString("1.1"), false);
965 it("[[Call]] returns false for numbers greater than or equal to -1 >>> 0", () => {
966 assertStrictEquals(isArrayIndexString(String(-1 >>> 0)), false);
968 isArrayIndexString(String((-1 >>> 0) + 1)),
973 it("[[Call]] returns true for array lengths less than -1 >>> 0", () => {
974 assertStrictEquals(isArrayIndexString("0"), true);
976 isArrayIndexString(String((-1 >>> 0) - 1)),
981 it("[[Construct]] throws an error", () => {
982 assertThrows(() => new isArrayIndexString("0"));
985 describe(".length", () => {
986 it("[[Get]] returns the correct length", () => {
987 assertStrictEquals(isArrayIndexString
.length
, 1);
991 describe(".name", () => {
992 it("[[Get]] returns the correct name", () => {
994 isArrayIndexString
.name
,
995 "isArrayIndexString",
1001 describe("isIntegerIndexString", () => {
1002 it("[[Call]] returns false for nonstrings", () => {
1003 assertStrictEquals(isIntegerIndexString(1), false);
1006 it("[[Call]] returns false for noncanonical strings", () => {
1007 assertStrictEquals(isIntegerIndexString(""), false);
1008 assertStrictEquals(isIntegerIndexString("01"), false);
1010 isIntegerIndexString("9007199254740993"),
1015 it("[[Call]] returns false for nonfinite numbers", () => {
1016 assertStrictEquals(isIntegerIndexString("NaN"), false);
1017 assertStrictEquals(isIntegerIndexString("Infinity"), false);
1018 assertStrictEquals(isIntegerIndexString("-Infinity"), false);
1021 it("[[Call]] returns false for negative numbers", () => {
1022 assertStrictEquals(isIntegerIndexString("-0"), false);
1023 assertStrictEquals(isIntegerIndexString("-1"), false);
1026 it("[[Call]] returns false for nonintegers", () => {
1027 assertStrictEquals(isIntegerIndexString("0.25"), false);
1028 assertStrictEquals(isIntegerIndexString("1.1"), false);
1031 it("[[Call]] returns false for numbers greater than or equal to 2 ** 53", () => {
1033 isIntegerIndexString("9007199254740992"),
1038 it("[[Call]] returns true for safe canonical integer strings", () => {
1039 assertStrictEquals(isIntegerIndexString("0"), true);
1040 assertStrictEquals(isIntegerIndexString("9007199254740991"), true);
1043 it("[[Construct]] throws an error", () => {
1044 assertThrows(() => new isIntegerIndexString("0"));
1047 describe(".length", () => {
1048 it("[[Get]] returns the correct length", () => {
1049 assertStrictEquals(isIntegerIndexString
.length
, 1);
1053 describe(".name", () => {
1054 it("[[Get]] returns the correct name", () => {
1056 isIntegerIndexString
.name
,
1057 "isIntegerIndexString",
1063 describe("join", () => {
1064 it("[[Call]] joins the provided iterator with the provided separartor", () => {
1065 assertStrictEquals(join([1, 2, 3, 4].values(), "☂"), "1☂2☂3☂4");
1068 it('[[Call]] uses "," if no separator is provided', () => {
1069 assertStrictEquals(join([1, 2, 3, 4].values()), "1,2,3,4");
1072 it("[[Call]] uses the empty sting for nullish values", () => {
1074 join([null, , null, undefined].values(), "☂"),
1079 it("[[Construct]] throws an error", () => {
1080 assertThrows(() => new join([]));
1083 describe(".length", () => {
1084 it("[[Get]] returns the correct length", () => {
1085 assertStrictEquals(join
.length
, 2);
1089 describe(".name", () => {
1090 it("[[Get]] returns the correct name", () => {
1091 assertStrictEquals(join
.name
, "join");
1096 describe("rawString", () => {
1097 it("[[Call]] acts like String.raw", () => {
1098 assertStrictEquals(rawString
`\nraw${" string"}`, "\\nraw string");
1101 it("[[Construct]] throws an error", () => {
1102 assertThrows(() => new rawString(["string"]));
1105 describe(".length", () => {
1106 it("[[Get]] returns the correct length", () => {
1107 assertStrictEquals(rawString
.length
, 1);
1111 describe(".name", () => {
1112 it("[[Get]] returns the correct name", () => {
1113 assertStrictEquals(rawString
.name
, "rawString");
1118 describe("scalarValues", () => {
1119 it("[[Call]] returns an iterable", () => {
1121 typeof scalarValues("")[Symbol
.iterator
],
1126 it("[[Call]] returns an iterator", () => {
1127 assertStrictEquals(typeof scalarValues("").next
, "function");
1130 it("[[Call]] returns a string scalar value iterator", () => {
1132 scalarValues("")[Symbol
.toStringTag
],
1133 "String Scalar Value Iterator",
1137 it("[[Call]] iterates over the scalar values", () => {
1139 ...scalarValues("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
1153 it("[[Construct]] throws an error", () => {
1154 assertThrows(() => new scalarValues(""));
1157 describe(".length", () => {
1158 it("[[Get]] returns the correct length", () => {
1159 assertStrictEquals(scalarValues
.length
, 1);
1163 describe(".name", () => {
1164 it("[[Get]] returns the correct name", () => {
1165 assertStrictEquals(scalarValues
.name
, "scalarValues");
1170 describe("splitOnAsciiWhitespace", () => {
1171 it("[[Call]] splits on sequences of spaces", () => {
1173 splitOnAsciiWhitespace("🅰️ 🅱️ 🆎 🅾️"),
1174 ["🅰️", "🅱️", "🆎", "🅾️"],
1178 it("[[Call]] splits on sequences of tabs", () => {
1180 splitOnAsciiWhitespace("🅰️\t\t\t🅱️\t🆎\t\t🅾️"),
1181 ["🅰️", "🅱️", "🆎", "🅾️"],
1185 it("[[Call]] splits on sequences of carriage returns", () => {
1187 splitOnAsciiWhitespace("🅰️\r\r\r🅱️\r🆎\r\r🅾️"),
1188 ["🅰️", "🅱️", "🆎", "🅾️"],
1192 it("[[Call]] splits on sequences of newlines", () => {
1194 splitOnAsciiWhitespace("🅰️\r\r\r🅱️\r🆎\r\r🅾️"),
1195 ["🅰️", "🅱️", "🆎", "🅾️"],
1199 it("[[Call]] splits on sequences of form feeds", () => {
1201 splitOnAsciiWhitespace("🅰️\f\f\f🅱️\f🆎\f\f🅾️"),
1202 ["🅰️", "🅱️", "🆎", "🅾️"],
1206 it("[[Call]] splits on mixed whitespace", () => {
1208 splitOnAsciiWhitespace("🅰️\f \t\n🅱️\r\n\r🆎\n\f🅾️"),
1209 ["🅰️", "🅱️", "🆎", "🅾️"],
1213 it("[[Call]] returns an array of just the empty string for the empty string", () => {
1214 assertEquals(splitOnAsciiWhitespace(""), [""]);
1217 it("[[Call]] returns a single token if there are no spaces", () => {
1218 assertEquals(splitOnAsciiWhitespace("abcd"), ["abcd"]);
1221 it("[[Call]] does not split on other kinds of whitespace", () => {
1223 splitOnAsciiWhitespace("a\u202F\u205F\xa0\v\0\bb"),
1224 ["a\u202F\u205F\xa0\v\0\bb"],
1228 it("[[Call]] trims leading and trailing whitespace", () => {
1230 splitOnAsciiWhitespace(
1231 "\f\r\n\r\n \n\t🅰️\f \t\n🅱️\r🆎\n\f🅾️\n\f",
1233 ["🅰️", "🅱️", "🆎", "🅾️"],
1237 it("[[Construct]] throws an error", () => {
1238 assertThrows(() => new splitOnAsciiWhitespace(""));
1241 describe(".length", () => {
1242 it("[[Get]] returns the correct length", () => {
1243 assertStrictEquals(splitOnAsciiWhitespace
.length
, 1);
1247 describe(".name", () => {
1248 it("[[Get]] returns the correct name", () => {
1250 splitOnAsciiWhitespace
.name
,
1251 "splitOnAsciiWhitespace",
1257 describe("splitOnCommas", () => {
1258 it("[[Call]] splits on commas", () => {
1260 splitOnCommas("🅰️,🅱️,🆎,🅾️"),
1261 ["🅰️", "🅱️", "🆎", "🅾️"],
1265 it("[[Call]] returns an array of just the empty string for the empty string", () => {
1266 assertEquals(splitOnCommas(""), [""]);
1269 it("[[Call]] returns a single token if there are no commas", () => {
1270 assertEquals(splitOnCommas("abcd"), ["abcd"]);
1273 it("[[Call]] splits into empty strings if there are only commas", () => {
1274 assertEquals(splitOnCommas(",,,"), ["", "", "", ""]);
1277 it("[[Call]] trims leading and trailing whitespace", () => {
1279 splitOnCommas("\f\r\n\r\n \n\t🅰️,🅱️,🆎,🅾️\n\f"),
1280 ["🅰️", "🅱️", "🆎", "🅾️"],
1283 splitOnCommas("\f\r\n\r\n \n\t,,,\n\f"),
1288 it("[[Call]] removes whitespace from the split tokens", () => {
1291 "\f\r\n\r\n \n\t🅰️\f , \t\n🅱️,\r\n\r🆎\n\f,🅾️\n\f",
1293 ["🅰️", "🅱️", "🆎", "🅾️"],
1296 splitOnCommas("\f\r\n\r\n \n\t\f , \t\n,\r\n\r\n\f,\n\f"),
1301 it("[[Construct]] throws an error", () => {
1302 assertThrows(() => new splitOnCommas(""));
1305 describe(".length", () => {
1306 it("[[Get]] returns the correct length", () => {
1307 assertStrictEquals(splitOnCommas
.length
, 1);
1311 describe(".name", () => {
1312 it("[[Get]] returns the correct name", () => {
1313 assertStrictEquals(splitOnCommas
.name
, "splitOnCommas");
1318 describe("stringCatenate", () => {
1319 it("[[Call]] catenates the values", () => {
1320 assertStrictEquals(stringCatenate("the", " values"), "the values");
1323 it("[[Call]] returns an empty string when called with no values", () => {
1324 assertStrictEquals(stringCatenate(), "");
1327 it('[[Call]] uses "undefined" when explicitly provided undefined', () => {
1329 stringCatenate(undefined, undefined),
1330 "undefinedundefined",
1334 it('[[Call]] uses "null" when provided null', () => {
1335 assertStrictEquals(stringCatenate(null, null), "nullnull");
1338 it("[[Construct]] throws an error", () => {
1339 assertThrows(() => new stringCatenate());
1342 describe(".length", () => {
1343 it("[[Get]] returns the correct length", () => {
1344 assertStrictEquals(stringCatenate
.length
, 2);
1348 describe(".name", () => {
1349 it("[[Get]] returns the correct name", () => {
1350 assertStrictEquals(stringCatenate
.name
, "stringCatenate");
1355 describe("stringEndsWith", () => {
1356 it("[[Call]] returns whether the string ends with the thing", () => {
1358 stringEndsWith("very success", " success"),
1361 assertStrictEquals(stringEndsWith("very fail", " success"), false);
1364 it("[[Call]] accepts an offset", () => {
1366 stringEndsWith("very successful", " success", 12),
1371 it("[[Call]] returns true for an empty string test", () => {
1372 assertStrictEquals(stringEndsWith("", ""), true);
1375 it("[[Construct]] throws an error", () => {
1376 assertThrows(() => new stringEndsWith("", ""));
1379 describe(".length", () => {
1380 it("[[Get]] returns the correct length", () => {
1381 assertStrictEquals(stringEndsWith
.length
, 2);
1385 describe(".name", () => {
1386 it("[[Get]] returns the correct name", () => {
1387 assertStrictEquals(stringEndsWith
.name
, "stringEndsWith");
1392 describe("stringFromCodeUnits", () => {
1393 it("[[Call]] makes the string", () => {
1395 stringFromCodeUnits(0xD83C, 0xDD97),
1400 it("[[Call]] throws with non‐integral arguments", () => {
1401 assertThrows(() => stringFromCodeUnits(NaN
));
1402 assertThrows(() => stringFromCodeUnits(Infinity
));
1403 assertThrows(() => stringFromCodeUnits(0.1));
1406 it("[[Call]] throws with arguments out of range", () => {
1407 assertThrows(() => stringFromCodeUnits(-1));
1408 assertThrows(() => stringFromCodeUnits(0x10000));
1411 it("[[Construct]] throws an error", () => {
1412 assertThrows(() => new stringFromCodeUnits([]));
1415 describe(".length", () => {
1416 it("[[Get]] returns the correct length", () => {
1417 assertStrictEquals(stringFromCodeUnits
.length
, 1);
1421 describe(".name", () => {
1422 it("[[Get]] returns the correct name", () => {
1424 stringFromCodeUnits
.name
,
1425 "stringFromCodeUnits",
1431 describe("stringFromCodepoints", () => {
1432 it("[[Call]] makes the string", () => {
1433 assertStrictEquals(stringFromCodepoints(0x1F197), "🆗");
1436 it("[[Call]] throws with non‐integral arguments", () => {
1437 assertThrows(() => stringFromCodepoints(NaN
));
1438 assertThrows(() => stringFromCodepoints(Infinity
));
1439 assertThrows(() => stringFromCodepoints(0.1));
1442 it("[[Call]] throws with arguments out of range", () => {
1443 assertThrows(() => stringFromCodepoints(-1));
1444 assertThrows(() => stringFromCodepoints(0x110000));
1447 it("[[Construct]] throws an error", () => {
1448 assertThrows(() => new stringFromCodepoints([]));
1451 describe(".length", () => {
1452 it("[[Get]] returns the correct length", () => {
1453 assertStrictEquals(stringFromCodepoints
.length
, 1);
1457 describe(".name", () => {
1458 it("[[Get]] returns the correct name", () => {
1460 stringFromCodepoints
.name
,
1461 "stringFromCodepoints",
1467 describe("stringIncludes", () => {
1468 it("[[Call]] returns whether the string includes the thing", () => {
1470 stringIncludes("very success full", " success "),
1474 stringIncludes("very fail full", " success "),
1479 it("[[Call]] accepts an offset", () => {
1481 stringIncludes("maybe success full", " success ", 4),
1485 stringIncludes("maybe success full", " success ", 5),
1489 stringIncludes("maybe success full", " success ", 6),
1494 it("[[Call]] returns true for an empty string test", () => {
1495 assertStrictEquals(stringIncludes("", ""), true);
1498 it("[[Construct]] throws an error", () => {
1499 assertThrows(() => new stringIncludes("", ""));
1502 describe(".length", () => {
1503 it("[[Get]] returns the correct length", () => {
1504 assertStrictEquals(stringIncludes
.length
, 2);
1508 describe(".name", () => {
1509 it("[[Get]] returns the correct name", () => {
1510 assertStrictEquals(stringIncludes
.name
, "stringIncludes");
1515 describe("stringMatch", () => {
1516 it("[[Call]] does the match akin to String::match", () => {
1518 [...stringMatch("very success full", /([sc]+[ue]?)+/)],
1522 [...stringMatch("very success full", /([sc]+)[ue]?/g)],
1523 ["su", "cce", "ss"],
1527 it("[[Construct]] throws an error", () => {
1528 assertThrows(() => new stringMatch("", /(?:)/));
1531 describe(".length", () => {
1532 it("[[Get]] returns the correct length", () => {
1533 assertStrictEquals(stringMatch
.length
, 2);
1537 describe(".name", () => {
1538 it("[[Get]] returns the correct name", () => {
1539 assertStrictEquals(stringMatch
.name
, "stringMatch");
1544 describe("stringMatchAll", () => {
1545 it("[[Call]] does the match akin to String::matchAll", () => {
1547 [...stringMatchAll("very success full", /([sc]+)[ue]?/g)].map((
1550 [["su", "s"], ["cce", "cc"], ["ss", "ss"]],
1554 it("[[Construct]] throws an error", () => {
1555 assertThrows(() => new stringMatchAll("", /(?:)/g));
1558 describe(".length", () => {
1559 it("[[Get]] returns the correct length", () => {
1560 assertStrictEquals(stringMatchAll
.length
, 2);
1564 describe(".name", () => {
1565 it("[[Get]] returns the correct name", () => {
1566 assertStrictEquals(stringMatchAll
.name
, "stringMatchAll");
1571 describe("stringNormalize", () => {
1572 it("[[Call]] normalizes the string properly", () => {
1573 assertStrictEquals(stringNormalize("ẛ", "NFC"), "\u1E9B");
1574 assertStrictEquals(stringNormalize("ẛ", "NFD"), "\u017F\u0307");
1575 assertStrictEquals(stringNormalize("ẛ", "NFKC"), "\u1E61");
1576 assertStrictEquals(stringNormalize("ẛ", "NFKD"), "\u0073\u0307");
1579 it("[[Call]] assumes NFC", () => {
1580 assertStrictEquals(stringNormalize("\u017F\u0307"), "\u1E9B");
1583 it("[[Call]] throws with an invalid form", () => {
1584 assertThrows(() => stringNormalize("", "NFB"));
1587 it("[[Construct]] throws an error", () => {
1588 assertThrows(() => new stringNormalize("", "NFC"));
1591 describe(".length", () => {
1592 it("[[Get]] returns the correct length", () => {
1593 assertStrictEquals(stringNormalize
.length
, 1);
1597 describe(".name", () => {
1598 it("[[Get]] returns the correct name", () => {
1599 assertStrictEquals(stringNormalize
.name
, "stringNormalize");
1604 describe("stringPadEnd", () => {
1605 it("[[Call]] pads the end of the string", () => {
1606 assertStrictEquals(stringPadEnd("xx", 3), "xx ");
1607 assertStrictEquals(stringPadEnd("xx", 3, "o"), "xxo");
1608 assertStrictEquals(stringPadEnd("", 3, "xo"), "xox");
1609 assertStrictEquals(stringPadEnd("xx", 3, ""), "xx");
1612 it("[[Construct]] throws an error", () => {
1613 assertThrows(() => new stringPadEnd("", 1));
1616 describe(".length", () => {
1617 it("[[Get]] returns the correct length", () => {
1618 assertStrictEquals(stringPadEnd
.length
, 2);
1622 describe(".name", () => {
1623 it("[[Get]] returns the correct name", () => {
1624 assertStrictEquals(stringPadEnd
.name
, "stringPadEnd");
1629 describe("stringPadStart", () => {
1630 it("[[Call]] pads the start of the string", () => {
1631 assertStrictEquals(stringPadStart("xx", 3), " xx");
1632 assertStrictEquals(stringPadStart("xx", 3, "o"), "oxx");
1633 assertStrictEquals(stringPadStart("", 3, "xo"), "xox");
1634 assertStrictEquals(stringPadStart("xx", 3, ""), "xx");
1637 it("[[Construct]] throws an error", () => {
1638 assertThrows(() => new stringPadStart("", 1));
1641 describe(".length", () => {
1642 it("[[Get]] returns the correct length", () => {
1643 assertStrictEquals(stringPadStart
.length
, 2);
1647 describe(".name", () => {
1648 it("[[Get]] returns the correct name", () => {
1649 assertStrictEquals(stringPadStart
.name
, "stringPadStart");
1654 describe("stringRepeat", () => {
1655 it("[[Call]] repeats the string", () => {
1656 assertStrictEquals(stringRepeat("xx", 3), "xxxxxx");
1657 assertStrictEquals(stringRepeat("", 3), "");
1658 assertStrictEquals(stringRepeat("xx", 0), "");
1661 it("[[Call]] throws for negative repititions", () => {
1662 assertThrows(() => stringRepeat("", -1));
1665 it("[[Call]] throws for infinite repititions", () => {
1666 assertThrows(() => stringRepeat("", Infinity
));
1669 it("[[Construct]] throws an error", () => {
1670 assertThrows(() => new stringRepeat("", 1));
1673 describe(".length", () => {
1674 it("[[Get]] returns the correct length", () => {
1675 assertStrictEquals(stringRepeat
.length
, 2);
1679 describe(".name", () => {
1680 it("[[Get]] returns the correct name", () => {
1681 assertStrictEquals(stringRepeat
.name
, "stringRepeat");
1686 describe("stringReplace", () => {
1687 it("[[Call]] does the replacement akin to String::replace", () => {
1689 stringReplace("it’s a failure", "failure", "success"),
1694 "very success full",
1702 "very success full",
1705 `${$s[0].length}`.repeat($s
[1].length
) +
1706 $s
[0].substring($s
[1].length
),
1708 "very 2u33e22 full",
1712 it("[[Construct]] throws an error", () => {
1713 assertThrows(() => new stringReplace("", /(?:)/, ""));
1716 describe(".length", () => {
1717 it("[[Get]] returns the correct length", () => {
1718 assertStrictEquals(stringReplace
.length
, 3);
1722 describe(".name", () => {
1723 it("[[Get]] returns the correct name", () => {
1724 assertStrictEquals(stringReplace
.name
, "stringReplace");
1729 describe("stringReplaceAll", () => {
1730 it("[[Call]] does the match akin to String::replaceAll", () => {
1732 stringReplaceAll("it’s a failure failure", "failure", "success"),
1733 "it’s a success success",
1737 "very success full",
1740 `${$s[0].length}`.repeat($s
[1].length
) +
1741 $s
[0].substring($s
[1].length
),
1743 "very 2u33e22 full",
1747 it("[[Construct]] throws an error", () => {
1748 assertThrows(() => new stringReplaceAll("", /(?:)/g));
1751 describe(".length", () => {
1752 it("[[Get]] returns the correct length", () => {
1753 assertStrictEquals(stringReplaceAll
.length
, 3);
1757 describe(".name", () => {
1758 it("[[Get]] returns the correct name", () => {
1759 assertStrictEquals(stringReplaceAll
.name
, "stringReplaceAll");
1764 describe("stringSearch", () => {
1765 it("[[Call]] does the search akin to String::search", () => {
1767 stringSearch("very success full", /([sc]+)[ue]?/),
1771 stringSearch("very fail full", /([sc]+)[ue]?/),
1776 it("[[Construct]] throws an error", () => {
1777 assertThrows(() => new stringSearch("", /(?:)/));
1780 describe(".length", () => {
1781 it("[[Get]] returns the correct length", () => {
1782 assertStrictEquals(stringSearch
.length
, 2);
1786 describe(".name", () => {
1787 it("[[Get]] returns the correct name", () => {
1788 assertStrictEquals(stringSearch
.name
, "stringSearch");
1793 describe("stringSlice", () => {
1794 it("[[Call]] slices the string akin to String::search", () => {
1796 stringSlice("very success full", 5, 12),
1800 stringSlice("very success full", -12, -5),
1805 it("[[Construct]] throws an error", () => {
1806 assertThrows(() => new stringSlice("", 0, 0));
1809 describe(".length", () => {
1810 it("[[Get]] returns the correct length", () => {
1811 assertStrictEquals(stringSlice
.length
, 3);
1815 describe(".name", () => {
1816 it("[[Get]] returns the correct name", () => {
1817 assertStrictEquals(stringSlice
.name
, "stringSlice");
1822 describe("stringSplit", () => {
1823 it("[[Call]] splits the string akin to String::split", () => {
1824 assertEquals(stringSplit("success", ""), [
1833 assertEquals(stringSplit("success", /(?<=[aeiou])(?=[^aeiou])/), [
1838 assertEquals(stringSplit("success", "failure"), ["success"]);
1841 it("[[Call]] recognizes a limit", () => {
1842 assertEquals(stringSplit("success", "", 4), ["s", "u", "c", "c"]);
1845 it("[[Construct]] throws an error", () => {
1846 assertThrows(() => new stringSplit("", ""));
1849 describe(".length", () => {
1850 it("[[Get]] returns the correct length", () => {
1851 assertStrictEquals(stringSplit
.length
, 3);
1855 describe(".name", () => {
1856 it("[[Get]] returns the correct name", () => {
1857 assertStrictEquals(stringSplit
.name
, "stringSplit");
1862 describe("stringStartsWith", () => {
1863 it("[[Call]] returns whether the string starts with the thing", () => {
1865 stringStartsWith("success is had", "success "),
1869 stringStartsWith("no success is had", "success "),
1874 it("[[Call]] accepts an offset", () => {
1876 stringStartsWith("much success is had", "success ", 5),
1881 it("[[Call]] returns true for an empty string test", () => {
1882 assertStrictEquals(stringEndsWith("", ""), true);
1885 it("[[Construct]] throws an error", () => {
1886 assertThrows(() => new stringStartsWith("", ""));
1889 describe(".length", () => {
1890 it("[[Get]] returns the correct length", () => {
1891 assertStrictEquals(stringStartsWith
.length
, 2);
1895 describe(".name", () => {
1896 it("[[Get]] returns the correct name", () => {
1897 assertStrictEquals(stringStartsWith
.name
, "stringStartsWith");
1902 describe("stringStartsWith", () => {
1903 it("[[Call]] returns the string value of a string literal", () => {
1904 assertStrictEquals(stringValue("success"), "success");
1907 it("[[Call]] returns the string value of a string object", () => {
1908 const string
= new String("success");
1909 Object
.defineProperties(string
, {
1910 toString
: { value
: () => "failure" },
1911 valueOf
: { value
: () => "failure" },
1913 assertStrictEquals(stringValue(string
), "success");
1916 it("[[Call]] throws for non‐strings", () => {
1917 assertThrows(() => stringValue(Object
.create(String
.prototype)));
1920 it("[[Construct]] throws an error", () => {
1921 assertThrows(() => new stringValue(""));
1924 describe(".length", () => {
1925 it("[[Get]] returns the correct length", () => {
1926 assertStrictEquals(stringValue
.length
, 1);
1930 describe(".name", () => {
1931 it("[[Get]] returns the correct name", () => {
1932 assertStrictEquals(stringValue
.name
, "stringValue");
1937 describe("stripAndCollapseAsciiWhitespace", () => {
1938 it("[[Call]] collapses mixed inner whitespace", () => {
1940 stripAndCollapseAsciiWhitespace("🅰️\f \t\n🅱️\r\n\r🆎\n\f🅾️"),
1945 it("[[Call]] trims leading and trailing whitespace", () => {
1947 stripAndCollapseAsciiWhitespace(
1948 "\f\r\n\r\n \n\t\f 🅰️\f \t\n🅱️\r\n\r🆎\n\f🅾️\n\f",
1954 it("[[Call]] returns the empty string for strings of whitespace", () => {
1956 stripAndCollapseAsciiWhitespace("\f\r\n\r\n \n\t\f \n\f"),
1961 it("[[Call]] does not collapse other kinds of whitespace", () => {
1963 stripAndCollapseAsciiWhitespace("a\u202F\u205F\xa0\v\0\bb"),
1964 "a\u202F\u205F\xa0\v\0\bb",
1968 it("[[Construct]] throws an error", () => {
1969 assertThrows(() => new stripAndCollapseAsciiWhitespace(""));
1972 describe(".length", () => {
1973 it("[[Get]] returns the correct length", () => {
1974 assertStrictEquals(stripAndCollapseAsciiWhitespace
.length
, 1);
1978 describe(".name", () => {
1979 it("[[Get]] returns the correct name", () => {
1981 stripAndCollapseAsciiWhitespace
.name
,
1982 "stripAndCollapseAsciiWhitespace",
1988 describe("stripLeadingAndTrailingAsciiWhitespace", () => {
1989 it("[[Call]] trims leading and trailing whitespace", () => {
1991 stripLeadingAndTrailingAsciiWhitespace(
1992 "\f\r\n\r\n \n\t\f 🅰️🅱️🆎🅾️\n\f",
1998 it("[[Call]] returns the empty string for strings of whitespace", () => {
2000 stripLeadingAndTrailingAsciiWhitespace("\f\r\n\r\n \n\t\f \n\f"),
2005 it("[[Call]] does not trim other kinds of whitespace", () => {
2007 stripLeadingAndTrailingAsciiWhitespace(
2008 "\v\u202F\u205Fx\0\b\xa0",
2010 "\v\u202F\u205Fx\0\b\xa0",
2014 it("[[Call]] does not adjust inner whitespace", () => {
2016 stripLeadingAndTrailingAsciiWhitespace("a b"),
2021 it("[[Construct]] throws an error", () => {
2022 assertThrows(() => new stripLeadingAndTrailingAsciiWhitespace(""));
2025 describe(".length", () => {
2026 it("[[Get]] returns the correct length", () => {
2028 stripLeadingAndTrailingAsciiWhitespace
.length
,
2034 describe(".name", () => {
2035 it("[[Get]] returns the correct name", () => {
2037 stripLeadingAndTrailingAsciiWhitespace
.name
,
2038 "stripLeadingAndTrailingAsciiWhitespace",
2044 describe("substring", () => {
2045 it("[[Call]] returns the substring", () => {
2047 substring("success", 0),
2051 substring("very success full", 5, 12),
2056 it("[[Construct]] throws an error", () => {
2057 assertThrows(() => new substring("", 0));
2060 describe(".length", () => {
2061 it("[[Get]] returns the correct length", () => {
2062 assertStrictEquals(substring
.length
, 3);
2066 describe(".name", () => {
2067 it("[[Get]] returns the correct name", () => {
2068 assertStrictEquals(substring
.name
, "substring");
2073 describe("toScalarValueString", () => {
2074 it("[[Call]] replaces invalid values", () => {
2076 toScalarValueString("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
2077 "Ii🎙\uFFFD\uFFFD\uFFFD\uFFFD🆗☺",
2081 it("[[Construct]] throws an error", () => {
2082 assertThrows(() => new toScalarValueString(""));
2085 describe(".length", () => {
2086 it("[[Get]] returns the correct length", () => {
2087 assertStrictEquals(toScalarValueString
.length
, 1);
2091 describe(".name", () => {
2092 it("[[Get]] returns the correct name", () => {
2094 toScalarValueString
.name
,
2095 "toScalarValueString",
2101 describe("toString", () => {
2102 it("[[Call]] converts to a string", () => {
2113 it("[[Call]] throws when provided a symbol", () => {
2114 assertThrows(() => toString(Symbol()));
2117 it("[[Construct]] throws an error", () => {
2118 assertThrows(() => new toString(""));
2121 describe(".length", () => {
2122 it("[[Get]] returns the correct length", () => {
2123 assertStrictEquals(toString
.length
, 1);
2127 describe(".name", () => {
2128 it("[[Get]] returns the correct name", () => {
2129 assertStrictEquals(toString
.name
, "toString");