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("::constructor", () => {
114 it("[[Get]] returns the same constructor", () => {
115 assertStrictEquals(new Matcher(/(?:)/su).constructor, Matcher
);
119 describe("::dotAll", () => {
120 it("[[Get]] returns true when the dotAll flag is present", () => {
121 assertStrictEquals(new Matcher(/(?:)/su).dotAll
, true);
124 it("[[Get]] returns false when the dotAll flag is not present", () => {
125 assertStrictEquals(new Matcher(/(?:)/u).dotAll
, false);
128 describe(".length", () => {
129 it("[[Get]] returns the correct length", () => {
131 Object
.getOwnPropertyDescriptor(
140 describe(".name", () => {
141 it("[[Get]] returns the correct name", () => {
143 Object
.getOwnPropertyDescriptor(
153 describe("::exec", () => {
154 it("[[Call]] returns the match object given a complete match", () => {
156 [...new Matcher(/.(?<wow>(?:.(?=.))*)(.)?/u).exec("success")],
157 ["success", "ucces", "s"],
161 /.(?<wow>(?:.(?=.))*)(.)?/u,
163 ($) => $ === "success",
165 ["success", "ucces", "s"],
169 it("[[Call]] calls the constraint if the match succeeds", () => {
170 const constraint
= spy((_
) => true);
171 const matcher
= new Matcher("(.).*", undefined, constraint
);
172 const result
= matcher
.exec({
177 assertEquals([...result
], ["etaoin", "e"]);
178 assertSpyCalls(constraint
, 1);
179 assertStrictEquals(constraint
.calls
[0].args
[0], "etaoin");
180 assertEquals([...constraint
.calls
[0].args
[1]], ["etaoin", "e"]);
181 assertStrictEquals(constraint
.calls
[0].args
[2], matcher
);
182 assertStrictEquals(constraint
.calls
[0].self
, undefined);
185 it("[[Call]] does not call the constraint if the match fails", () => {
186 const constraint
= spy((_
) => true);
187 const matcher
= new Matcher("", undefined, constraint
);
188 matcher
.exec("failure");
189 assertSpyCalls(constraint
, 0);
192 it("[[Call]] returns null given a partial match", () => {
193 assertStrictEquals(new Matcher("").exec("failure"), null);
196 it("[[Call]] returns null if the constraint fails", () => {
198 new Matcher(".*", undefined, () => false).exec(""),
203 describe(".length", () => {
204 it("[[Get]] returns the correct length", () => {
205 assertStrictEquals(Matcher
.prototype.exec
.length
, 1);
209 describe(".name", () => {
210 it("[[Get]] returns the correct name", () => {
211 assertStrictEquals(Matcher
.prototype.exec
.name
, "exec");
216 describe("::global", () => {
217 it("[[Get]] returns true when the global flag is present", () => {
218 assertStrictEquals(new Matcher(/(?:)/gu).global
, true);
221 it("[[Get]] returns false when the global flag is not present", () => {
222 assertStrictEquals(new Matcher(/(?:)/u).global
, false);
225 describe(".length", () => {
226 it("[[Get]] returns the correct length", () => {
228 Object
.getOwnPropertyDescriptor(
237 describe(".name", () => {
238 it("[[Get]] returns the correct name", () => {
240 Object
.getOwnPropertyDescriptor(
250 describe("::hasIndices", () => {
251 it("[[Get]] returns true when the hasIndices flag is present", () => {
252 assertStrictEquals(new Matcher(/(?:)/du).hasIndices
, true);
255 it("[[Get]] returns false when the hasIndices flag is not present", () => {
256 assertStrictEquals(new Matcher(/(?:)/u).hasIndices
, false);
259 describe(".length", () => {
260 it("[[Get]] returns the correct length", () => {
262 Object
.getOwnPropertyDescriptor(
271 describe(".name", () => {
272 it("[[Get]] returns the correct name", () => {
274 Object
.getOwnPropertyDescriptor(
284 describe("::ignoreCase", () => {
285 it("[[Get]] returns true when the ignoreCase flag is present", () => {
286 assertStrictEquals(new Matcher(/(?:)/iu).ignoreCase
, true);
289 it("[[Get]] returns false when the ignoreCase flag is not present", () => {
290 assertStrictEquals(new Matcher(/(?:)/u).ignoreCase
, false);
293 describe(".length", () => {
294 it("[[Get]] returns the correct length", () => {
296 Object
.getOwnPropertyDescriptor(
305 describe(".name", () => {
306 it("[[Get]] returns the correct name", () => {
308 Object
.getOwnPropertyDescriptor(
318 describe("::multiline", () => {
319 it("[[Get]] returns true when the multiline flag is present", () => {
320 assertStrictEquals(new Matcher(/(?:)/mu).multiline
, true);
323 it("[[Get]] returns false when the multiline flag is not present", () => {
324 assertStrictEquals(new Matcher(/(?:)/u).multiline
, false);
327 describe(".length", () => {
328 it("[[Get]] returns the correct length", () => {
330 Object
.getOwnPropertyDescriptor(
339 describe(".name", () => {
340 it("[[Get]] returns the correct name", () => {
342 Object
.getOwnPropertyDescriptor(
352 describe("::source", () => {
353 it("[[Get]] returns the RegExp source", () => {
354 assertStrictEquals(new Matcher("").source
, "(?:)");
355 assertStrictEquals(new Matcher(/.*/su).source
, ".*");
358 describe(".length", () => {
359 it("[[Get]] returns the correct length", () => {
361 Object
.getOwnPropertyDescriptor(
370 describe(".name", () => {
371 it("[[Get]] returns the correct name", () => {
373 Object
.getOwnPropertyDescriptor(
383 describe("::sticky", () => {
384 it("[[Get]] returns true when the sticky flag is present", () => {
385 assertStrictEquals(new Matcher(/(?:)/uy).sticky
, true);
388 it("[[Get]] returns false when the sticky flag is not present", () => {
389 assertStrictEquals(new Matcher(/(?:)/u).sticky
, false);
392 describe(".length", () => {
393 it("[[Get]] returns the correct length", () => {
395 Object
.getOwnPropertyDescriptor(
404 describe(".name", () => {
405 it("[[Get]] returns the correct name", () => {
407 Object
.getOwnPropertyDescriptor(
417 describe("::toString", () => {
418 it("[[Call]] returns the string source", () => {
419 assertStrictEquals(new Matcher(/(?:)/u).toString(), "/(?:)/u");
423 describe("::unicode", () => {
424 it("[[Get]] returns true when the unicode flag is present", () => {
425 assertStrictEquals(new Matcher(/(?:)/u).unicode
, true);
428 describe(".length", () => {
429 it("[[Get]] returns the correct length", () => {
431 Object
.getOwnPropertyDescriptor(
440 describe(".name", () => {
441 it("[[Get]] returns the correct name", () => {
443 Object
.getOwnPropertyDescriptor(
453 describe("~", () => {
454 it("[[Call]] returns true for a complete match", () => {
455 assertStrictEquals(new Matcher("")(""), true);
456 assertStrictEquals(new Matcher(/.*/su)("success\nyay"), true);
458 new Matcher(/.*/su, undefined, ($) => $ === "success")(
465 it("[[Call]] calls the constraint if the match succeeds", () => {
466 const constraint
= spy((_
) => true);
467 const matcher
= new Matcher("(.).*", undefined, constraint
);
469 assertSpyCalls(constraint
, 1);
470 assertStrictEquals(constraint
.calls
[0].args
[0], "etaoin");
471 assertEquals([...constraint
.calls
[0].args
[1]], ["etaoin", "e"]);
472 assertStrictEquals(constraint
.calls
[0].args
[2], matcher
);
473 assertStrictEquals(constraint
.calls
[0].self
, undefined);
476 it("[[Call]] does not call the constraint if the match fails", () => {
477 const constraint
= spy((_
) => true);
478 const matcher
= new Matcher("", undefined, constraint
);
480 assertSpyCalls(constraint
, 0);
483 it("[[Call]] returns false for a partial match", () => {
484 assertStrictEquals(new Matcher("")("failure"), false);
485 assertStrictEquals(new Matcher(/.*/u)("failure\nno"), false);
488 it("[[Call]] returns false if the constraint fails", () => {
490 new Matcher(".*", undefined, () => false)(""),
496 describe("~lastIndex", () => {
497 it("[[Get]] returns zero", () => {
498 assertStrictEquals(new Matcher("").lastIndex
, 0);
501 it("[[Set]] fails", () => {
502 assertThrows(() => (new Matcher("").lastIndex
= 1));
506 describe("~length", () => {
507 it("[[Get]] returns one", () => {
508 assertStrictEquals(new Matcher("").length
, 1);
512 describe("~name", () => {
513 it("[[Get]] wraps the stringified regular expression if no name was provided", () => {
514 assertStrictEquals(new Matcher("").name
, "Matcher(/(?:)/u)");
516 new Matcher(/.*/gsu).name
,
521 it("[[Get]] uses the provided name if one was provided", () => {
522 assertStrictEquals(new Matcher("", "success").name
, "success");
527 describe("asciiLowercase", () => {
528 it("[[Call]] lowercases (just) A·S·C·I·I letters", () => {
529 assertStrictEquals(asciiLowercase("aBſÆss FtɁɂß"), "abſÆss ftɁɂß");
532 it("[[Construct]] throws an error", () => {
533 assertThrows(() => new asciiLowercase(""));
536 describe(".length", () => {
537 it("[[Get]] returns the correct length", () => {
538 assertStrictEquals(asciiLowercase
.length
, 1);
542 describe(".name", () => {
543 it("[[Get]] returns the correct name", () => {
544 assertStrictEquals(asciiLowercase
.name
, "asciiLowercase");
549 describe("asciiUppercase", () => {
550 it("[[Call]] uppercases (just) A·S·C·I·I letters", () => {
551 assertStrictEquals(asciiUppercase("aBſÆss FtɁɂß"), "ABſÆSS FTɁɂß");
554 it("[[Construct]] throws an error", () => {
555 assertThrows(() => new asciiUppercase(""));
558 describe(".length", () => {
559 it("[[Get]] returns the correct length", () => {
560 assertStrictEquals(asciiUppercase
.length
, 1);
564 describe(".name", () => {
565 it("[[Get]] returns the correct name", () => {
566 assertStrictEquals(asciiUppercase
.name
, "asciiUppercase");
571 describe("canonicalNumericIndexString", () => {
572 it("[[Call]] returns undefined for nonstrings", () => {
573 assertStrictEquals(canonicalNumericIndexString(1), void {});
576 it("[[Call]] returns undefined for noncanonical strings", () => {
577 assertStrictEquals(canonicalNumericIndexString(""), void {});
578 assertStrictEquals(canonicalNumericIndexString("01"), void {});
580 canonicalNumericIndexString("9007199254740993"),
585 it('[[Call]] returns -0 for "-0"', () => {
586 assertStrictEquals(canonicalNumericIndexString("-0"), -0);
589 it("[[Call]] returns the corresponding number for canonical strings", () => {
590 assertStrictEquals(canonicalNumericIndexString("0"), 0);
591 assertStrictEquals(canonicalNumericIndexString("-0.25"), -0.25);
593 canonicalNumericIndexString("9007199254740992"),
596 assertStrictEquals(canonicalNumericIndexString("NaN"), 0 / 0);
597 assertStrictEquals(canonicalNumericIndexString("Infinity"), 1 / 0);
599 canonicalNumericIndexString("-Infinity"),
604 it("[[Construct]] throws an error", () => {
605 assertThrows(() => new canonicalNumericIndexString(""));
608 describe(".length", () => {
609 it("[[Get]] returns the correct length", () => {
610 assertStrictEquals(canonicalNumericIndexString
.length
, 1);
614 describe(".name", () => {
615 it("[[Get]] returns the correct name", () => {
617 canonicalNumericIndexString
.name
,
618 "canonicalNumericIndexString",
624 describe("characters", () => {
625 it("[[Call]] returns an iterable", () => {
627 typeof characters("")[Symbol
.iterator
],
632 it("[[Call]] returns an iterator", () => {
633 assertStrictEquals(typeof characters("").next
, "function");
636 it("[[Call]] returns a string character iterator", () => {
638 characters("")[Symbol
.toStringTag
],
639 "String Character Iterator",
643 it("[[Call]] iterates over the characters", () => {
645 ...characters("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
659 it("[[Construct]] throws an error", () => {
660 assertThrows(() => new characters(""));
663 describe(".length", () => {
664 it("[[Get]] returns the correct length", () => {
665 assertStrictEquals(characters
.length
, 1);
669 describe(".name", () => {
670 it("[[Get]] returns the correct name", () => {
671 assertStrictEquals(characters
.name
, "characters");
676 describe("codeUnits", () => {
677 it("[[Call]] returns an iterable", () => {
679 typeof codeUnits("")[Symbol
.iterator
],
684 it("[[Call]] returns an iterator", () => {
685 assertStrictEquals(typeof codeUnits("").next
, "function");
688 it("[[Call]] returns a string code unit iterator", () => {
690 codeUnits("")[Symbol
.toStringTag
],
691 "String Code Unit Iterator",
695 it("[[Call]] iterates over the code units", () => {
697 ...codeUnits("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
713 it("[[Construct]] throws an error", () => {
714 assertThrows(() => new codeUnits(""));
717 describe(".length", () => {
718 it("[[Get]] returns the correct length", () => {
719 assertStrictEquals(codeUnits
.length
, 1);
723 describe(".name", () => {
724 it("[[Get]] returns the correct name", () => {
725 assertStrictEquals(codeUnits
.name
, "codeUnits");
730 describe("codepoints", () => {
731 it("[[Call]] returns an iterable", () => {
733 typeof codepoints("")[Symbol
.iterator
],
738 it("[[Call]] returns an iterator", () => {
739 assertStrictEquals(typeof codepoints("").next
, "function");
742 it("[[Call]] returns a string codepoint iterator", () => {
744 codepoints("")[Symbol
.toStringTag
],
745 "String Codepoint Iterator",
749 it("[[Call]] iterates over the codepoints", () => {
751 ...codepoints("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
765 it("[[Construct]] throws an error", () => {
766 assertThrows(() => new codepoints(""));
769 describe(".length", () => {
770 it("[[Get]] returns the correct length", () => {
771 assertStrictEquals(codepoints
.length
, 1);
775 describe(".name", () => {
776 it("[[Get]] returns the correct name", () => {
777 assertStrictEquals(codepoints
.name
, "codepoints");
782 describe("getCharacter", () => {
783 it("[[Call]] returns the character at the provided position", () => {
784 assertStrictEquals(getCharacter("Ii🎙🆗☺", 4), "🆗");
787 it("[[Call]] returns a low surrogate if the provided position splits a character", () => {
788 assertStrictEquals(getCharacter("Ii🎙🆗☺", 5), "\uDD97");
791 it("[[Call]] returns undefined for an out‐of‐bounds index", () => {
792 assertStrictEquals(getCharacter("Ii🎙🆗☺", -1), undefined);
793 assertStrictEquals(getCharacter("Ii🎙🆗☺", 7), undefined);
796 it("[[Construct]] throws an error", () => {
797 assertThrows(() => new getCharacter("a", 0));
800 describe(".length", () => {
801 it("[[Get]] returns the correct length", () => {
802 assertStrictEquals(getCharacter
.length
, 2);
806 describe(".name", () => {
807 it("[[Get]] returns the correct name", () => {
808 assertStrictEquals(getCharacter
.name
, "getCharacter");
813 describe("getCodeUnit", () => {
814 it("[[Call]] returns the code unit at the provided position", () => {
815 assertStrictEquals(getCodeUnit("Ii🎙🆗☺", 4), 0xD83C);
818 it("[[Call]] returns a low surrogate if the provided position splits a character", () => {
819 assertStrictEquals(getCodeUnit("Ii🎙🆗☺", 5), 0xDD97);
822 it("[[Call]] returns undefined for an out‐of‐bounds index", () => {
823 assertStrictEquals(getCodeUnit("Ii🎙🆗☺", -1), undefined);
824 assertStrictEquals(getCodeUnit("Ii🎙🆗☺", 7), undefined);
827 it("[[Construct]] throws an error", () => {
828 assertThrows(() => new getCodeUnit("a", 0));
831 describe(".length", () => {
832 it("[[Get]] returns the correct length", () => {
833 assertStrictEquals(getCodeUnit
.length
, 2);
837 describe(".name", () => {
838 it("[[Get]] returns the correct name", () => {
839 assertStrictEquals(getCodeUnit
.name
, "getCodeUnit");
844 describe("getCodepoint", () => {
845 it("[[Call]] returns the character at the provided position", () => {
846 assertStrictEquals(getCodepoint("Ii🎙🆗☺", 4), 0x1F197);
849 it("[[Call]] returns a low surrogate if the provided position splits a character", () => {
850 assertStrictEquals(getCodepoint("Ii🎙🆗☺", 5), 0xDD97);
853 it("[[Call]] returns undefined for an out‐of‐bounds index", () => {
854 assertStrictEquals(getCodepoint("Ii🎙🆗☺", -1), undefined);
855 assertStrictEquals(getCodepoint("Ii🎙🆗☺", 7), undefined);
858 it("[[Construct]] throws an error", () => {
859 assertThrows(() => new getCodepoint("a", 0));
862 describe(".length", () => {
863 it("[[Get]] returns the correct length", () => {
864 assertStrictEquals(getCodepoint
.length
, 2);
868 describe(".name", () => {
869 it("[[Get]] returns the correct name", () => {
870 assertStrictEquals(getCodepoint
.name
, "getCodepoint");
875 describe("getFirstSubstringIndex", () => {
876 it("[[Call]] returns the index of the first match", () => {
877 assertStrictEquals(getFirstSubstringIndex("Ii🎙🆗☺🆗", "🆗"), 4);
880 it("[[Call]] returns −1 if no match is found", () => {
881 assertStrictEquals(getFirstSubstringIndex("Ii🎙🆗☺🆗", "🆗🆖"), -1);
884 it("[[Call]] returns 0 when provided with an empty string", () => {
885 assertStrictEquals(getFirstSubstringIndex("Ii🎙🆗☺🆗", ""), 0);
888 it("[[Construct]] throws an error", () => {
889 assertThrows(() => new getFirstSubstringIndex("", ""));
892 describe(".length", () => {
893 it("[[Get]] returns the correct length", () => {
894 assertStrictEquals(getFirstSubstringIndex
.length
, 2);
898 describe(".name", () => {
899 it("[[Get]] returns the correct name", () => {
901 getFirstSubstringIndex
.name
,
902 "getFirstSubstringIndex",
908 describe("getLastSubstringIndex", () => {
909 it("[[Call]] returns the index of the first match", () => {
910 assertStrictEquals(getLastSubstringIndex("Ii🎙🆗☺🆗", "🆗"), 7);
913 it("[[Call]] returns −1 if no match is found", () => {
914 assertStrictEquals(getLastSubstringIndex("Ii🎙🆗☺🆗", "🆖🆗"), -1);
917 it("[[Call]] returns the length when provided with an empty string", () => {
919 getLastSubstringIndex("Ii🎙🆗☺🆗", ""),
924 it("[[Construct]] throws an error", () => {
925 assertThrows(() => new getLastSubstringIndex("", ""));
928 describe(".length", () => {
929 it("[[Get]] returns the correct length", () => {
930 assertStrictEquals(getLastSubstringIndex
.length
, 2);
934 describe(".name", () => {
935 it("[[Get]] returns the correct name", () => {
937 getLastSubstringIndex
.name
,
938 "getLastSubstringIndex",
944 describe("isArrayIndexString", () => {
945 it("[[Call]] returns false for nonstrings", () => {
946 assertStrictEquals(isArrayIndexString(1), false);
949 it("[[Call]] returns false for noncanonical strings", () => {
950 assertStrictEquals(isArrayIndexString(""), false);
951 assertStrictEquals(isArrayIndexString("01"), false);
952 assertStrictEquals(isArrayIndexString("9007199254740993"), false);
955 it("[[Call]] returns false for nonfinite numbers", () => {
956 assertStrictEquals(isArrayIndexString("NaN"), false);
957 assertStrictEquals(isArrayIndexString("Infinity"), false);
958 assertStrictEquals(isArrayIndexString("-Infinity"), false);
961 it("[[Call]] returns false for negative numbers", () => {
962 assertStrictEquals(isArrayIndexString("-0"), false);
963 assertStrictEquals(isArrayIndexString("-1"), false);
966 it("[[Call]] returns false for nonintegers", () => {
967 assertStrictEquals(isArrayIndexString("0.25"), false);
968 assertStrictEquals(isArrayIndexString("1.1"), false);
971 it("[[Call]] returns false for numbers greater than or equal to -1 >>> 0", () => {
972 assertStrictEquals(isArrayIndexString(String(-1 >>> 0)), false);
974 isArrayIndexString(String((-1 >>> 0) + 1)),
979 it("[[Call]] returns true for array lengths less than -1 >>> 0", () => {
980 assertStrictEquals(isArrayIndexString("0"), true);
982 isArrayIndexString(String((-1 >>> 0) - 1)),
987 it("[[Construct]] throws an error", () => {
988 assertThrows(() => new isArrayIndexString("0"));
991 describe(".length", () => {
992 it("[[Get]] returns the correct length", () => {
993 assertStrictEquals(isArrayIndexString
.length
, 1);
997 describe(".name", () => {
998 it("[[Get]] returns the correct name", () => {
1000 isArrayIndexString
.name
,
1001 "isArrayIndexString",
1007 describe("isIntegerIndexString", () => {
1008 it("[[Call]] returns false for nonstrings", () => {
1009 assertStrictEquals(isIntegerIndexString(1), false);
1012 it("[[Call]] returns false for noncanonical strings", () => {
1013 assertStrictEquals(isIntegerIndexString(""), false);
1014 assertStrictEquals(isIntegerIndexString("01"), false);
1016 isIntegerIndexString("9007199254740993"),
1021 it("[[Call]] returns false for nonfinite numbers", () => {
1022 assertStrictEquals(isIntegerIndexString("NaN"), false);
1023 assertStrictEquals(isIntegerIndexString("Infinity"), false);
1024 assertStrictEquals(isIntegerIndexString("-Infinity"), false);
1027 it("[[Call]] returns false for negative numbers", () => {
1028 assertStrictEquals(isIntegerIndexString("-0"), false);
1029 assertStrictEquals(isIntegerIndexString("-1"), false);
1032 it("[[Call]] returns false for nonintegers", () => {
1033 assertStrictEquals(isIntegerIndexString("0.25"), false);
1034 assertStrictEquals(isIntegerIndexString("1.1"), false);
1037 it("[[Call]] returns false for numbers greater than or equal to 2 ** 53", () => {
1039 isIntegerIndexString("9007199254740992"),
1044 it("[[Call]] returns true for safe canonical integer strings", () => {
1045 assertStrictEquals(isIntegerIndexString("0"), true);
1046 assertStrictEquals(isIntegerIndexString("9007199254740991"), true);
1049 it("[[Construct]] throws an error", () => {
1050 assertThrows(() => new isIntegerIndexString("0"));
1053 describe(".length", () => {
1054 it("[[Get]] returns the correct length", () => {
1055 assertStrictEquals(isIntegerIndexString
.length
, 1);
1059 describe(".name", () => {
1060 it("[[Get]] returns the correct name", () => {
1062 isIntegerIndexString
.name
,
1063 "isIntegerIndexString",
1069 describe("join", () => {
1070 it("[[Call]] joins the provided iterator with the provided separartor", () => {
1071 assertStrictEquals(join([1, 2, 3, 4].values(), "☂"), "1☂2☂3☂4");
1074 it('[[Call]] uses "," if no separator is provided', () => {
1075 assertStrictEquals(join([1, 2, 3, 4].values()), "1,2,3,4");
1078 it("[[Call]] uses the empty sting for nullish values", () => {
1080 join([null, , null, undefined].values(), "☂"),
1085 it("[[Construct]] throws an error", () => {
1086 assertThrows(() => new join([]));
1089 describe(".length", () => {
1090 it("[[Get]] returns the correct length", () => {
1091 assertStrictEquals(join
.length
, 2);
1095 describe(".name", () => {
1096 it("[[Get]] returns the correct name", () => {
1097 assertStrictEquals(join
.name
, "join");
1102 describe("rawString", () => {
1103 it("[[Call]] acts like String.raw", () => {
1104 assertStrictEquals(rawString
`\nraw${" string"}`, "\\nraw string");
1107 it("[[Construct]] throws an error", () => {
1108 assertThrows(() => new rawString(["string"]));
1111 describe(".length", () => {
1112 it("[[Get]] returns the correct length", () => {
1113 assertStrictEquals(rawString
.length
, 1);
1117 describe(".name", () => {
1118 it("[[Get]] returns the correct name", () => {
1119 assertStrictEquals(rawString
.name
, "rawString");
1124 describe("scalarValues", () => {
1125 it("[[Call]] returns an iterable", () => {
1127 typeof scalarValues("")[Symbol
.iterator
],
1132 it("[[Call]] returns an iterator", () => {
1133 assertStrictEquals(typeof scalarValues("").next
, "function");
1136 it("[[Call]] returns a string scalar value iterator", () => {
1138 scalarValues("")[Symbol
.toStringTag
],
1139 "String Scalar Value Iterator",
1143 it("[[Call]] iterates over the scalar values", () => {
1145 ...scalarValues("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
1159 it("[[Construct]] throws an error", () => {
1160 assertThrows(() => new scalarValues(""));
1163 describe(".length", () => {
1164 it("[[Get]] returns the correct length", () => {
1165 assertStrictEquals(scalarValues
.length
, 1);
1169 describe(".name", () => {
1170 it("[[Get]] returns the correct name", () => {
1171 assertStrictEquals(scalarValues
.name
, "scalarValues");
1176 describe("splitOnAsciiWhitespace", () => {
1177 it("[[Call]] splits on sequences of spaces", () => {
1179 splitOnAsciiWhitespace("🅰️ 🅱️ 🆎 🅾️"),
1180 ["🅰️", "🅱️", "🆎", "🅾️"],
1184 it("[[Call]] splits on sequences of tabs", () => {
1186 splitOnAsciiWhitespace("🅰️\t\t\t🅱️\t🆎\t\t🅾️"),
1187 ["🅰️", "🅱️", "🆎", "🅾️"],
1191 it("[[Call]] splits on sequences of carriage returns", () => {
1193 splitOnAsciiWhitespace("🅰️\r\r\r🅱️\r🆎\r\r🅾️"),
1194 ["🅰️", "🅱️", "🆎", "🅾️"],
1198 it("[[Call]] splits on sequences of newlines", () => {
1200 splitOnAsciiWhitespace("🅰️\r\r\r🅱️\r🆎\r\r🅾️"),
1201 ["🅰️", "🅱️", "🆎", "🅾️"],
1205 it("[[Call]] splits on sequences of form feeds", () => {
1207 splitOnAsciiWhitespace("🅰️\f\f\f🅱️\f🆎\f\f🅾️"),
1208 ["🅰️", "🅱️", "🆎", "🅾️"],
1212 it("[[Call]] splits on mixed whitespace", () => {
1214 splitOnAsciiWhitespace("🅰️\f \t\n🅱️\r\n\r🆎\n\f🅾️"),
1215 ["🅰️", "🅱️", "🆎", "🅾️"],
1219 it("[[Call]] returns an array of just the empty string for the empty string", () => {
1220 assertEquals(splitOnAsciiWhitespace(""), [""]);
1223 it("[[Call]] returns a single token if there are no spaces", () => {
1224 assertEquals(splitOnAsciiWhitespace("abcd"), ["abcd"]);
1227 it("[[Call]] does not split on other kinds of whitespace", () => {
1229 splitOnAsciiWhitespace("a\u202F\u205F\xa0\v\0\bb"),
1230 ["a\u202F\u205F\xa0\v\0\bb"],
1234 it("[[Call]] trims leading and trailing whitespace", () => {
1236 splitOnAsciiWhitespace(
1237 "\f\r\n\r\n \n\t🅰️\f \t\n🅱️\r🆎\n\f🅾️\n\f",
1239 ["🅰️", "🅱️", "🆎", "🅾️"],
1243 it("[[Construct]] throws an error", () => {
1244 assertThrows(() => new splitOnAsciiWhitespace(""));
1247 describe(".length", () => {
1248 it("[[Get]] returns the correct length", () => {
1249 assertStrictEquals(splitOnAsciiWhitespace
.length
, 1);
1253 describe(".name", () => {
1254 it("[[Get]] returns the correct name", () => {
1256 splitOnAsciiWhitespace
.name
,
1257 "splitOnAsciiWhitespace",
1263 describe("splitOnCommas", () => {
1264 it("[[Call]] splits on commas", () => {
1266 splitOnCommas("🅰️,🅱️,🆎,🅾️"),
1267 ["🅰️", "🅱️", "🆎", "🅾️"],
1271 it("[[Call]] returns an array of just the empty string for the empty string", () => {
1272 assertEquals(splitOnCommas(""), [""]);
1275 it("[[Call]] returns a single token if there are no commas", () => {
1276 assertEquals(splitOnCommas("abcd"), ["abcd"]);
1279 it("[[Call]] splits into empty strings if there are only commas", () => {
1280 assertEquals(splitOnCommas(",,,"), ["", "", "", ""]);
1283 it("[[Call]] trims leading and trailing whitespace", () => {
1285 splitOnCommas("\f\r\n\r\n \n\t🅰️,🅱️,🆎,🅾️\n\f"),
1286 ["🅰️", "🅱️", "🆎", "🅾️"],
1289 splitOnCommas("\f\r\n\r\n \n\t,,,\n\f"),
1294 it("[[Call]] removes whitespace from the split tokens", () => {
1297 "\f\r\n\r\n \n\t🅰️\f , \t\n🅱️,\r\n\r🆎\n\f,🅾️\n\f",
1299 ["🅰️", "🅱️", "🆎", "🅾️"],
1302 splitOnCommas("\f\r\n\r\n \n\t\f , \t\n,\r\n\r\n\f,\n\f"),
1307 it("[[Construct]] throws an error", () => {
1308 assertThrows(() => new splitOnCommas(""));
1311 describe(".length", () => {
1312 it("[[Get]] returns the correct length", () => {
1313 assertStrictEquals(splitOnCommas
.length
, 1);
1317 describe(".name", () => {
1318 it("[[Get]] returns the correct name", () => {
1319 assertStrictEquals(splitOnCommas
.name
, "splitOnCommas");
1324 describe("stringCatenate", () => {
1325 it("[[Call]] catenates the values", () => {
1326 assertStrictEquals(stringCatenate("the", " values"), "the values");
1329 it("[[Call]] returns an empty string when called with no values", () => {
1330 assertStrictEquals(stringCatenate(), "");
1333 it('[[Call]] uses "undefined" when explicitly provided undefined', () => {
1335 stringCatenate(undefined, undefined),
1336 "undefinedundefined",
1340 it('[[Call]] uses "null" when provided null', () => {
1341 assertStrictEquals(stringCatenate(null, null), "nullnull");
1344 it("[[Construct]] throws an error", () => {
1345 assertThrows(() => new stringCatenate());
1348 describe(".length", () => {
1349 it("[[Get]] returns the correct length", () => {
1350 assertStrictEquals(stringCatenate
.length
, 2);
1354 describe(".name", () => {
1355 it("[[Get]] returns the correct name", () => {
1356 assertStrictEquals(stringCatenate
.name
, "stringCatenate");
1361 describe("stringEndsWith", () => {
1362 it("[[Call]] returns whether the string ends with the thing", () => {
1364 stringEndsWith("very success", " success"),
1367 assertStrictEquals(stringEndsWith("very fail", " success"), false);
1370 it("[[Call]] accepts an offset", () => {
1372 stringEndsWith("very successful", " success", 12),
1377 it("[[Call]] returns true for an empty string test", () => {
1378 assertStrictEquals(stringEndsWith("", ""), true);
1381 it("[[Construct]] throws an error", () => {
1382 assertThrows(() => new stringEndsWith("", ""));
1385 describe(".length", () => {
1386 it("[[Get]] returns the correct length", () => {
1387 assertStrictEquals(stringEndsWith
.length
, 2);
1391 describe(".name", () => {
1392 it("[[Get]] returns the correct name", () => {
1393 assertStrictEquals(stringEndsWith
.name
, "stringEndsWith");
1398 describe("stringFromCodeUnits", () => {
1399 it("[[Call]] makes the string", () => {
1401 stringFromCodeUnits(0xD83C, 0xDD97),
1406 it("[[Call]] throws with non‐integral arguments", () => {
1407 assertThrows(() => stringFromCodeUnits(NaN
));
1408 assertThrows(() => stringFromCodeUnits(Infinity
));
1409 assertThrows(() => stringFromCodeUnits(0.1));
1412 it("[[Call]] throws with arguments out of range", () => {
1413 assertThrows(() => stringFromCodeUnits(-1));
1414 assertThrows(() => stringFromCodeUnits(0x10000));
1417 it("[[Construct]] throws an error", () => {
1418 assertThrows(() => new stringFromCodeUnits([]));
1421 describe(".length", () => {
1422 it("[[Get]] returns the correct length", () => {
1423 assertStrictEquals(stringFromCodeUnits
.length
, 1);
1427 describe(".name", () => {
1428 it("[[Get]] returns the correct name", () => {
1430 stringFromCodeUnits
.name
,
1431 "stringFromCodeUnits",
1437 describe("stringFromCodepoints", () => {
1438 it("[[Call]] makes the string", () => {
1439 assertStrictEquals(stringFromCodepoints(0x1F197), "🆗");
1442 it("[[Call]] throws with non‐integral arguments", () => {
1443 assertThrows(() => stringFromCodepoints(NaN
));
1444 assertThrows(() => stringFromCodepoints(Infinity
));
1445 assertThrows(() => stringFromCodepoints(0.1));
1448 it("[[Call]] throws with arguments out of range", () => {
1449 assertThrows(() => stringFromCodepoints(-1));
1450 assertThrows(() => stringFromCodepoints(0x110000));
1453 it("[[Construct]] throws an error", () => {
1454 assertThrows(() => new stringFromCodepoints([]));
1457 describe(".length", () => {
1458 it("[[Get]] returns the correct length", () => {
1459 assertStrictEquals(stringFromCodepoints
.length
, 1);
1463 describe(".name", () => {
1464 it("[[Get]] returns the correct name", () => {
1466 stringFromCodepoints
.name
,
1467 "stringFromCodepoints",
1473 describe("stringIncludes", () => {
1474 it("[[Call]] returns whether the string includes the thing", () => {
1476 stringIncludes("very success full", " success "),
1480 stringIncludes("very fail full", " success "),
1485 it("[[Call]] accepts an offset", () => {
1487 stringIncludes("maybe success full", " success ", 4),
1491 stringIncludes("maybe success full", " success ", 5),
1495 stringIncludes("maybe success full", " success ", 6),
1500 it("[[Call]] returns true for an empty string test", () => {
1501 assertStrictEquals(stringIncludes("", ""), true);
1504 it("[[Construct]] throws an error", () => {
1505 assertThrows(() => new stringIncludes("", ""));
1508 describe(".length", () => {
1509 it("[[Get]] returns the correct length", () => {
1510 assertStrictEquals(stringIncludes
.length
, 2);
1514 describe(".name", () => {
1515 it("[[Get]] returns the correct name", () => {
1516 assertStrictEquals(stringIncludes
.name
, "stringIncludes");
1521 describe("stringMatch", () => {
1522 it("[[Call]] does the match akin to String::match", () => {
1524 [...stringMatch("very success full", /([sc]+[ue]?)+/)],
1528 [...stringMatch("very success full", /([sc]+)[ue]?/g)],
1529 ["su", "cce", "ss"],
1533 it("[[Construct]] throws an error", () => {
1534 assertThrows(() => new stringMatch("", /(?:)/));
1537 describe(".length", () => {
1538 it("[[Get]] returns the correct length", () => {
1539 assertStrictEquals(stringMatch
.length
, 2);
1543 describe(".name", () => {
1544 it("[[Get]] returns the correct name", () => {
1545 assertStrictEquals(stringMatch
.name
, "stringMatch");
1550 describe("stringMatchAll", () => {
1551 it("[[Call]] does the match akin to String::matchAll", () => {
1553 [...stringMatchAll("very success full", /([sc]+)[ue]?/g)].map((
1556 [["su", "s"], ["cce", "cc"], ["ss", "ss"]],
1560 it("[[Construct]] throws an error", () => {
1561 assertThrows(() => new stringMatchAll("", /(?:)/g));
1564 describe(".length", () => {
1565 it("[[Get]] returns the correct length", () => {
1566 assertStrictEquals(stringMatchAll
.length
, 2);
1570 describe(".name", () => {
1571 it("[[Get]] returns the correct name", () => {
1572 assertStrictEquals(stringMatchAll
.name
, "stringMatchAll");
1577 describe("stringNormalize", () => {
1578 it("[[Call]] normalizes the string properly", () => {
1579 assertStrictEquals(stringNormalize("ẛ", "NFC"), "\u1E9B");
1580 assertStrictEquals(stringNormalize("ẛ", "NFD"), "\u017F\u0307");
1581 assertStrictEquals(stringNormalize("ẛ", "NFKC"), "\u1E61");
1582 assertStrictEquals(stringNormalize("ẛ", "NFKD"), "\u0073\u0307");
1585 it("[[Call]] assumes NFC", () => {
1586 assertStrictEquals(stringNormalize("\u017F\u0307"), "\u1E9B");
1589 it("[[Call]] throws with an invalid form", () => {
1590 assertThrows(() => stringNormalize("", "NFB"));
1593 it("[[Construct]] throws an error", () => {
1594 assertThrows(() => new stringNormalize("", "NFC"));
1597 describe(".length", () => {
1598 it("[[Get]] returns the correct length", () => {
1599 assertStrictEquals(stringNormalize
.length
, 1);
1603 describe(".name", () => {
1604 it("[[Get]] returns the correct name", () => {
1605 assertStrictEquals(stringNormalize
.name
, "stringNormalize");
1610 describe("stringPadEnd", () => {
1611 it("[[Call]] pads the end of the string", () => {
1612 assertStrictEquals(stringPadEnd("xx", 3), "xx ");
1613 assertStrictEquals(stringPadEnd("xx", 3, "o"), "xxo");
1614 assertStrictEquals(stringPadEnd("", 3, "xo"), "xox");
1615 assertStrictEquals(stringPadEnd("xx", 3, ""), "xx");
1618 it("[[Construct]] throws an error", () => {
1619 assertThrows(() => new stringPadEnd("", 1));
1622 describe(".length", () => {
1623 it("[[Get]] returns the correct length", () => {
1624 assertStrictEquals(stringPadEnd
.length
, 2);
1628 describe(".name", () => {
1629 it("[[Get]] returns the correct name", () => {
1630 assertStrictEquals(stringPadEnd
.name
, "stringPadEnd");
1635 describe("stringPadStart", () => {
1636 it("[[Call]] pads the start of the string", () => {
1637 assertStrictEquals(stringPadStart("xx", 3), " xx");
1638 assertStrictEquals(stringPadStart("xx", 3, "o"), "oxx");
1639 assertStrictEquals(stringPadStart("", 3, "xo"), "xox");
1640 assertStrictEquals(stringPadStart("xx", 3, ""), "xx");
1643 it("[[Construct]] throws an error", () => {
1644 assertThrows(() => new stringPadStart("", 1));
1647 describe(".length", () => {
1648 it("[[Get]] returns the correct length", () => {
1649 assertStrictEquals(stringPadStart
.length
, 2);
1653 describe(".name", () => {
1654 it("[[Get]] returns the correct name", () => {
1655 assertStrictEquals(stringPadStart
.name
, "stringPadStart");
1660 describe("stringRepeat", () => {
1661 it("[[Call]] repeats the string", () => {
1662 assertStrictEquals(stringRepeat("xx", 3), "xxxxxx");
1663 assertStrictEquals(stringRepeat("", 3), "");
1664 assertStrictEquals(stringRepeat("xx", 0), "");
1667 it("[[Call]] throws for negative repititions", () => {
1668 assertThrows(() => stringRepeat("", -1));
1671 it("[[Call]] throws for infinite repititions", () => {
1672 assertThrows(() => stringRepeat("", Infinity
));
1675 it("[[Construct]] throws an error", () => {
1676 assertThrows(() => new stringRepeat("", 1));
1679 describe(".length", () => {
1680 it("[[Get]] returns the correct length", () => {
1681 assertStrictEquals(stringRepeat
.length
, 2);
1685 describe(".name", () => {
1686 it("[[Get]] returns the correct name", () => {
1687 assertStrictEquals(stringRepeat
.name
, "stringRepeat");
1692 describe("stringReplace", () => {
1693 it("[[Call]] does the replacement akin to String::replace", () => {
1695 stringReplace("it’s a failure", "failure", "success"),
1700 "very success full",
1708 "very success full",
1711 `${$s[0].length}`.repeat($s
[1].length
) +
1712 $s
[0].substring($s
[1].length
),
1714 "very 2u33e22 full",
1718 it("[[Construct]] throws an error", () => {
1719 assertThrows(() => new stringReplace("", /(?:)/, ""));
1722 describe(".length", () => {
1723 it("[[Get]] returns the correct length", () => {
1724 assertStrictEquals(stringReplace
.length
, 3);
1728 describe(".name", () => {
1729 it("[[Get]] returns the correct name", () => {
1730 assertStrictEquals(stringReplace
.name
, "stringReplace");
1735 describe("stringReplaceAll", () => {
1736 it("[[Call]] does the match akin to String::replaceAll", () => {
1738 stringReplaceAll("it’s a failure failure", "failure", "success"),
1739 "it’s a success success",
1743 "very success full",
1746 `${$s[0].length}`.repeat($s
[1].length
) +
1747 $s
[0].substring($s
[1].length
),
1749 "very 2u33e22 full",
1753 it("[[Construct]] throws an error", () => {
1754 assertThrows(() => new stringReplaceAll("", /(?:)/g));
1757 describe(".length", () => {
1758 it("[[Get]] returns the correct length", () => {
1759 assertStrictEquals(stringReplaceAll
.length
, 3);
1763 describe(".name", () => {
1764 it("[[Get]] returns the correct name", () => {
1765 assertStrictEquals(stringReplaceAll
.name
, "stringReplaceAll");
1770 describe("stringSearch", () => {
1771 it("[[Call]] does the search akin to String::search", () => {
1773 stringSearch("very success full", /([sc]+)[ue]?/),
1777 stringSearch("very fail full", /([sc]+)[ue]?/),
1782 it("[[Construct]] throws an error", () => {
1783 assertThrows(() => new stringSearch("", /(?:)/));
1786 describe(".length", () => {
1787 it("[[Get]] returns the correct length", () => {
1788 assertStrictEquals(stringSearch
.length
, 2);
1792 describe(".name", () => {
1793 it("[[Get]] returns the correct name", () => {
1794 assertStrictEquals(stringSearch
.name
, "stringSearch");
1799 describe("stringSlice", () => {
1800 it("[[Call]] slices the string akin to String::search", () => {
1802 stringSlice("very success full", 5, 12),
1806 stringSlice("very success full", -12, -5),
1811 it("[[Construct]] throws an error", () => {
1812 assertThrows(() => new stringSlice("", 0, 0));
1815 describe(".length", () => {
1816 it("[[Get]] returns the correct length", () => {
1817 assertStrictEquals(stringSlice
.length
, 3);
1821 describe(".name", () => {
1822 it("[[Get]] returns the correct name", () => {
1823 assertStrictEquals(stringSlice
.name
, "stringSlice");
1828 describe("stringSplit", () => {
1829 it("[[Call]] splits the string akin to String::split", () => {
1830 assertEquals(stringSplit("success", ""), [
1839 assertEquals(stringSplit("success", /(?<=[aeiou])(?=[^aeiou])/), [
1844 assertEquals(stringSplit("success", "failure"), ["success"]);
1847 it("[[Call]] recognizes a limit", () => {
1848 assertEquals(stringSplit("success", "", 4), ["s", "u", "c", "c"]);
1851 it("[[Construct]] throws an error", () => {
1852 assertThrows(() => new stringSplit("", ""));
1855 describe(".length", () => {
1856 it("[[Get]] returns the correct length", () => {
1857 assertStrictEquals(stringSplit
.length
, 3);
1861 describe(".name", () => {
1862 it("[[Get]] returns the correct name", () => {
1863 assertStrictEquals(stringSplit
.name
, "stringSplit");
1868 describe("stringStartsWith", () => {
1869 it("[[Call]] returns whether the string starts with the thing", () => {
1871 stringStartsWith("success is had", "success "),
1875 stringStartsWith("no success is had", "success "),
1880 it("[[Call]] accepts an offset", () => {
1882 stringStartsWith("much success is had", "success ", 5),
1887 it("[[Call]] returns true for an empty string test", () => {
1888 assertStrictEquals(stringEndsWith("", ""), true);
1891 it("[[Construct]] throws an error", () => {
1892 assertThrows(() => new stringStartsWith("", ""));
1895 describe(".length", () => {
1896 it("[[Get]] returns the correct length", () => {
1897 assertStrictEquals(stringStartsWith
.length
, 2);
1901 describe(".name", () => {
1902 it("[[Get]] returns the correct name", () => {
1903 assertStrictEquals(stringStartsWith
.name
, "stringStartsWith");
1908 describe("stringStartsWith", () => {
1909 it("[[Call]] returns the string value of a string literal", () => {
1910 assertStrictEquals(stringValue("success"), "success");
1913 it("[[Call]] returns the string value of a string object", () => {
1914 const string
= new String("success");
1915 Object
.defineProperties(string
, {
1916 toString
: { value
: () => "failure" },
1917 valueOf
: { value
: () => "failure" },
1919 assertStrictEquals(stringValue(string
), "success");
1922 it("[[Call]] throws for non‐strings", () => {
1923 assertThrows(() => stringValue(Object
.create(String
.prototype)));
1926 it("[[Construct]] throws an error", () => {
1927 assertThrows(() => new stringValue(""));
1930 describe(".length", () => {
1931 it("[[Get]] returns the correct length", () => {
1932 assertStrictEquals(stringValue
.length
, 1);
1936 describe(".name", () => {
1937 it("[[Get]] returns the correct name", () => {
1938 assertStrictEquals(stringValue
.name
, "stringValue");
1943 describe("stripAndCollapseAsciiWhitespace", () => {
1944 it("[[Call]] collapses mixed inner whitespace", () => {
1946 stripAndCollapseAsciiWhitespace("🅰️\f \t\n🅱️\r\n\r🆎\n\f🅾️"),
1951 it("[[Call]] trims leading and trailing whitespace", () => {
1953 stripAndCollapseAsciiWhitespace(
1954 "\f\r\n\r\n \n\t\f 🅰️\f \t\n🅱️\r\n\r🆎\n\f🅾️\n\f",
1960 it("[[Call]] returns the empty string for strings of whitespace", () => {
1962 stripAndCollapseAsciiWhitespace("\f\r\n\r\n \n\t\f \n\f"),
1967 it("[[Call]] does not collapse other kinds of whitespace", () => {
1969 stripAndCollapseAsciiWhitespace("a\u202F\u205F\xa0\v\0\bb"),
1970 "a\u202F\u205F\xa0\v\0\bb",
1974 it("[[Construct]] throws an error", () => {
1975 assertThrows(() => new stripAndCollapseAsciiWhitespace(""));
1978 describe(".length", () => {
1979 it("[[Get]] returns the correct length", () => {
1980 assertStrictEquals(stripAndCollapseAsciiWhitespace
.length
, 1);
1984 describe(".name", () => {
1985 it("[[Get]] returns the correct name", () => {
1987 stripAndCollapseAsciiWhitespace
.name
,
1988 "stripAndCollapseAsciiWhitespace",
1994 describe("stripLeadingAndTrailingAsciiWhitespace", () => {
1995 it("[[Call]] trims leading and trailing whitespace", () => {
1997 stripLeadingAndTrailingAsciiWhitespace(
1998 "\f\r\n\r\n \n\t\f 🅰️🅱️🆎🅾️\n\f",
2004 it("[[Call]] returns the empty string for strings of whitespace", () => {
2006 stripLeadingAndTrailingAsciiWhitespace("\f\r\n\r\n \n\t\f \n\f"),
2011 it("[[Call]] does not trim other kinds of whitespace", () => {
2013 stripLeadingAndTrailingAsciiWhitespace(
2014 "\v\u202F\u205Fx\0\b\xa0",
2016 "\v\u202F\u205Fx\0\b\xa0",
2020 it("[[Call]] does not adjust inner whitespace", () => {
2022 stripLeadingAndTrailingAsciiWhitespace("a b"),
2027 it("[[Construct]] throws an error", () => {
2028 assertThrows(() => new stripLeadingAndTrailingAsciiWhitespace(""));
2031 describe(".length", () => {
2032 it("[[Get]] returns the correct length", () => {
2034 stripLeadingAndTrailingAsciiWhitespace
.length
,
2040 describe(".name", () => {
2041 it("[[Get]] returns the correct name", () => {
2043 stripLeadingAndTrailingAsciiWhitespace
.name
,
2044 "stripLeadingAndTrailingAsciiWhitespace",
2050 describe("substring", () => {
2051 it("[[Call]] returns the substring", () => {
2053 substring("success", 0),
2057 substring("very success full", 5, 12),
2062 it("[[Construct]] throws an error", () => {
2063 assertThrows(() => new substring("", 0));
2066 describe(".length", () => {
2067 it("[[Get]] returns the correct length", () => {
2068 assertStrictEquals(substring
.length
, 3);
2072 describe(".name", () => {
2073 it("[[Get]] returns the correct name", () => {
2074 assertStrictEquals(substring
.name
, "substring");
2079 describe("toScalarValueString", () => {
2080 it("[[Call]] replaces invalid values", () => {
2082 toScalarValueString("Ii🎙\uDFFF\uDD96\uD83C\uD800🆗☺"),
2083 "Ii🎙\uFFFD\uFFFD\uFFFD\uFFFD🆗☺",
2087 it("[[Construct]] throws an error", () => {
2088 assertThrows(() => new toScalarValueString(""));
2091 describe(".length", () => {
2092 it("[[Get]] returns the correct length", () => {
2093 assertStrictEquals(toScalarValueString
.length
, 1);
2097 describe(".name", () => {
2098 it("[[Get]] returns the correct name", () => {
2100 toScalarValueString
.name
,
2101 "toScalarValueString",
2107 describe("toString", () => {
2108 it("[[Call]] converts to a string", () => {
2119 it("[[Call]] throws when provided a symbol", () => {
2120 assertThrows(() => toString(Symbol()));
2123 it("[[Construct]] throws an error", () => {
2124 assertThrows(() => new toString(""));
2127 describe(".length", () => {
2128 it("[[Get]] returns the correct length", () => {
2129 assertStrictEquals(toString
.length
, 1);
2133 describe(".name", () => {
2134 it("[[Get]] returns the correct name", () => {
2135 assertStrictEquals(toString
.name
, "toString");