Meta: Increase the line length enforced by prettier to 120

This matches our coding style recommendation in CodingStyle.md, and
matches our python formatting.
This commit is contained in:
Timothy Flynn 2025-10-31 11:50:48 -04:00 committed by Tim Flynn
parent b7ecdad685
commit 019c529c07
178 changed files with 774 additions and 2019 deletions

View File

@ -3,7 +3,7 @@
"bracketSpacing": true, "bracketSpacing": true,
"endOfLine": "lf", "endOfLine": "lf",
"insertPragma": false, "insertPragma": false,
"printWidth": 100, "printWidth": 120,
"quoteProps": "as-needed", "quoteProps": "as-needed",
"semi": true, "semi": true,
"singleQuote": false, "singleQuote": false,

View File

@ -1,18 +1,18 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="color-scheme" content="light dark"> <meta name="color-scheme" content="light dark" />
<title>About URLs</title> <title>About URLs</title>
</head> </head>
<body> <body>
<h1>List of About URLs</h1> <h1>List of About URLs</h1>
<ul> <ul>
<li><a href="about:about">about:about</a></li> <li><a href="about:about">about:about</a></li>
<li><a href="about:newtab">about:newtab</a></li> <li><a href="about:newtab">about:newtab</a></li>
<li><a href="about:processes">about:processes</a></li> <li><a href="about:processes">about:processes</a></li>
<li><a href="about:settings">about:settings</a></li> <li><a href="about:settings">about:settings</a></li>
<li><a href="about:version">about:version</a></li> <li><a href="about:version">about:version</a></li>
</ul> </ul>
</body> </body>
</html> </html>

View File

@ -1,12 +1,12 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>New Tab</title> <title>New Tab</title>
<style> <style>
html { html {
color-scheme: light dark; color-scheme: light dark;
} }
</style> </style>
</head> </head>
</html> </html>

View File

@ -300,10 +300,7 @@
<body> <body>
<header> <header>
<picture> <picture>
<source <source srcset="resource://icons/128x128/app-browser.png" media="(prefers-color-scheme: dark)" />
srcset="resource://icons/128x128/app-browser.png"
media="(prefers-color-scheme: dark)"
/>
<img src="resource://icons/128x128/app-browser-dark.png" /> <img src="resource://icons/128x128/app-browser-dark.png" />
</picture> </picture>
<h1>Ladybird Settings</h1> <h1>Ladybird Settings</h1>
@ -350,9 +347,7 @@
<div class="card-group"> <div class="card-group">
<label for="autocomplete-engine">Search Suggestions</label> <label for="autocomplete-engine">Search Suggestions</label>
<p class="description"> <p class="description">Select the engine that will provide search suggestions.</p>
Select the engine that will provide search suggestions.
</p>
<select id="autocomplete-engine"> <select id="autocomplete-engine">
<option value="">Disable search suggestions</option> <option value="">Disable search suggestions</option>
<hr /> <hr />
@ -379,9 +374,7 @@
<div class="card-body"> <div class="card-body">
<div class="card-group"> <div class="card-group">
<div class="inline-container"> <div class="inline-container">
<label for="global-privacy-control-toggle"> <label for="global-privacy-control-toggle">Enable Global Privacy Control</label>
Enable Global Privacy Control
</label>
<input id="global-privacy-control-toggle" type="checkbox" switch /> <input id="global-privacy-control-toggle" type="checkbox" switch />
</div> </div>
<p class="description">Tell websites not to sell or share your data.</p> <p class="description">Tell websites not to sell or share your data.</p>
@ -471,11 +464,7 @@
<div class="form-group"> <div class="form-group">
<label for="search-custom-url">Search URL</label> <label for="search-custom-url">Search URL</label>
<p class="description">Use %s as a placeholder for the search query</p> <p class="description">Use %s as a placeholder for the search query</p>
<input <input id="search-custom-url" type="url" placeholder="https://example.com/search?q=%s" />
id="search-custom-url"
type="url"
placeholder="https://example.com/search?q=%s"
/>
</div> </div>
<div class="dialog-controls"> <div class="dialog-controls">
<button id="search-custom-add" class="primary-button">Add&nbsp;Engine</button> <button id="search-custom-add" class="primary-button">Add&nbsp;Engine</button>
@ -502,9 +491,7 @@
</div> </div>
</div> </div>
<div class="dialog-footer"> <div class="dialog-footer">
<button id="site-settings-remove-all" class="secondary-button"> <button id="site-settings-remove-all" class="secondary-button">Remove All Sites</button>
Remove All Sites
</button>
</div> </div>
</dialog> </dialog>

View File

@ -1,23 +1,6 @@
const defaultZoomLevelDropdown = document.querySelector("#default-zoom-level"); const defaultZoomLevelDropdown = document.querySelector("#default-zoom-level");
const zoomLevelFactors = [ const zoomLevelFactors = [1 / 3.0, 0.5, 2 / 3.0, 0.75, 0.8, 0.9, 1.0, 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 5.0];
1 / 3.0,
0.5,
2 / 3.0,
0.75,
0.8,
0.9,
1.0,
1.1,
1.25,
1.5,
1.75,
2.0,
2.5,
3.0,
4.0,
5.0,
];
const zoomLevelFactorMap = zoomLevelFactors.map(factor => ({ const zoomLevelFactorMap = zoomLevelFactors.map(factor => ({
factor, factor,

View File

@ -1,65 +1,67 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>Index of %path%</title> <title>Index of %path%</title>
<style> <style>
html { html {
color-scheme: light dark; color-scheme: light dark;
} }
header { header {
margin-bottom: 10px; margin-bottom: 10px;
} }
h1 { h1 {
display: inline; display: inline;
} }
a { a {
text-decoration: none; text-decoration: none;
} }
a:focus, a:focus,
a:hover { a:hover {
text-decoration: underline; text-decoration: underline;
} }
table { table {
font-family: monospace; font-family: monospace;
} }
.folder, .folder,
.file, .file,
.open-parent { .open-parent {
display: inline-block; display: inline-block;
width: 16px; width: 16px;
height: 16px; height: 16px;
margin-right: 5px; margin-right: 5px;
background-size: contain; background-size: contain;
} }
.folder { .folder {
background-image: url('resource://icons/32x32/filetype-folder.png'); background-image: url("resource://icons/32x32/filetype-folder.png");
} }
.file { .file {
background-image: url('resource://icons/32x32/filetype-unknown.png'); background-image: url("resource://icons/32x32/filetype-unknown.png");
} }
.open-parent { .open-parent {
background-image: url('resource://icons/16x16/open-parent-directory.png'); background-image: url("resource://icons/16x16/open-parent-directory.png");
} }
</style> </style>
</head> </head>
<body> <body>
<header> <header>
<span class="folder" style="width: 24px; height: 24px;"></span> <span class="folder" style="width: 24px; height: 24px"></span>
<h1>Index of %path%</h1> <h1>Index of %path%</h1>
</header> </header>
<p><a href="%parent_url%"><span class="open-parent"></span>Open Parent Directory</a></p> <p>
<hr> <a href="%parent_url%"><span class="open-parent"></span>Open Parent Directory</a>
%contents% </p>
<hr> <hr />
</body> %contents%
<hr />
</body>
</html> </html>

View File

@ -1,58 +1,58 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>Error!</title> <title>Error!</title>
<style> <style>
:root { :root {
color-scheme: light dark; color-scheme: light dark;
font-family: system-ui, sans-serif; font-family: system-ui, sans-serif;
} }
body { body {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
min-height: 100vh; min-height: 100vh;
box-sizing: border-box; box-sizing: border-box;
margin: 0; margin: 0;
padding: 1rem; padding: 1rem;
text-align: center; text-align: center;
} }
header { header {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
gap: 2rem; gap: 2rem;
margin-bottom: 1rem; margin-bottom: 1rem;
} }
svg { svg {
height: 64px; height: 64px;
width: auto; width: auto;
stroke: currentColor; stroke: currentColor;
fill: none; fill: none;
stroke-width: 1.5; stroke-width: 1.5;
stroke-linecap: round; stroke-linecap: round;
stroke-linejoin: round; stroke-linejoin: round;
} }
h1 { h1 {
margin: 0; margin: 0;
font-size: 1.5rem; font-size: 1.5rem;
} }
p { p {
font-size: 1rem; font-size: 1rem;
color: #555; color: #555;
} }
</style> </style>
</head> </head>
<body> <body>
<header> <header>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17.5 21.5"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17.5 21.5">
<path d="M11.75.75h-9c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-13l-5-5z"/> <path d="M11.75.75h-9c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-13l-5-5z" />
<path d="M10.75.75v4c0 1.1.9 2 2 2h4M5.75 9.75v2M11.75 9.75v2M5.75 16.75c1-2.67 5-2.67 6 0"/> <path d="M10.75.75v4c0 1.1.9 2 2 2h4M5.75 9.75v2M11.75 9.75v2M5.75 16.75c1-2.67 5-2.67 6 0" />
</svg> </svg>
<h1>Failed to load %failed_url%</h1> <h1>Failed to load %failed_url%</h1>
</header> </header>
<p>%error_message%</p> <p>%error_message%</p>
</body> </body>
</html> </html>

View File

@ -1,58 +1,58 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<title>About %browser_name%</title> <title>About %browser_name%</title>
<style> <style>
html { html {
color-scheme: light dark; color-scheme: light dark;
} }
img { img {
float: left; float: left;
margin-right: 10px; margin-right: 10px;
height: 48px; height: 48px;
} }
th { th {
text-align: right; text-align: right;
} }
td { td {
font-family: monospace; font-family: monospace;
} }
</style> </style>
</head> </head>
<body> <body>
<header> <header>
<picture> <picture>
<source srcset="resource://icons/128x128/app-browser.png" media="(prefers-color-scheme: dark)"> <source srcset="resource://icons/128x128/app-browser.png" media="(prefers-color-scheme: dark)" />
<img src="resource://icons/128x128/app-browser-dark.png"> <img src="resource://icons/128x128/app-browser-dark.png" />
</picture> </picture>
<h1>About %browser_name%</h1> <h1>About %browser_name%</h1>
</header> </header>
<table> <table>
<tr> <tr>
<th>Version:</th> <th>Version:</th>
<td>%browser_version%</td> <td>%browser_version%</td>
</tr> </tr>
<tr> <tr>
<th>Arch:</th> <th>Arch:</th>
<td>%arch_name%</td> <td>%arch_name%</td>
</tr> </tr>
<tr> <tr>
<th>Operating System:</th> <th>Operating System:</th>
<td>%os_name%</td> <td>%os_name%</td>
</tr> </tr>
<tr> <tr>
<th>User Agent:</th> <th>User Agent:</th>
<td>%user_agent%</td> <td>%user_agent%</td>
</tr> </tr>
<tr> <tr>
<th>Command Line:</th> <th>Command Line:</th>
<td>%command_line%</td> <td>%command_line%</td>
</tr> </tr>
<tr> <tr>
<th>Executable Path:</th> <th>Executable Path:</th>
<td>%executable_path%</td> <td>%executable_path%</td>
</tr> </tr>
</table> </table>
</body> </body>
</html> </html>

View File

@ -53,21 +53,9 @@ describe("ability to work with generic non-array objects", () => {
} }
{ {
const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" }; const o = { length: 5, 0: "foo", 1: "bar", 3: "baz" };
expect(Array.prototype.slice.call(o)).toEqual([ expect(Array.prototype.slice.call(o)).toEqual(["foo", "bar", undefined, "baz", undefined]);
"foo",
"bar",
undefined,
"baz",
undefined,
]);
expect(Array.prototype.slice.call(o, 0, 3)).toEqual(["foo", "bar", undefined]); expect(Array.prototype.slice.call(o, 0, 3)).toEqual(["foo", "bar", undefined]);
expect(Array.prototype.slice.call(o, 0, 15)).toEqual([ expect(Array.prototype.slice.call(o, 0, 15)).toEqual(["foo", "bar", undefined, "baz", undefined]);
"foo",
"bar",
undefined,
"baz",
undefined,
]);
expect(Array.prototype.slice.call(o, 1)).toEqual(["bar", undefined, "baz", undefined]); expect(Array.prototype.slice.call(o, 1)).toEqual(["bar", undefined, "baz", undefined]);
expect(Array.prototype.slice.call(o, 15)).toEqual([]); expect(Array.prototype.slice.call(o, 15)).toEqual([]);
@ -89,13 +77,9 @@ describe("ability to work with generic non-array objects", () => {
expect(Array.prototype.join.call({ length: "foo" })).toBe(""); expect(Array.prototype.join.call({ length: "foo" })).toBe("");
expect(Array.prototype.join.call({ length: 3 })).toBe(",,"); expect(Array.prototype.join.call({ length: 3 })).toBe(",,");
expect(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" })).toBe("foo,bar"); expect(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar" })).toBe("foo,bar");
expect(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" })).toBe( expect(Array.prototype.join.call({ length: 2, 0: "foo", 1: "bar", 2: "baz" })).toBe("foo,bar");
"foo,bar"
);
expect(Array.prototype.join.call({ length: 3, 1: "bar" }, "~")).toBe("~bar~"); expect(Array.prototype.join.call({ length: 3, 1: "bar" }, "~")).toBe("~bar~");
expect(Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~")).toBe( expect(Array.prototype.join.call({ length: 3, 0: "foo", 1: "bar", 2: "baz" }, "~")).toBe("foo~bar~baz");
"foo~bar~baz"
);
}); });
test("toString", () => { test("toString", () => {
@ -120,9 +104,7 @@ describe("ability to work with generic non-array objects", () => {
expect(Array.prototype.lastIndexOf.call({ length: 1, 2: "foo" }, "foo")).toBe(-1); expect(Array.prototype.lastIndexOf.call({ length: 1, 2: "foo" }, "foo")).toBe(-1);
expect(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo" }, "foo")).toBe(2); expect(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo" }, "foo")).toBe(2);
expect(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo")).toBe(4); expect(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo")).toBe(4);
expect(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", -2)).toBe( expect(Array.prototype.lastIndexOf.call({ length: 5, 2: "foo", 4: "foo" }, "foo", -2)).toBe(2);
2
);
}); });
test("includes", () => { test("includes", () => {
@ -279,13 +261,7 @@ describe("ability to work with generic non-array objects", () => {
3: "baz", 3: "baz",
[Symbol.isConcatSpreadable]: true, [Symbol.isConcatSpreadable]: true,
}; };
expect(Array.prototype.concat.call(spreadable)).toEqual([ expect(Array.prototype.concat.call(spreadable)).toEqual(["foo", "bar", undefined, "baz", undefined]);
"foo",
"bar",
undefined,
"baz",
undefined,
]);
expect(Array.prototype.concat.call(spreadable, [1, 2])).toEqual([ expect(Array.prototype.concat.call(spreadable, [1, 2])).toEqual([
"foo", "foo",
"bar", "bar",

View File

@ -51,12 +51,6 @@ describe("normal behavior", () => {
return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1); return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1);
}; };
expect(filterItems(fruits, "Berry")).toEqual(["Blueberry", "Raspberry"]); expect(filterItems(fruits, "Berry")).toEqual(["Blueberry", "Raspberry"]);
expect(filterItems(fruits, "P")).toEqual([ expect(filterItems(fruits, "P")).toEqual(["Apple", "Grape", "Peach", "Pineapple", "Raspberry"]);
"Apple",
"Grape",
"Peach",
"Pineapple",
"Raspberry",
]);
}); });
}); });

View File

@ -32,11 +32,7 @@ describe("normal behavior", () => {
}); });
test("can map based on callback return value", () => { test("can map based on callback return value", () => {
expect( expect([undefined, null, true, "foo", 42, {}].map((value, index) => "" + index + " -> " + value)).toEqual([
[undefined, null, true, "foo", 42, {}].map(
(value, index) => "" + index + " -> " + value
)
).toEqual([
"0 -> undefined", "0 -> undefined",
"1 -> null", "1 -> null",
"2 -> true", "2 -> true",

View File

@ -20,38 +20,12 @@ describe("Array.prototype.sort", () => {
// mix of data, including empty slots and undefined // mix of data, including empty slots and undefined
arr = ["2", Infinity, null, null, , undefined, 5, , undefined, null, 54, "5"]; arr = ["2", Infinity, null, null, , undefined, 5, , undefined, null, 54, "5"];
expect(arr.sort()).toEqual([ expect(arr.sort()).toEqual(["2", 5, "5", 54, Infinity, null, null, null, undefined, undefined, , ,]);
"2",
5,
"5",
54,
Infinity,
null,
null,
null,
undefined,
undefined,
,
,
]);
expect(arr.length).toEqual(12); expect(arr.length).toEqual(12);
// undefined compare function // undefined compare function
arr = ["2", Infinity, null, null, , undefined, 5n, , undefined, null, 54, "5"]; arr = ["2", Infinity, null, null, , undefined, 5n, , undefined, null, 54, "5"];
expect(arr.sort(undefined)).toEqual([ expect(arr.sort(undefined)).toEqual(["2", 5n, "5", 54, Infinity, null, null, null, undefined, undefined, , ,]);
"2",
5n,
"5",
54,
Infinity,
null,
null,
null,
undefined,
undefined,
,
,
]);
expect(arr.length).toEqual(12); expect(arr.length).toEqual(12);
// numeric data with compare function to sort numerically // numeric data with compare function to sort numerically
@ -123,10 +97,7 @@ describe("Array.prototype.sort", () => {
expect([].sort(expectNoCallCompareFunction)).toEqual([]); expect([].sort(expectNoCallCompareFunction)).toEqual([]);
expect([1].sort(expectNoCallCompareFunction)).toEqual([1]); expect([1].sort(expectNoCallCompareFunction)).toEqual([1]);
expect([1, undefined].sort(expectNoCallCompareFunction)).toEqual([1, undefined]); expect([1, undefined].sort(expectNoCallCompareFunction)).toEqual([1, undefined]);
expect([undefined, undefined].sort(expectNoCallCompareFunction)).toEqual([ expect([undefined, undefined].sort(expectNoCallCompareFunction)).toEqual([undefined, undefined]);
undefined,
undefined,
]);
expect([, , 1, ,].sort(expectNoCallCompareFunction)).toEqual([1, , , ,]); expect([, , 1, ,].sort(expectNoCallCompareFunction)).toEqual([1, , , ,]);
expect([undefined, , 1, , undefined, ,].sort(expectNoCallCompareFunction)).toEqual([ expect([undefined, , 1, , undefined, ,].sort(expectNoCallCompareFunction)).toEqual([
1, 1,

View File

@ -65,8 +65,6 @@ describe("normal behavior", () => {
expect([12, 34].toLocaleString("ar-u-nu-arab")).toBe("\u0661\u0662,\u0663\u0664"); expect([12, 34].toLocaleString("ar-u-nu-arab")).toBe("\u0661\u0662,\u0663\u0664");
expect([0.234].toLocaleString("en", { style: "percent" })).toBe("23%"); expect([0.234].toLocaleString("en", { style: "percent" })).toBe("23%");
expect([0.234].toLocaleString("ar-u-nu-arab", { style: "percent" })).toBe( expect([0.234].toLocaleString("ar-u-nu-arab", { style: "percent" })).toBe("\u0662\u0663\u066a\u061c");
"\u0662\u0663\u066a\u061c"
);
}); });
}); });

View File

@ -27,8 +27,5 @@ test("invalid ArrayBuffer maximum size option", () => {
test("ArrayBuffer size exceeds maximum size", () => { test("ArrayBuffer size exceeds maximum size", () => {
expect(() => { expect(() => {
new ArrayBuffer(10, { maxByteLength: 5 }); new ArrayBuffer(10, { maxByteLength: 5 });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "ArrayBuffer byte length of 10 exceeds the max byte length of 5");
RangeError,
"ArrayBuffer byte length of 10 exceeds the max byte length of 5"
);
}); });

View File

@ -36,10 +36,7 @@ describe("errors", () => {
expect(() => { expect(() => {
buffer.resize(11); buffer.resize(11);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "ArrayBuffer byte length of 11 exceeds the max byte length of 10");
RangeError,
"ArrayBuffer byte length of 11 exceeds the max byte length of 10"
);
}); });
}); });

View File

@ -7,10 +7,7 @@ describe("errors", () => {
test("called without new", () => { test("called without new", () => {
expect(() => { expect(() => {
AsyncDisposableStack(); AsyncDisposableStack();
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "AsyncDisposableStack constructor must be called with 'new'");
TypeError,
"AsyncDisposableStack constructor must be called with 'new'"
);
}); });
}); });

View File

@ -3,7 +3,5 @@ test("length is 0", () => {
}); });
test("is the same as disposeAsync", () => { test("is the same as disposeAsync", () => {
expect(AsyncDisposableStack.prototype[Symbol.asyncDispose]).toBe( expect(AsyncDisposableStack.prototype[Symbol.asyncDispose]).toBe(AsyncDisposableStack.prototype.disposeAsync);
AsyncDisposableStack.prototype.disposeAsync
);
}); });

View File

@ -80,9 +80,6 @@ describe("basic functionality", () => {
}, },
}); });
expect(async () => await stack.disposeAsync()).toThrowWithMessage( expect(async () => await stack.disposeAsync()).toThrowWithMessage(ExpectationError, "fail in dispose");
ExpectationError,
"fail in dispose"
);
}); });
}); });

View File

@ -54,9 +54,6 @@ describe("throws errors", () => {
await stack.disposeAsync(); await stack.disposeAsync();
expect(stack.disposed).toBeTrue(); expect(stack.disposed).toBeTrue();
expect(() => stack.move()).toThrowWithMessage( expect(() => stack.move()).toThrowWithMessage(ReferenceError, "AsyncDisposableStack already disposed values");
ReferenceError,
"AsyncDisposableStack already disposed values"
);
}); });
}); });

View File

@ -53,10 +53,7 @@ describe("throws errors", () => {
test("if added object does not have a dispose method throws type error", () => { test("if added object does not have a dispose method throws type error", () => {
const stack = new AsyncDisposableStack(); const stack = new AsyncDisposableStack();
[{}, [], { f() {} }].forEach(value => { [{}, [], { f() {} }].forEach(value => {
expect(() => stack.use(value)).toThrowWithMessage( expect(() => stack.use(value)).toThrowWithMessage(TypeError, "does not have dispose method");
TypeError,
"does not have dispose method"
);
}); });
expect(stack.disposed).toBeFalse(); expect(stack.disposed).toBeFalse();

View File

@ -105,9 +105,7 @@ describe("correct behaviour", () => {
unhandledExceptionGenerator unhandledExceptionGenerator
.next("bad10") .next("bad10")
.then(() => { .then(() => {
expect().fail( expect().fail("Unhandled exception generator did NOT throw an unhandled exception.");
"Unhandled exception generator did NOT throw an unhandled exception."
);
}) })
.catch(e => { .catch(e => {
expect(e).toBe(1337); expect(e).toBe(1337);
@ -123,9 +121,7 @@ describe("correct behaviour", () => {
expect(iteratorResult.done).toBeTrue(); expect(iteratorResult.done).toBeTrue();
}) })
.catch(e => { .catch(e => {
expect().fail( expect().fail("Unhandled exception generator threw an unhandled exception in Completed state.");
"Unhandled exception generator threw an unhandled exception in Completed state."
);
}); });
runQueuedPromiseJobs(); runQueuedPromiseJobs();
}); });

View File

@ -21,10 +21,7 @@ describe("errors", () => {
expect(() => { expect(() => {
const typedArray = new Float32Array(4); const typedArray = new Float32Array(4);
Atomics.notify(typedArray, 0, 0); Atomics.notify(typedArray, 0, 0);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Typed array Float32Array element type is not Int32 or BigInt64");
TypeError,
"Typed array Float32Array element type is not Int32 or BigInt64"
);
}); });
test("invalid index", () => { test("invalid index", () => {

View File

@ -21,10 +21,7 @@ describe("errors", () => {
expect(() => { expect(() => {
const typedArray = new Float32Array(4); const typedArray = new Float32Array(4);
Atomics.wait(typedArray, 0, 0, 0); Atomics.wait(typedArray, 0, 0, 0);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Typed array Float32Array element type is not Int32 or BigInt64");
TypeError,
"Typed array Float32Array element type is not Int32 or BigInt64"
);
}); });
test("non-shared ArrayBuffer", () => { test("non-shared ArrayBuffer", () => {

View File

@ -21,10 +21,7 @@ describe("errors", () => {
expect(() => { expect(() => {
const typedArray = new Float32Array(4); const typedArray = new Float32Array(4);
Atomics.waitAsync(typedArray, 0, 0, 0); Atomics.waitAsync(typedArray, 0, 0, 0);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Typed array Float32Array element type is not Int32 or BigInt64");
TypeError,
"Typed array Float32Array element type is not Int32 or BigInt64"
);
}); });
test("non-shared ArrayBuffer", () => { test("non-shared ArrayBuffer", () => {

View File

@ -33,36 +33,22 @@ test("integer digits", () => {
expect(1n.toLocaleString("ar-u-nu-arab", { minimumIntegerDigits: 2 })).toBe("\u0660\u0661"); expect(1n.toLocaleString("ar-u-nu-arab", { minimumIntegerDigits: 2 })).toBe("\u0660\u0661");
expect(12n.toLocaleString("ar-u-nu-arab", { minimumIntegerDigits: 2 })).toBe("\u0661\u0662"); expect(12n.toLocaleString("ar-u-nu-arab", { minimumIntegerDigits: 2 })).toBe("\u0661\u0662");
expect(123n.toLocaleString("ar-u-nu-arab", { minimumIntegerDigits: 2 })).toBe( expect(123n.toLocaleString("ar-u-nu-arab", { minimumIntegerDigits: 2 })).toBe("\u0661\u0662\u0663");
"\u0661\u0662\u0663"
);
}); });
test("significant digits", () => { test("significant digits", () => {
expect( expect(1n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })).toBe("1.000");
1n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 }) expect(12n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })).toBe("12.00");
).toBe("1.000"); expect(123n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })).toBe("123.0");
expect( expect(1234n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })).toBe("1,234");
12n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 }) expect(12345n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })).toBe("12,345");
).toBe("12.00"); expect(123456n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })).toBe("123,456");
expect( expect(1234567n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })).toBe(
123n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 }) "1,234,570"
).toBe("123.0"); );
expect( expect(1234561n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })).toBe(
1234n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 }) "1,234,560"
).toBe("1,234"); );
expect(
12345n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })
).toBe("12,345");
expect(
123456n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })
).toBe("123,456");
expect(
1234567n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })
).toBe("1,234,570");
expect(
1234561n.toLocaleString("en", { minimumSignificantDigits: 4, maximumSignificantDigits: 6 })
).toBe("1,234,560");
expect( expect(
1n.toLocaleString("ar-u-nu-arab", { 1n.toLocaleString("ar-u-nu-arab", {

View File

@ -30,8 +30,7 @@ describe("correct behavior", () => {
expect(2n ** 3n).toBe(8n); expect(2n ** 3n).toBe(8n);
expect(5n % 3n).toBe(2n); expect(5n % 3n).toBe(2n);
expect( expect(
45977665298704210987n + 45977665298704210987n + (714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n
(714320987142450987412098743217984576n / 4598741987421098765327980n) * 987498743n
).toBe(199365500239020623962n); ).toBe(199365500239020623962n);
}); });

View File

@ -4,10 +4,7 @@ const doTest = (operatorName, executeOperation) => {
expect(() => { expect(() => {
executeOperation(1n, value); executeOperation(1n, value);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, `Cannot use ${operatorName} operator with BigInt${messageSuffix}`);
TypeError,
`Cannot use ${operatorName} operator with BigInt${messageSuffix}`
);
}); });
}; };

View File

@ -2,28 +2,19 @@ test("Issue #9336, integer overflow in get_view_value", () => {
const dataView = new DataView(new ArrayBuffer(16)); const dataView = new DataView(new ArrayBuffer(16));
expect(() => { expect(() => {
dataView.getUint32(0xfffffffc); dataView.getUint32(0xfffffffc);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Data view byte offset 4294967292 is out of range for buffer with length 16");
RangeError,
"Data view byte offset 4294967292 is out of range for buffer with length 16"
);
}); });
test("Issue #9338, integer overflow in set_view_value", () => { test("Issue #9338, integer overflow in set_view_value", () => {
const dataView = new DataView(new ArrayBuffer(16)); const dataView = new DataView(new ArrayBuffer(16));
expect(() => { expect(() => {
dataView.setUint32(0xfffffffc, 0); dataView.setUint32(0xfffffffc, 0);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Data view byte offset 4294967292 is out of range for buffer with length 16");
RangeError,
"Data view byte offset 4294967292 is out of range for buffer with length 16"
);
}); });
test("Issue #9338, integer overflow in set_view_value - zero-length DataView", () => { test("Issue #9338, integer overflow in set_view_value - zero-length DataView", () => {
const dataView = new DataView(new ArrayBuffer(4), 4); const dataView = new DataView(new ArrayBuffer(4), 4);
expect(() => { expect(() => {
dataView.setUint32(0xfffffffc, 0); dataView.setUint32(0xfffffffc, 0);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Data view byte offset 4294967292 is out of range for buffer with length 0");
RangeError,
"Data view byte offset 4294967292 is out of range for buffer with length 0"
);
}); });

View File

@ -25,9 +25,7 @@ test("basic functionality", () => {
expect(Date.parse("2024-01-08 9:00Z")).toBe(1704704400000); expect(Date.parse("2024-01-08 9:00Z")).toBe(1704704400000);
expect(Date.parse("Wed, 17 Jan 2024 11:36:34 +0000")).toBe(1705491394000); expect(Date.parse("Wed, 17 Jan 2024 11:36:34 +0000")).toBe(1705491394000);
expect(Date.parse("Thu, 09 Jan 2025 23:00:00")).toBe(1736485200000); expect(Date.parse("Thu, 09 Jan 2025 23:00:00")).toBe(1736485200000);
expect(Date.parse("Sun Jan 21 2024 21:11:31 GMT +0100 (Central European Standard Time)")).toBe( expect(Date.parse("Sun Jan 21 2024 21:11:31 GMT +0100 (Central European Standard Time)")).toBe(1705867891000);
1705867891000
);
expect(Date.parse("05 Jul 2024 00:00")).toBe(1720155600000); expect(Date.parse("05 Jul 2024 00:00")).toBe(1720155600000);
expect(Date.parse("05 Jul 2024")).toBe(1720155600000); expect(Date.parse("05 Jul 2024")).toBe(1720155600000);
expect(Date.parse("05 July 2024")).toBe(1720155600000); expect(Date.parse("05 July 2024")).toBe(1720155600000);

View File

@ -73,9 +73,7 @@ test("canonical format: ECMA date time string format", () => {
expect("1980-10-01T10:34:56.789Z").toBe(new Date("1980-10T12:34:56.789+0200").toISOString()); expect("1980-10-01T10:34:56.789Z").toBe(new Date("1980-10T12:34:56.789+0200").toISOString());
expect("1980-10-11T10:34:56.789Z").toBe(new Date("1980-10-11T12:34:56.789+0200").toISOString()); expect("1980-10-11T10:34:56.789Z").toBe(new Date("1980-10-11T12:34:56.789+0200").toISOString());
expect("1980-10-11T10:34:54.789Z").toBe( expect("1980-10-11T10:34:54.789Z").toBe(new Date("1980-10-11T12:34:56.789+020002").toISOString());
new Date("1980-10-11T12:34:56.789+020002").toISOString()
);
// Timezone offset HH:MM // Timezone offset HH:MM
expect("1980-01-01T10:34:00.000Z").toBe(new Date("1980T12:34+02:00").toISOString()); expect("1980-01-01T10:34:00.000Z").toBe(new Date("1980T12:34+02:00").toISOString());
@ -88,9 +86,7 @@ test("canonical format: ECMA date time string format", () => {
expect("1980-01-01T10:34:56.789Z").toBe(new Date("1980T12:34:56.789+02:00").toISOString()); expect("1980-01-01T10:34:56.789Z").toBe(new Date("1980T12:34:56.789+02:00").toISOString());
expect("1980-10-01T10:34:56.789Z").toBe(new Date("1980-10T12:34:56.789+02:00").toISOString()); expect("1980-10-01T10:34:56.789Z").toBe(new Date("1980-10T12:34:56.789+02:00").toISOString());
expect("1980-10-11T10:34:56.789Z").toBe( expect("1980-10-11T10:34:56.789Z").toBe(new Date("1980-10-11T12:34:56.789+02:00").toISOString());
new Date("1980-10-11T12:34:56.789+02:00").toISOString()
);
setTimeZone(originalTimeZone); setTimeZone(originalTimeZone);
}); });
@ -109,12 +105,8 @@ test('canonical format: ECMA + ISO8601 extensions ("simplified" ISO8601)', () =>
expect("1980-10-11T10:34:11.000Z").toBe(new Date("1980-10-11T12:34:56+02:00:45").toISOString()); expect("1980-10-11T10:34:11.000Z").toBe(new Date("1980-10-11T12:34:56+02:00:45").toISOString());
expect("1980-01-01T10:34:11.789Z").toBe(new Date("1980T12:34:56.789+02:00:45").toISOString()); expect("1980-01-01T10:34:11.789Z").toBe(new Date("1980T12:34:56.789+02:00:45").toISOString());
expect("1980-10-01T10:34:11.789Z").toBe( expect("1980-10-01T10:34:11.789Z").toBe(new Date("1980-10T12:34:56.789+02:00:45").toISOString());
new Date("1980-10T12:34:56.789+02:00:45").toISOString() expect("1980-10-11T10:34:11.789Z").toBe(new Date("1980-10-11T12:34:56.789+02:00:45").toISOString());
);
expect("1980-10-11T10:34:11.789Z").toBe(
new Date("1980-10-11T12:34:56.789+02:00:45").toISOString()
);
// The ECMA date-time string format requires literal uppercase 'T' and 'Z'. // The ECMA date-time string format requires literal uppercase 'T' and 'Z'.
// Chrome also accepts lowercase. // Chrome also accepts lowercase.
@ -126,37 +118,19 @@ test('canonical format: ECMA + ISO8601 extensions ("simplified" ISO8601)', () =>
// Timezone offset HH:MM:SS.Ns // Timezone offset HH:MM:SS.Ns
expect("1980-01-01T10:33:14.322Z").toBe(new Date("1980T12:34+02:00:45.678").toISOString()); expect("1980-01-01T10:33:14.322Z").toBe(new Date("1980T12:34+02:00:45.678").toISOString());
expect("1980-10-01T10:33:14.322Z").toBe(new Date("1980-10T12:34+02:00:45.678").toISOString()); expect("1980-10-01T10:33:14.322Z").toBe(new Date("1980-10T12:34+02:00:45.678").toISOString());
expect("1980-10-11T10:33:14.322Z").toBe( expect("1980-10-11T10:33:14.322Z").toBe(new Date("1980-10-11T12:34+02:00:45.678").toISOString());
new Date("1980-10-11T12:34+02:00:45.678").toISOString()
);
expect("1980-01-01T10:34:10.322Z").toBe(new Date("1980T12:34:56+02:00:45.678").toISOString()); expect("1980-01-01T10:34:10.322Z").toBe(new Date("1980T12:34:56+02:00:45.678").toISOString());
expect("1980-10-01T10:34:10.322Z").toBe( expect("1980-10-01T10:34:10.322Z").toBe(new Date("1980-10T12:34:56+02:00:45.678").toISOString());
new Date("1980-10T12:34:56+02:00:45.678").toISOString() expect("1980-10-11T10:34:10.322Z").toBe(new Date("1980-10-11T12:34:56+02:00:45.678").toISOString());
);
expect("1980-10-11T10:34:10.322Z").toBe(
new Date("1980-10-11T12:34:56+02:00:45.678").toISOString()
);
expect("1980-01-01T10:34:11.111Z").toBe( expect("1980-01-01T10:34:11.111Z").toBe(new Date("1980T12:34:56.789+02:00:45.678").toISOString());
new Date("1980T12:34:56.789+02:00:45.678").toISOString() expect("1980-10-01T10:34:11.111Z").toBe(new Date("1980-10T12:34:56.789+02:00:45.678").toISOString());
); expect("1980-10-11T10:34:11.111Z").toBe(new Date("1980-10-11T12:34:56.789+02:00:45.678").toISOString());
expect("1980-10-01T10:34:11.111Z").toBe(
new Date("1980-10T12:34:56.789+02:00:45.678").toISOString()
);
expect("1980-10-11T10:34:11.111Z").toBe(
new Date("1980-10-11T12:34:56.789+02:00:45.678").toISOString()
);
expect("1980-01-01T10:34:11.666Z").toBe( expect("1980-01-01T10:34:11.666Z").toBe(new Date("1980T12:34:56.789+02:00:45.123456879").toISOString());
new Date("1980T12:34:56.789+02:00:45.123456879").toISOString() expect("1980-10-01T10:34:11.666Z").toBe(new Date("1980-10T12:34:56.789+02:00:45.123456879").toISOString());
); expect("1980-10-11T10:34:11.666Z").toBe(new Date("1980-10-11T12:34:56.789+02:00:45.123456879").toISOString());
expect("1980-10-01T10:34:11.666Z").toBe(
new Date("1980-10T12:34:56.789+02:00:45.123456879").toISOString()
);
expect("1980-10-11T10:34:11.666Z").toBe(
new Date("1980-10-11T12:34:56.789+02:00:45.123456879").toISOString()
);
// Expanded years https://tc39.es/ecma262/#sec-expanded-years // Expanded years https://tc39.es/ecma262/#sec-expanded-years
expect("2023-01-01T00:00:00.000Z").toBe(new Date("+002023").toISOString()); expect("2023-01-01T00:00:00.000Z").toBe(new Date("+002023").toISOString());
@ -168,40 +142,20 @@ test('canonical format: ECMA + ISO8601 extensions ("simplified" ISO8601)', () =>
expect("2023-10-11T19:34:56.789Z").toBe(new Date("+002023-10-11T12:34:56.789").toISOString()); expect("2023-10-11T19:34:56.789Z").toBe(new Date("+002023-10-11T12:34:56.789").toISOString());
expect("2023-10-11T12:34:56.000Z").toBe(new Date("+002023-10-11T12:34:56Z").toISOString()); expect("2023-10-11T12:34:56.000Z").toBe(new Date("+002023-10-11T12:34:56Z").toISOString());
expect("2023-10-11T12:34:56.789Z").toBe(new Date("+002023-10-11T12:34:56.789Z").toISOString()); expect("2023-10-11T12:34:56.789Z").toBe(new Date("+002023-10-11T12:34:56.789Z").toISOString());
expect("2023-10-11T10:34:56.789Z").toBe( expect("2023-10-11T10:34:56.789Z").toBe(new Date("+002023-10-11T12:34:56.789+0200").toISOString());
new Date("+002023-10-11T12:34:56.789+0200").toISOString() expect("2023-10-11T10:34:56.789Z").toBe(new Date("+002023-10-11T12:34:56.789+02:00").toISOString());
); expect("2023-10-11T10:34:11.666Z").toBe(new Date("+002023-10-11T12:34:56.789+02:00:45.123").toISOString());
expect("2023-10-11T10:34:56.789Z").toBe( expect("2023-10-11T10:34:11.666Z").toBe(new Date("+002023-10-11T12:34:56.789+02:00:45.123456789").toISOString());
new Date("+002023-10-11T12:34:56.789+02:00").toISOString()
);
expect("2023-10-11T10:34:11.666Z").toBe(
new Date("+002023-10-11T12:34:56.789+02:00:45.123").toISOString()
);
expect("2023-10-11T10:34:11.666Z").toBe(
new Date("+002023-10-11T12:34:56.789+02:00:45.123456789").toISOString()
);
expect("-002023-10-11T00:00:00.000Z").toBe(new Date("-002023-10-11").toISOString()); expect("-002023-10-11T00:00:00.000Z").toBe(new Date("-002023-10-11").toISOString());
expect("-002023-10-11T20:46:28.000Z").toBe(new Date("-002023-10-11T12:34").toISOString()); expect("-002023-10-11T20:46:28.000Z").toBe(new Date("-002023-10-11T12:34").toISOString());
expect("-002023-10-11T20:47:24.000Z").toBe(new Date("-002023-10-11T12:34:56").toISOString()); expect("-002023-10-11T20:47:24.000Z").toBe(new Date("-002023-10-11T12:34:56").toISOString());
expect("-002023-10-11T20:47:24.789Z").toBe( expect("-002023-10-11T20:47:24.789Z").toBe(new Date("-002023-10-11T12:34:56.789").toISOString());
new Date("-002023-10-11T12:34:56.789").toISOString() expect("-002023-10-11T10:34:56.789Z").toBe(new Date("-002023-10-11T12:34:56.789+0200").toISOString());
); expect("-002023-10-11T10:34:56.789Z").toBe(new Date("-002023-10-11T12:34:56.789+02:00").toISOString());
expect("-002023-10-11T10:34:56.789Z").toBe( expect("-002023-10-11T10:34:11.789Z").toBe(new Date("-002023-10-11T12:34:56.789+02:00:45").toISOString());
new Date("-002023-10-11T12:34:56.789+0200").toISOString() expect("-002023-10-11T10:34:11.666Z").toBe(new Date("-002023-10-11T12:34:56.789+02:00:45.123").toISOString());
); expect("-002023-10-11T10:34:11.666Z").toBe(new Date("-002023-10-11T12:34:56.789+02:00:45.123456789").toISOString());
expect("-002023-10-11T10:34:56.789Z").toBe(
new Date("-002023-10-11T12:34:56.789+02:00").toISOString()
);
expect("-002023-10-11T10:34:11.789Z").toBe(
new Date("-002023-10-11T12:34:56.789+02:00:45").toISOString()
);
expect("-002023-10-11T10:34:11.666Z").toBe(
new Date("-002023-10-11T12:34:56.789+02:00:45.123").toISOString()
);
expect("-002023-10-11T10:34:11.666Z").toBe(
new Date("-002023-10-11T12:34:56.789+02:00:45.123456789").toISOString()
);
expect("0000-02-03T12:34:56.789Z").toBe(new Date("+000000-02-03T12:34:56.789Z").toISOString()); expect("0000-02-03T12:34:56.789Z").toBe(new Date("+000000-02-03T12:34:56.789Z").toISOString());
@ -219,9 +173,7 @@ test("canonical format: Date.toString", () => {
const originalTimeZone = setTimeZone("America/Vancouver"); const originalTimeZone = setTimeZone("America/Vancouver");
expect("1999-12-08T12:34:56.000Z").toBe(new Date("Wed Dec 08 1999 12:34:56 GMT").toISOString()); // Clint Eastwood elected mayor of Carmel expect("1999-12-08T12:34:56.000Z").toBe(new Date("Wed Dec 08 1999 12:34:56 GMT").toISOString()); // Clint Eastwood elected mayor of Carmel
expect("1999-12-08T20:34:56.000Z").toBe( expect("1999-12-08T20:34:56.000Z").toBe(new Date("Wed Dec 08 1999 12:34:56 GMT-0800").toISOString());
new Date("Wed Dec 08 1999 12:34:56 GMT-0800").toISOString()
);
expect("1999-12-08T20:34:56.000Z").toBe( expect("1999-12-08T20:34:56.000Z").toBe(
new Date("Wed Dec 08 1999 12:34:56 GMT-0800 (Pacific Standard Time)").toISOString() new Date("Wed Dec 08 1999 12:34:56 GMT-0800 (Pacific Standard Time)").toISOString()
); );
@ -234,12 +186,8 @@ test("canonical format: Date.toString", () => {
}); });
test("canonical format: Date.toUTCString", () => { test("canonical format: Date.toUTCString", () => {
expect("1999-12-08T08:00:00.000Z").toBe( expect("1999-12-08T08:00:00.000Z").toBe(new Date("Wed, 08 Dec 1999 08:00:00 GMT").toISOString());
new Date("Wed, 08 Dec 1999 08:00:00 GMT").toISOString() expect("1999-12-08T08:00:00.000Z").toBe(new Date("Thu, 08 Dec 1999 08:00:00 GMT").toISOString()); // Wrong weekday is ignored
);
expect("1999-12-08T08:00:00.000Z").toBe(
new Date("Thu, 08 Dec 1999 08:00:00 GMT").toISOString()
); // Wrong weekday is ignored
}); });
test("ambiguous date: 1 number", () => { test("ambiguous date: 1 number", () => {
@ -573,12 +521,8 @@ test("timezone offset", () => {
expect("2019-07-18T08:01:00.000Z").toBe(new Date("07/18/2019 11:22 +3:21").toISOString()); expect("2019-07-18T08:01:00.000Z").toBe(new Date("07/18/2019 11:22 +3:21").toISOString());
expect("2019-07-18T08:00:51.000Z").toBe(new Date("07/18/2019 11:22 +03:21:09").toISOString()); // Chrome and Firefox do not support seconds in timezone offset expect("2019-07-18T08:00:51.000Z").toBe(new Date("07/18/2019 11:22 +03:21:09").toISOString()); // Chrome and Firefox do not support seconds in timezone offset
expect("2019-07-18T08:00:50.877Z").toBe( expect("2019-07-18T08:00:50.877Z").toBe(new Date("07/18/2019 11:22 +03:21:09.123").toISOString());
new Date("07/18/2019 11:22 +03:21:09.123").toISOString() expect("2019-07-18T08:00:50.877Z").toBe(new Date("07/18/2019 11:22 +03:21:09.12345678").toISOString()); // Truncate to milliseconds
);
expect("2019-07-18T08:00:50.877Z").toBe(
new Date("07/18/2019 11:22 +03:21:09.12345678").toISOString()
); // Truncate to milliseconds
expect("2019-07-18T08:22:00.000Z").toBe(new Date("07/18/2019 11:22 GMT+03").toISOString()); expect("2019-07-18T08:22:00.000Z").toBe(new Date("07/18/2019 11:22 GMT+03").toISOString());
expect("2019-07-18T08:22:00.000Z").toBe(new Date("07/18/2019 11:22 UTC+03").toISOString()); expect("2019-07-18T08:22:00.000Z").toBe(new Date("07/18/2019 11:22 UTC+03").toISOString());
@ -654,9 +598,7 @@ test("us timezones", () => {
expect("2025-02-23T12:34:00.000Z").toBe(new Date("23 feb 2025 12:34 UTC").toISOString()); expect("2025-02-23T12:34:00.000Z").toBe(new Date("23 feb 2025 12:34 UTC").toISOString());
expect("2025-02-23T12:34:00.000Z").toBe(new Date("23 feb 2025 12:34 Z").toISOString()); expect("2025-02-23T12:34:00.000Z").toBe(new Date("23 feb 2025 12:34 Z").toISOString());
expect("2025-02-23T18:34:00.000Z").toBe( expect("2025-02-23T18:34:00.000Z").toBe(new Date("23 EST feb PDT 2025 CST 12:34").toISOString()); // For multiple occurrences, the last one wins
new Date("23 EST feb PDT 2025 CST 12:34").toISOString()
); // For multiple occurrences, the last one wins
expect("2022-02-12T20:34:00.000Z").toBe(new Date("2/12/22 12:34 +0100 PST").toISOString()); // Timezone name wins after timezone offset. expect("2022-02-12T20:34:00.000Z").toBe(new Date("2/12/22 12:34 +0100 PST").toISOString()); // Timezone name wins after timezone offset.
expect(Date.parse("12-Dec-2024 15:30:00 PT")).toBeNaN(); // Non-qualified timezone names ("PT"="Pacific Time"; no S/D) are not recognized expect(Date.parse("12-Dec-2024 15:30:00 PT")).toBeNaN(); // Non-qualified timezone names ("PT"="Pacific Time"; no S/D) are not recognized
@ -682,9 +624,7 @@ test("weekdays", () => {
expect("2024-12-05T08:00:00.000Z").toBe(new Date("Thurnip Dec 5 2024").toISOString()); expect("2024-12-05T08:00:00.000Z").toBe(new Date("Thurnip Dec 5 2024").toISOString());
expect("2024-12-05T08:00:00.000Z").toBe(new Date("Mon Dec 5 2024").toISOString()); // Incorrect weekday is ignored. expect("2024-12-05T08:00:00.000Z").toBe(new Date("Mon Dec 5 2024").toISOString()); // Incorrect weekday is ignored.
expect("2024-12-05T08:00:00.000Z").toBe(new Date("Theater Dec 5 2024").toISOString()); // Anything before the first number is ignored. expect("2024-12-05T08:00:00.000Z").toBe(new Date("Theater Dec 5 2024").toISOString()); // Anything before the first number is ignored.
expect("2024-12-05T08:00:00.000Z").toBe( expect("2024-12-05T08:00:00.000Z").toBe(new Date("Mon Tue Wed Dec Thu YMCA 5 2024").toISOString());
new Date("Mon Tue Wed Dec Thu YMCA 5 2024").toISOString()
);
expect(Date.parse("Mon Dec Tue 5 Wed 2024")).toBeNaN(); // Weekday names (or any other word) fail after the first number expect(Date.parse("Mon Dec Tue 5 Wed 2024")).toBeNaN(); // Weekday names (or any other word) fail after the first number
expect(Date.parse("Mon Dec Tue 5 Wed 2024 Thu")).toBeNaN(); expect(Date.parse("Mon Dec Tue 5 Wed 2024 Thu")).toBeNaN();
@ -696,15 +636,9 @@ test("timezone name", () => {
// Compatible with Chrome and Firefox. Anything that is not a closing bracket following an open bracket is ignored. // Compatible with Chrome and Firefox. Anything that is not a closing bracket following an open bracket is ignored.
const originalTimeZone = setTimeZone("America/Vancouver"); const originalTimeZone = setTimeZone("America/Vancouver");
expect("2020-12-05T20:23:00.000Z").toBe( expect("2020-12-05T20:23:00.000Z").toBe(new Date("Thu Dec 5 2020 12:23 -0800 (America/Vancouver)").toISOString());
new Date("Thu Dec 5 2020 12:23 -0800 (America/Vancouver)").toISOString() expect("2020-12-05T20:23:00.000Z").toBe(new Date("Thu Dec 5 2020 12:23 -0800 (America/Chicago)").toISOString()); // Incorrect time zone name.
); expect("2020-12-05T20:23:00.000Z").toBe(new Date("Thu Dec 5 2020 12:23 (America/Chicago)").toISOString()); // Missing timezone offset makes it local time. Timezone name is ignored.
expect("2020-12-05T20:23:00.000Z").toBe(
new Date("Thu Dec 5 2020 12:23 -0800 (America/Chicago)").toISOString()
); // Incorrect time zone name.
expect("2020-12-05T20:23:00.000Z").toBe(
new Date("Thu Dec 5 2020 12:23 (America/Chicago)").toISOString()
); // Missing timezone offset makes it local time. Timezone name is ignored.
expect("2020-12-05T20:23:00.000Z").toBe( expect("2020-12-05T20:23:00.000Z").toBe(
new Date( new Date(
"Thu Dec 5 2020 12:23 -0800 (Whatever alpha 123 numerics or punctuation $# ({}[] works )" "Thu Dec 5 2020 12:23 -0800 (Whatever alpha 123 numerics or punctuation $# ({}[] works )"
@ -731,9 +665,7 @@ test("garbage", () => {
// Accept punctuation at any point before time. // Accept punctuation at any point before time.
// Firefox fails in some conditions before time. // Firefox fails in some conditions before time.
// Chrome is finnicky on interior punctuation. // Chrome is finnicky on interior punctuation.
expect("2204-01-20T02:32:00.000Z").toBe( expect("2204-01-20T02:32:00.000Z").toBe(new Date("2204 //. -/, Jan ./- 20 ..- 10:32 GMT+08:00").toISOString());
new Date("2204 //. -/, Jan ./- 20 ..- 10:32 GMT+08:00").toISOString()
);
// Chrome does not accept punctuation after time. Firefox accepts some. We accept punctuation. // Chrome does not accept punctuation after time. Firefox accepts some. We accept punctuation.
expect("2204-01-29T18:30:00.000Z").toBe(new Date("2204 Jan 29 10:30 /--/").toISOString()); expect("2204-01-29T18:30:00.000Z").toBe(new Date("2204 Jan 29 10:30 /--/").toISOString());
@ -756,18 +688,10 @@ test("multiple month names", () => {
const originalTimeZone = setTimeZone("America/Vancouver"); const originalTimeZone = setTimeZone("America/Vancouver");
// Multiple month names are accepted. Last one wins. // Multiple month names are accepted. Last one wins.
expect("1981-03-23T22:56:00.000Z").toBe( expect("1981-03-23T22:56:00.000Z").toBe(new Date("March 23, 1981 14:56 GMT-08:00").toISOString());
new Date("March 23, 1981 14:56 GMT-08:00").toISOString() expect("1981-04-23T22:56:00.000Z").toBe(new Date("March 23, Apr 1981 14:56 GMT-08:00").toISOString());
); expect("1981-05-23T22:56:00.000Z").toBe(new Date("March 23, Apron 1981 mAY 14:56 GMT-08:00").toISOString());
expect("1981-04-23T22:56:00.000Z").toBe( expect("1981-06-23T22:56:00.000Z").toBe(new Date("March 23, Apron 1981 mAY 14:56 junuary GMT-08:00").toISOString());
new Date("March 23, Apr 1981 14:56 GMT-08:00").toISOString()
);
expect("1981-05-23T22:56:00.000Z").toBe(
new Date("March 23, Apron 1981 mAY 14:56 GMT-08:00").toISOString()
);
expect("1981-06-23T22:56:00.000Z").toBe(
new Date("March 23, Apron 1981 mAY 14:56 junuary GMT-08:00").toISOString()
);
expect("1981-07-23T22:56:00.000Z").toBe( expect("1981-07-23T22:56:00.000Z").toBe(
new Date("March 23, Apron 1981 mAY 14:56 junuary GMT-08:00 Julie").toISOString() new Date("March 23, Apron 1981 mAY 14:56 junuary GMT-08:00 Julie").toISOString()
); );

View File

@ -45,12 +45,8 @@ describe("correct behavior", () => {
}); });
test("dateStyle may be set", () => { test("dateStyle may be set", () => {
expect(d0.toLocaleDateString("en", { dateStyle: "full", timeZone: "UTC" })).toBe( expect(d0.toLocaleDateString("en", { dateStyle: "full", timeZone: "UTC" })).toBe("Tuesday, December 7, 2021");
"Tuesday, December 7, 2021" expect(d1.toLocaleDateString("en", { dateStyle: "full", timeZone: "UTC" })).toBe("Monday, January 23, 1989");
);
expect(d1.toLocaleDateString("en", { dateStyle: "full", timeZone: "UTC" })).toBe(
"Monday, January 23, 1989"
);
expect(d0.toLocaleDateString("ar-u-nu-arab", { dateStyle: "full", timeZone: "UTC" })).toBe( expect(d0.toLocaleDateString("ar-u-nu-arab", { dateStyle: "full", timeZone: "UTC" })).toBe(
"الثلاثاء، ٧ ديسمبر ٢٠٢١" "الثلاثاء، ٧ ديسمبر ٢٠٢١"

View File

@ -34,35 +34,23 @@ describe("correct behavior", () => {
expect(d0.toLocaleString("en", { timeZone: "UTC" })).toBe("12/7/2021, 5:40:50 PM"); expect(d0.toLocaleString("en", { timeZone: "UTC" })).toBe("12/7/2021, 5:40:50 PM");
expect(d1.toLocaleString("en", { timeZone: "UTC" })).toBe("1/23/1989, 7:08:09 AM"); expect(d1.toLocaleString("en", { timeZone: "UTC" })).toBe("1/23/1989, 7:08:09 AM");
expect(d0.toLocaleString("ar-u-nu-arab", { timeZone: "UTC" })).toBe( expect(d0.toLocaleString("ar-u-nu-arab", { timeZone: "UTC" })).toBe("٧/١٢‏/٢٠٢١، ٥:٤٠:٥٠ م");
"٧/١٢‏/٢٠٢١، ٥:٤٠:٥٠ م" expect(d1.toLocaleString("ar-u-nu-arab", { timeZone: "UTC" })).toBe("٢٣‏/١/١٩٨٩، ٧:٠٨:٠٩ ص");
);
expect(d1.toLocaleString("ar-u-nu-arab", { timeZone: "UTC" })).toBe(
"٢٣‏/١/١٩٨٩، ٧:٠٨:٠٩ ص"
);
}); });
test("dateStyle may be set", () => { test("dateStyle may be set", () => {
expect(d0.toLocaleString("en", { dateStyle: "short", timeZone: "UTC" })).toBe("12/7/21"); expect(d0.toLocaleString("en", { dateStyle: "short", timeZone: "UTC" })).toBe("12/7/21");
expect(d1.toLocaleString("en", { dateStyle: "short", timeZone: "UTC" })).toBe("1/23/89"); expect(d1.toLocaleString("en", { dateStyle: "short", timeZone: "UTC" })).toBe("1/23/89");
expect(d0.toLocaleString("ar-u-nu-arab", { dateStyle: "short", timeZone: "UTC" })).toBe( expect(d0.toLocaleString("ar-u-nu-arab", { dateStyle: "short", timeZone: "UTC" })).toBe("٧/١٢‏/٢٠٢١");
"٧/١٢‏/٢٠٢١" expect(d1.toLocaleString("ar-u-nu-arab", { dateStyle: "short", timeZone: "UTC" })).toBe("٢٣‏/١/١٩٨٩");
);
expect(d1.toLocaleString("ar-u-nu-arab", { dateStyle: "short", timeZone: "UTC" })).toBe(
"٢٣‏/١/١٩٨٩"
);
}); });
test("timeStyle may be set", () => { test("timeStyle may be set", () => {
expect(d0.toLocaleString("en", { timeStyle: "short", timeZone: "UTC" })).toBe("5:40 PM"); expect(d0.toLocaleString("en", { timeStyle: "short", timeZone: "UTC" })).toBe("5:40 PM");
expect(d1.toLocaleString("en", { timeStyle: "short", timeZone: "UTC" })).toBe("7:08 AM"); expect(d1.toLocaleString("en", { timeStyle: "short", timeZone: "UTC" })).toBe("7:08 AM");
expect(d0.toLocaleString("ar-u-nu-arab", { timeStyle: "short", timeZone: "UTC" })).toBe( expect(d0.toLocaleString("ar-u-nu-arab", { timeStyle: "short", timeZone: "UTC" })).toBe("٥:٤٠ م");
"٥:٤٠ م" expect(d1.toLocaleString("ar-u-nu-arab", { timeStyle: "short", timeZone: "UTC" })).toBe("٧:٠٨ ص");
);
expect(d1.toLocaleString("ar-u-nu-arab", { timeStyle: "short", timeZone: "UTC" })).toBe(
"٧:٠٨ ص"
);
}); });
}); });

View File

@ -45,18 +45,10 @@ describe("correct behavior", () => {
}); });
test("timeStyle may be set", () => { test("timeStyle may be set", () => {
expect(d0.toLocaleTimeString("en", { timeStyle: "long", timeZone: "UTC" })).toBe( expect(d0.toLocaleTimeString("en", { timeStyle: "long", timeZone: "UTC" })).toBe("5:40:50 PM UTC");
"5:40:50 PM UTC" expect(d1.toLocaleTimeString("en", { timeStyle: "long", timeZone: "UTC" })).toBe("7:08:09 AM UTC");
);
expect(d1.toLocaleTimeString("en", { timeStyle: "long", timeZone: "UTC" })).toBe(
"7:08:09 AM UTC"
);
expect(d0.toLocaleTimeString("ar-u-nu-arab", { timeStyle: "long", timeZone: "UTC" })).toBe( expect(d0.toLocaleTimeString("ar-u-nu-arab", { timeStyle: "long", timeZone: "UTC" })).toBe("٥:٤٠:٥٠ م UTC");
"٥:٤٠:٥٠ م UTC" expect(d1.toLocaleTimeString("ar-u-nu-arab", { timeStyle: "long", timeZone: "UTC" })).toBe("٧:٠٨:٠٩ ص UTC");
);
expect(d1.toLocaleTimeString("ar-u-nu-arab", { timeStyle: "long", timeZone: "UTC" })).toBe(
"٧:٠٨:٠٩ ص UTC"
);
}); });
}); });

View File

@ -54,9 +54,6 @@ describe("throws errors", () => {
stack.dispose(); stack.dispose();
expect(stack.disposed).toBeTrue(); expect(stack.disposed).toBeTrue();
expect(() => stack.move()).toThrowWithMessage( expect(() => stack.move()).toThrowWithMessage(ReferenceError, "DisposableStack already disposed values");
ReferenceError,
"DisposableStack already disposed values"
);
}); });
}); });

View File

@ -53,10 +53,7 @@ describe("throws errors", () => {
test("if added object does not have a dispose method throws type error", () => { test("if added object does not have a dispose method throws type error", () => {
const stack = new DisposableStack(); const stack = new DisposableStack();
[{}, [], { f() {} }].forEach(value => { [{}, [], { f() {} }].forEach(value => {
expect(() => stack.use(value)).toThrowWithMessage( expect(() => stack.use(value)).toThrowWithMessage(TypeError, "does not have dispose method");
TypeError,
"does not have dispose method"
);
}); });
expect(stack.disposed).toBeFalse(); expect(stack.disposed).toBeFalse();

View File

@ -14,10 +14,7 @@ describe("errors", () => {
test("called without new", () => { test("called without new", () => {
expect(() => { expect(() => {
FinalizationRegistry(); FinalizationRegistry();
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "FinalizationRegistry constructor must be called with 'new'");
TypeError,
"FinalizationRegistry constructor must be called with 'new'"
);
}); });
}); });

View File

@ -21,12 +21,8 @@ describe("correct behavior", () => {
expect(new Function("foo", "bar", "return foo + bar")(1, 2)).toBe(3); expect(new Function("foo", "bar", "return foo + bar")(1, 2)).toBe(3);
expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6); expect(new Function("foo", "bar,baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6); expect(new Function("foo", "bar", "baz", "return foo + bar + baz")(1, 2, 3)).toBe(6);
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe( expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(true)).toBe(42);
42 expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe("bar");
);
expect(new Function("foo", "if (foo) { return 42; } else { return 'bar'; }")(false)).toBe(
"bar"
);
expect(new Function("return typeof Function()")()).toBe("function"); expect(new Function("return typeof Function()")()).toBe("function");
expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3); expect(new Function("x", "return function (y) { return x + y };")(1)(2)).toBe(3);
@ -49,10 +45,7 @@ describe("errors", () => {
// FIXME: The position is odd though, I'd expect `line: 2, column: 2` and `line: 3, column: 1`... // FIXME: The position is odd though, I'd expect `line: 2, column: 2` and `line: 3, column: 1`...
// > eval("\n[") // Uncaught exception: [SyntaxError] Unexpected token Eof. Expected BracketClose (line: 2, column: 2) // > eval("\n[") // Uncaught exception: [SyntaxError] Unexpected token Eof. Expected BracketClose (line: 2, column: 2)
// > eval("\n[\n") // Uncaught exception: [SyntaxError] Unexpected token Eof. Expected BracketClose (line: 2, column: 3) // > eval("\n[\n") // Uncaught exception: [SyntaxError] Unexpected token Eof. Expected BracketClose (line: 2, column: 3)
.toThrowWithMessage( .toThrowWithMessage(SyntaxError, "Unexpected token Eof. Expected BracketClose (line: 2, column: 3)");
SyntaxError,
"Unexpected token Eof. Expected BracketClose (line: 2, column: 3)"
);
}); });
test("parameters and body must be valid standalone", () => { test("parameters and body must be valid standalone", () => {

View File

@ -39,12 +39,8 @@ describe("correct behavior", () => {
expect({ *foo() {} }.foo.toString()).toBe("*foo() {}"); expect({ *foo() {} }.foo.toString()).toBe("*foo() {}");
expect({ async foo() {} }.foo.toString()).toBe("async foo() {}"); expect({ async foo() {} }.foo.toString()).toBe("async foo() {}");
expect({ async *foo() {} }.foo.toString()).toBe("async *foo() {}"); expect({ async *foo() {} }.foo.toString()).toBe("async *foo() {}");
expect(Object.getOwnPropertyDescriptor({ get foo() {} }, "foo").get.toString()).toBe( expect(Object.getOwnPropertyDescriptor({ get foo() {} }, "foo").get.toString()).toBe("get foo() {}");
"get foo() {}" expect(Object.getOwnPropertyDescriptor({ set foo(x) {} }, "foo").set.toString()).toBe("set foo(x) {}");
);
expect(Object.getOwnPropertyDescriptor({ set foo(x) {} }, "foo").set.toString()).toBe(
"set foo(x) {}"
);
}); });
test("arrow function", () => { test("arrow function", () => {
@ -127,9 +123,9 @@ describe("correct behavior", () => {
// Built-in functions // Built-in functions
expect(console.debug.toString()).toBe("function debug() { [native code] }"); expect(console.debug.toString()).toBe("function debug() { [native code] }");
expect(Function.toString()).toBe("function Function() { [native code] }"); expect(Function.toString()).toBe("function Function() { [native code] }");
expect( expect(Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get.toString()).toBe(
Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get.toString() "function get format() { [native code] }"
).toBe("function get format() { [native code] }"); );
const values = [ const values = [
// Callable Proxy // Callable Proxy

View File

@ -51,10 +51,7 @@ describe("errors", () => {
["hello!", "+1", "+1:02", "+01:02:03"].forEach(timeZone => { ["hello!", "+1", "+1:02", "+01:02:03"].forEach(timeZone => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { timeZone: timeZone }); new Intl.DateTimeFormat("en", { timeZone: timeZone });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, `${timeZone} is not a valid value for option timeZone`);
RangeError,
`${timeZone} is not a valid value for option timeZone`
);
}); });
}); });
@ -65,10 +62,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { era: "narrow", dateStyle: "long" }); new Intl.DateTimeFormat("en", { era: "narrow", dateStyle: "long" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option era cannot be set when also providing dateStyle or timeStyle");
TypeError,
"Option era cannot be set when also providing dateStyle or timeStyle"
);
}); });
test("year option is invalid", () => { test("year option is invalid", () => {
@ -78,10 +72,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { year: "numeric", dateStyle: "long" }); new Intl.DateTimeFormat("en", { year: "numeric", dateStyle: "long" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option year cannot be set when also providing dateStyle or timeStyle");
TypeError,
"Option year cannot be set when also providing dateStyle or timeStyle"
);
}); });
test("month option is invalid", () => { test("month option is invalid", () => {
@ -91,10 +82,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { month: "numeric", dateStyle: "long" }); new Intl.DateTimeFormat("en", { month: "numeric", dateStyle: "long" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option month cannot be set when also providing dateStyle or timeStyle");
TypeError,
"Option month cannot be set when also providing dateStyle or timeStyle"
);
}); });
test("weekday option is invalid", () => { test("weekday option is invalid", () => {
@ -104,10 +92,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { weekday: "narrow", dateStyle: "long" }); new Intl.DateTimeFormat("en", { weekday: "narrow", dateStyle: "long" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option weekday cannot be set when also providing dateStyle or timeStyle");
TypeError,
"Option weekday cannot be set when also providing dateStyle or timeStyle"
);
}); });
test("day option is invalid", () => { test("day option is invalid", () => {
@ -117,10 +102,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { day: "numeric", dateStyle: "long" }); new Intl.DateTimeFormat("en", { day: "numeric", dateStyle: "long" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option day cannot be set when also providing dateStyle or timeStyle");
TypeError,
"Option day cannot be set when also providing dateStyle or timeStyle"
);
}); });
test("dayPeriod option is invalid", () => { test("dayPeriod option is invalid", () => {
@ -130,10 +112,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { dayPeriod: "narrow", dateStyle: "long" }); new Intl.DateTimeFormat("en", { dayPeriod: "narrow", dateStyle: "long" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option dayPeriod cannot be set when also providing dateStyle or timeStyle");
TypeError,
"Option dayPeriod cannot be set when also providing dateStyle or timeStyle"
);
}); });
test("hour option is invalid", () => { test("hour option is invalid", () => {
@ -143,10 +122,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { hour: "numeric", dateStyle: "long" }); new Intl.DateTimeFormat("en", { hour: "numeric", dateStyle: "long" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option hour cannot be set when also providing dateStyle or timeStyle");
TypeError,
"Option hour cannot be set when also providing dateStyle or timeStyle"
);
}); });
test("minute option is invalid", () => { test("minute option is invalid", () => {
@ -156,10 +132,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { minute: "numeric", dateStyle: "long" }); new Intl.DateTimeFormat("en", { minute: "numeric", dateStyle: "long" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option minute cannot be set when also providing dateStyle or timeStyle");
TypeError,
"Option minute cannot be set when also providing dateStyle or timeStyle"
);
}); });
test("second option is invalid", () => { test("second option is invalid", () => {
@ -169,10 +142,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.DateTimeFormat("en", { second: "numeric", dateStyle: "long" }); new Intl.DateTimeFormat("en", { second: "numeric", dateStyle: "long" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option second cannot be set when also providing dateStyle or timeStyle");
TypeError,
"Option second cannot be set when also providing dateStyle or timeStyle"
);
}); });
test("fractionalSecondDigits option is invalid", () => { test("fractionalSecondDigits option is invalid", () => {
@ -366,13 +336,11 @@ describe("normal behavior", () => {
}); });
test("all valid timeZoneName options", () => { test("all valid timeZoneName options", () => {
["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"].forEach( ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"].forEach(timeZoneName => {
timeZoneName => { expect(() => {
expect(() => { new Intl.DateTimeFormat("en", { timeZoneName: timeZoneName });
new Intl.DateTimeFormat("en", { timeZoneName: timeZoneName }); }).not.toThrow();
}).not.toThrow(); });
}
);
}); });
test("all valid formatMatcher options", () => { test("all valid formatMatcher options", () => {

View File

@ -58,9 +58,7 @@ describe("errors", () => {
); );
expect(() => { expect(() => {
formatter.format( formatter.format(new Temporal.PlainDateTime(1972, 1, 1, 8, 45, 56, 123, 345, 789, "gregory"));
new Temporal.PlainDateTime(1972, 1, 1, 8, 45, 56, 123, 345, 789, "gregory")
);
}).toThrowWithMessage( }).toThrowWithMessage(
RangeError, RangeError,
"Cannot format Temporal.PlainDateTime with calendar 'gregory' in locale with calendar 'iso8601'" "Cannot format Temporal.PlainDateTime with calendar 'gregory' in locale with calendar 'iso8601'"

View File

@ -65,18 +65,7 @@ describe("errors", () => {
); );
expect(() => { expect(() => {
const plainDateTime = new Temporal.PlainDateTime( const plainDateTime = new Temporal.PlainDateTime(1972, 1, 1, 8, 45, 56, 123, 345, 789, "gregory");
1972,
1,
1,
8,
45,
56,
123,
345,
789,
"gregory"
);
formatter.formatRange(plainDateTime, plainDateTime); formatter.formatRange(plainDateTime, plainDateTime);
}).toThrowWithMessage( }).toThrowWithMessage(
RangeError, RangeError,
@ -98,19 +87,13 @@ describe("errors", () => {
expect(() => { expect(() => {
const plainDate = new Temporal.PlainDate(1972, 1, 1, "gregory"); const plainDate = new Temporal.PlainDate(1972, 1, 1, "gregory");
new Intl.DateTimeFormat().formatRange(plainDate, 0); new Intl.DateTimeFormat().formatRange(plainDate, 0);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Cannot format a date-time range with different date-time types");
TypeError,
"Cannot format a date-time range with different date-time types"
);
expect(() => { expect(() => {
const plainYearMonth = new Temporal.PlainYearMonth(1972, 1, "gregory"); const plainYearMonth = new Temporal.PlainYearMonth(1972, 1, "gregory");
const plainMonthDay = new Temporal.PlainMonthDay(1, 1, "gregory"); const plainMonthDay = new Temporal.PlainMonthDay(1, 1, "gregory");
new Intl.DateTimeFormat().formatRange(plainYearMonth, plainMonthDay); new Intl.DateTimeFormat().formatRange(plainYearMonth, plainMonthDay);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Cannot format a date-time range with different date-time types");
TypeError,
"Cannot format a date-time range with different date-time types"
);
}); });
test("Temporal fields must overlap formatter", () => { test("Temporal fields must overlap formatter", () => {
@ -346,8 +329,6 @@ describe("Temporal objects", () => {
test("Temporal.Instant", () => { test("Temporal.Instant", () => {
const instant1 = new Temporal.Instant(601546251000000000n); const instant1 = new Temporal.Instant(601546251000000000n);
const instant2 = new Temporal.Instant(1732740069000000000n); const instant2 = new Temporal.Instant(1732740069000000000n);
expect(formatter.formatRange(instant1, instant2)).toBe( expect(formatter.formatRange(instant1, instant2)).toBe("1989-01-23, 8:10:51 AM 2024-11-27, 8:41:09 PM");
"1989-01-23, 8:10:51 AM 2024-11-27, 8:41:09 PM"
);
}); });
}); });

View File

@ -65,18 +65,7 @@ describe("errors", () => {
); );
expect(() => { expect(() => {
const plainDateTime = new Temporal.PlainDateTime( const plainDateTime = new Temporal.PlainDateTime(1972, 1, 1, 8, 45, 56, 123, 345, 789, "gregory");
1972,
1,
1,
8,
45,
56,
123,
345,
789,
"gregory"
);
formatter.formatRangeToParts(plainDateTime, plainDateTime); formatter.formatRangeToParts(plainDateTime, plainDateTime);
}).toThrowWithMessage( }).toThrowWithMessage(
RangeError, RangeError,
@ -98,19 +87,13 @@ describe("errors", () => {
expect(() => { expect(() => {
const plainDate = new Temporal.PlainDate(1972, 1, 1, "gregory"); const plainDate = new Temporal.PlainDate(1972, 1, 1, "gregory");
new Intl.DateTimeFormat().formatRangeToParts(plainDate, 0); new Intl.DateTimeFormat().formatRangeToParts(plainDate, 0);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Cannot format a date-time range with different date-time types");
TypeError,
"Cannot format a date-time range with different date-time types"
);
expect(() => { expect(() => {
const plainYearMonth = new Temporal.PlainYearMonth(1972, 1, "gregory"); const plainYearMonth = new Temporal.PlainYearMonth(1972, 1, "gregory");
const plainMonthDay = new Temporal.PlainMonthDay(1, 1, "gregory"); const plainMonthDay = new Temporal.PlainMonthDay(1, 1, "gregory");
new Intl.DateTimeFormat().formatRangeToParts(plainYearMonth, plainMonthDay); new Intl.DateTimeFormat().formatRangeToParts(plainYearMonth, plainMonthDay);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Cannot format a date-time range with different date-time types");
TypeError,
"Cannot format a date-time range with different date-time types"
);
}); });
test("Temporal fields must overlap formatter", () => { test("Temporal fields must overlap formatter", () => {

View File

@ -54,9 +54,7 @@ describe("errors", () => {
); );
expect(() => { expect(() => {
formatter.formatToParts( formatter.formatToParts(new Temporal.PlainDateTime(1972, 1, 1, 8, 45, 56, 123, 345, 789, "gregory"));
new Temporal.PlainDateTime(1972, 1, 1, 8, 45, 56, 123, 345, 789, "gregory")
);
}).toThrowWithMessage( }).toThrowWithMessage(
RangeError, RangeError,
"Cannot format Temporal.PlainDateTime with calendar 'gregory' in locale with calendar 'iso8601'" "Cannot format Temporal.PlainDateTime with calendar 'gregory' in locale with calendar 'iso8601'"

View File

@ -232,11 +232,9 @@ describe("correct behavior", () => {
}); });
test("timeZoneName", () => { test("timeZoneName", () => {
["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"].forEach( ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"].forEach(timeZoneName => {
timeZoneName => { const en = new Intl.DateTimeFormat("en", { timeZoneName: timeZoneName });
const en = new Intl.DateTimeFormat("en", { timeZoneName: timeZoneName }); expect(en.resolvedOptions().timeZoneName).toBe(timeZoneName);
expect(en.resolvedOptions().timeZoneName).toBe(timeZoneName); });
}
);
}); });
}); });

View File

@ -21,9 +21,9 @@ describe("correct behavior", () => {
for (const [input, expected] of values) { for (const [input, expected] of values) {
expect(Intl.DateTimeFormat.supportedLocalesOf(input)).toEqual(expected); expect(Intl.DateTimeFormat.supportedLocalesOf(input)).toEqual(expected);
// "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment // "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment
expect( expect(Intl.DateTimeFormat.supportedLocalesOf(input, { localeMatcher: "best fit" })).toEqual(
Intl.DateTimeFormat.supportedLocalesOf(input, { localeMatcher: "best fit" }) Intl.DateTimeFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })
).toEqual(Intl.DateTimeFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })); );
} }
}); });
}); });

View File

@ -21,9 +21,9 @@ describe("correct behavior", () => {
for (const [input, expected] of values) { for (const [input, expected] of values) {
expect(Intl.DisplayNames.supportedLocalesOf(input)).toEqual(expected); expect(Intl.DisplayNames.supportedLocalesOf(input)).toEqual(expected);
// "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment // "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment
expect( expect(Intl.DisplayNames.supportedLocalesOf(input, { localeMatcher: "best fit" })).toEqual(
Intl.DisplayNames.supportedLocalesOf(input, { localeMatcher: "best fit" }) Intl.DisplayNames.supportedLocalesOf(input, { localeMatcher: "lookup" })
).toEqual(Intl.DisplayNames.supportedLocalesOf(input, { localeMatcher: "lookup" })); );
} }
}); });
}); });

View File

@ -2,10 +2,7 @@ describe("errors", () => {
test("called without new", () => { test("called without new", () => {
expect(() => { expect(() => {
Intl.DurationFormat(); Intl.DurationFormat();
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Intl.DurationFormat constructor must be called with 'new'");
TypeError,
"Intl.DurationFormat constructor must be called with 'new'"
);
}); });
test("structurally invalid tag", () => { test("structurally invalid tag", () => {
@ -137,10 +134,7 @@ describe("errors", () => {
test("millisecondsDisplay option is invalid", () => { test("millisecondsDisplay option is invalid", () => {
expect(() => { expect(() => {
new Intl.DurationFormat("en", { millisecondsDisplay: "hello!" }); new Intl.DurationFormat("en", { millisecondsDisplay: "hello!" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "hello! is not a valid value for option millisecondsDisplay");
RangeError,
"hello! is not a valid value for option millisecondsDisplay"
);
}); });
test("microseconds option is invalid", () => { test("microseconds option is invalid", () => {
@ -152,10 +146,7 @@ describe("errors", () => {
test("microsecondsDisplay option is invalid", () => { test("microsecondsDisplay option is invalid", () => {
expect(() => { expect(() => {
new Intl.DurationFormat("en", { microsecondsDisplay: "hello!" }); new Intl.DurationFormat("en", { microsecondsDisplay: "hello!" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "hello! is not a valid value for option microsecondsDisplay");
RangeError,
"hello! is not a valid value for option microsecondsDisplay"
);
}); });
test("nanoseconds option is invalid", () => { test("nanoseconds option is invalid", () => {
@ -167,10 +158,7 @@ describe("errors", () => {
test("nanosecondsDisplay option is invalid", () => { test("nanosecondsDisplay option is invalid", () => {
expect(() => { expect(() => {
new Intl.DurationFormat("en", { nanosecondsDisplay: "hello!" }); new Intl.DurationFormat("en", { nanosecondsDisplay: "hello!" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "hello! is not a valid value for option nanosecondsDisplay");
RangeError,
"hello! is not a valid value for option nanosecondsDisplay"
);
}); });
}); });

View File

@ -211,33 +211,31 @@ describe("correct behavior", () => {
{ type: "integer", value: "9", unit: "nanosecond" }, { type: "integer", value: "9", unit: "nanosecond" },
{ type: "unit", value: "ns", unit: "nanosecond" }, { type: "unit", value: "ns", unit: "nanosecond" },
]); ]);
expect(new Intl.DurationFormat("en", { style: "digital" }).formatToParts(duration)).toEqual( expect(new Intl.DurationFormat("en", { style: "digital" }).formatToParts(duration)).toEqual([
[ { type: "integer", value: "1", unit: "year" },
{ type: "integer", value: "1", unit: "year" }, { type: "literal", value: " ", unit: "year" },
{ type: "literal", value: " ", unit: "year" }, { type: "unit", value: "yr", unit: "year" },
{ type: "unit", value: "yr", unit: "year" }, { type: "literal", value: ", " },
{ type: "literal", value: ", " }, { type: "integer", value: "2", unit: "month" },
{ type: "integer", value: "2", unit: "month" }, { type: "literal", value: " ", unit: "month" },
{ type: "literal", value: " ", unit: "month" }, { type: "unit", value: "mths", unit: "month" },
{ type: "unit", value: "mths", unit: "month" }, { type: "literal", value: ", " },
{ type: "literal", value: ", " }, { type: "integer", value: "3", unit: "week" },
{ type: "integer", value: "3", unit: "week" }, { type: "literal", value: " ", unit: "week" },
{ type: "literal", value: " ", unit: "week" }, { type: "unit", value: "wks", unit: "week" },
{ type: "unit", value: "wks", unit: "week" }, { type: "literal", value: ", " },
{ type: "literal", value: ", " }, { type: "integer", value: "3", unit: "day" },
{ type: "integer", value: "3", unit: "day" }, { type: "literal", value: " ", unit: "day" },
{ type: "literal", value: " ", unit: "day" }, { type: "unit", value: "days", unit: "day" },
{ type: "unit", value: "days", unit: "day" }, { type: "literal", value: ", " },
{ type: "literal", value: ", " }, { type: "integer", value: "4", unit: "hour" },
{ type: "integer", value: "4", unit: "hour" }, { type: "literal", value: ":" },
{ type: "literal", value: ":" }, { type: "integer", value: "05", unit: "minute" },
{ type: "integer", value: "05", unit: "minute" }, { type: "literal", value: ":" },
{ type: "literal", value: ":" }, { type: "integer", value: "06", unit: "second" },
{ type: "integer", value: "06", unit: "second" }, { type: "decimal", value: ".", unit: "second" },
{ type: "decimal", value: ".", unit: "second" }, { type: "fraction", value: "007008009", unit: "second" },
{ type: "fraction", value: "007008009", unit: "second" }, ]);
]
);
expect( expect(
new Intl.DurationFormat("en", { new Intl.DurationFormat("en", {
style: "narrow", style: "narrow",
@ -398,33 +396,31 @@ describe("correct behavior", () => {
{ type: "literal", value: " ", unit: "nanosecond" }, { type: "literal", value: " ", unit: "nanosecond" },
{ type: "unit", value: "ns", unit: "nanosecond" }, { type: "unit", value: "ns", unit: "nanosecond" },
]); ]);
expect(new Intl.DurationFormat("de", { style: "digital" }).formatToParts(duration)).toEqual( expect(new Intl.DurationFormat("de", { style: "digital" }).formatToParts(duration)).toEqual([
[ { type: "integer", value: "1", unit: "year" },
{ type: "integer", value: "1", unit: "year" }, { type: "literal", value: " ", unit: "year" },
{ type: "literal", value: " ", unit: "year" }, { type: "unit", value: "J", unit: "year" },
{ type: "unit", value: "J", unit: "year" }, { type: "literal", value: ", " },
{ type: "literal", value: ", " }, { type: "integer", value: "2", unit: "month" },
{ type: "integer", value: "2", unit: "month" }, { type: "literal", value: " ", unit: "month" },
{ type: "literal", value: " ", unit: "month" }, { type: "unit", value: "Mon.", unit: "month" },
{ type: "unit", value: "Mon.", unit: "month" }, { type: "literal", value: ", " },
{ type: "literal", value: ", " }, { type: "integer", value: "3", unit: "week" },
{ type: "integer", value: "3", unit: "week" }, { type: "literal", value: " ", unit: "week" },
{ type: "literal", value: " ", unit: "week" }, { type: "unit", value: "Wo.", unit: "week" },
{ type: "unit", value: "Wo.", unit: "week" }, { type: "literal", value: ", " },
{ type: "literal", value: ", " }, { type: "integer", value: "3", unit: "day" },
{ type: "integer", value: "3", unit: "day" }, { type: "literal", value: " ", unit: "day" },
{ type: "literal", value: " ", unit: "day" }, { type: "unit", value: "Tg.", unit: "day" },
{ type: "unit", value: "Tg.", unit: "day" }, { type: "literal", value: " und " },
{ type: "literal", value: " und " }, { type: "integer", value: "4", unit: "hour" },
{ type: "integer", value: "4", unit: "hour" }, { type: "literal", value: ":" },
{ type: "literal", value: ":" }, { type: "integer", value: "05", unit: "minute" },
{ type: "integer", value: "05", unit: "minute" }, { type: "literal", value: ":" },
{ type: "literal", value: ":" }, { type: "integer", value: "06", unit: "second" },
{ type: "integer", value: "06", unit: "second" }, { type: "decimal", value: ",", unit: "second" },
{ type: "decimal", value: ",", unit: "second" }, { type: "fraction", value: "007008009", unit: "second" },
{ type: "fraction", value: "007008009", unit: "second" }, ]);
]
);
expect( expect(
new Intl.DurationFormat("de", { new Intl.DurationFormat("de", {
style: "narrow", style: "narrow",

View File

@ -21,9 +21,9 @@ describe("correct behavior", () => {
for (const [input, expected] of values) { for (const [input, expected] of values) {
expect(Intl.DurationFormat.supportedLocalesOf(input)).toEqual(expected); expect(Intl.DurationFormat.supportedLocalesOf(input)).toEqual(expected);
// "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment // "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment
expect( expect(Intl.DurationFormat.supportedLocalesOf(input, { localeMatcher: "best fit" })).toEqual(
Intl.DurationFormat.supportedLocalesOf(input, { localeMatcher: "best fit" }) Intl.DurationFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })
).toEqual(Intl.DurationFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })); );
} }
}); });
}); });

View File

@ -20,17 +20,11 @@ describe("errors", () => {
test("duplicate variant subtags", () => { test("duplicate variant subtags", () => {
expect(() => { expect(() => {
Intl.getCanonicalLocales("en-posix-POSIX"); Intl.getCanonicalLocales("en-posix-POSIX");
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "en-posix-POSIX is not a structurally valid language tag");
RangeError,
"en-posix-POSIX is not a structurally valid language tag"
);
expect(() => { expect(() => {
Intl.getCanonicalLocales("en-POSIX-POSIX"); Intl.getCanonicalLocales("en-POSIX-POSIX");
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "en-POSIX-POSIX is not a structurally valid language tag");
RangeError,
"en-POSIX-POSIX is not a structurally valid language tag"
);
}); });
test("improperly placed separator", () => { test("improperly placed separator", () => {
@ -70,10 +64,7 @@ describe("errors", () => {
test("duplicate transformed extension variant subtags", () => { test("duplicate transformed extension variant subtags", () => {
expect(() => { expect(() => {
Intl.getCanonicalLocales("en-t-en-POSIX-POSIX"); Intl.getCanonicalLocales("en-t-en-POSIX-POSIX");
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "en-t-en-POSIX-POSIX is not a structurally valid language tag");
RangeError,
"en-t-en-POSIX-POSIX is not a structurally valid language tag"
);
}); });
}); });
@ -111,9 +102,7 @@ describe("normal behavior", () => {
test("duplicate Unicode locale extension keywords", () => { test("duplicate Unicode locale extension keywords", () => {
expect(Intl.getCanonicalLocales("en-us-u-1k-aaa-1k-bbb")).toEqual(["en-US-u-1k-aaa"]); expect(Intl.getCanonicalLocales("en-us-u-1k-aaa-1k-bbb")).toEqual(["en-US-u-1k-aaa"]);
expect(Intl.getCanonicalLocales("en-us-u-1k-aaa-2k-ccc-1k-bbb")).toEqual([ expect(Intl.getCanonicalLocales("en-us-u-1k-aaa-2k-ccc-1k-bbb")).toEqual(["en-US-u-1k-aaa-2k-ccc"]);
"en-US-u-1k-aaa-2k-ccc",
]);
}); });
test("canonicalize locale objects", () => { test("canonicalize locale objects", () => {

View File

@ -21,9 +21,9 @@ describe("correct behavior", () => {
for (const [input, expected] of values) { for (const [input, expected] of values) {
expect(Intl.ListFormat.supportedLocalesOf(input)).toEqual(expected); expect(Intl.ListFormat.supportedLocalesOf(input)).toEqual(expected);
// "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment // "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment
expect( expect(Intl.ListFormat.supportedLocalesOf(input, { localeMatcher: "best fit" })).toEqual(
Intl.ListFormat.supportedLocalesOf(input, { localeMatcher: "best fit" }) Intl.ListFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })
).toEqual(Intl.ListFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })); );
} }
}); });
}); });

View File

@ -9,10 +9,7 @@ describe("errors", () => {
[123456789, "a", "longerthan8chars"].forEach(value => { [123456789, "a", "longerthan8chars"].forEach(value => {
expect(() => { expect(() => {
new Intl.Locale("en", { firstDayOfWeek: value }).firstDayOfWeek; new Intl.Locale("en", { firstDayOfWeek: value }).firstDayOfWeek;
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, `${value} is not a valid value for option firstDayOfWeek`);
RangeError,
`${value} is not a valid value for option firstDayOfWeek`
);
}); });
}); });
}); });
@ -27,20 +24,14 @@ describe("normal behavior", () => {
expect(new Intl.Locale("en", { firstDayOfWeek: day }).firstDayOfWeek).toBe(day); expect(new Intl.Locale("en", { firstDayOfWeek: day }).firstDayOfWeek).toBe(day);
expect(new Intl.Locale("en", { firstDayOfWeek: index }).firstDayOfWeek).toBe(day); expect(new Intl.Locale("en", { firstDayOfWeek: index }).firstDayOfWeek).toBe(day);
expect(new Intl.Locale("en-u-fw-mon", { firstDayOfWeek: day }).firstDayOfWeek).toBe( expect(new Intl.Locale("en-u-fw-mon", { firstDayOfWeek: day }).firstDayOfWeek).toBe(day);
day expect(new Intl.Locale("en-u-fw-mon", { firstDayOfWeek: index }).firstDayOfWeek).toBe(day);
);
expect(new Intl.Locale("en-u-fw-mon", { firstDayOfWeek: index }).firstDayOfWeek).toBe(
day
);
}); });
}); });
test("non-standard options", () => { test("non-standard options", () => {
[100, Infinity, NaN, "hello", 152n, true].forEach(value => { [100, Infinity, NaN, "hello", 152n, true].forEach(value => {
expect(new Intl.Locale("en", { firstDayOfWeek: value }).firstDayOfWeek).toBe( expect(new Intl.Locale("en", { firstDayOfWeek: value }).firstDayOfWeek).toBe(value.toString());
value.toString()
);
}); });
}); });
}); });

View File

@ -26,7 +26,5 @@ test("normal behavior", () => {
test("keywords are preserved", () => { test("keywords are preserved", () => {
expect(new Intl.Locale("en-u-ca-abc").maximize().toString()).toBe("en-Latn-US-u-ca-abc"); expect(new Intl.Locale("en-u-ca-abc").maximize().toString()).toBe("en-Latn-US-u-ca-abc");
expect(new Intl.Locale("en", { calendar: "abc" }).maximize().toString()).toBe( expect(new Intl.Locale("en", { calendar: "abc" }).maximize().toString()).toBe("en-Latn-US-u-ca-abc");
"en-Latn-US-u-ca-abc"
);
}); });

View File

@ -28,7 +28,5 @@ test("normal behavior", () => {
test("keywords are preserved", () => { test("keywords are preserved", () => {
expect(new Intl.Locale("en-Latn-US-u-ca-abc").minimize().toString()).toBe("en-u-ca-abc"); expect(new Intl.Locale("en-Latn-US-u-ca-abc").minimize().toString()).toBe("en-u-ca-abc");
expect(new Intl.Locale("en-Latn-US", { calendar: "abc" }).minimize().toString()).toBe( expect(new Intl.Locale("en-Latn-US", { calendar: "abc" }).minimize().toString()).toBe("en-u-ca-abc");
"en-u-ca-abc"
);
}); });

View File

@ -11,8 +11,6 @@ describe("normal behavior", () => {
expect(new Intl.Locale("en").numberingSystem).toBeUndefined(); expect(new Intl.Locale("en").numberingSystem).toBeUndefined();
expect(new Intl.Locale("en-u-nu-abc").numberingSystem).toBe("abc"); expect(new Intl.Locale("en-u-nu-abc").numberingSystem).toBe("abc");
expect(new Intl.Locale("en", { numberingSystem: "abc" }).numberingSystem).toBe("abc"); expect(new Intl.Locale("en", { numberingSystem: "abc" }).numberingSystem).toBe("abc");
expect(new Intl.Locale("en-u-nu-abc", { numberingSystem: "def" }).numberingSystem).toBe( expect(new Intl.Locale("en-u-nu-abc", { numberingSystem: "def" }).numberingSystem).toBe("def");
"def"
);
}); });
}); });

View File

@ -8,10 +8,7 @@ describe("errors", () => {
test("duplicate variants", () => { test("duplicate variants", () => {
expect(() => { expect(() => {
new Intl.Locale("en-abcde-abcde"); new Intl.Locale("en-abcde-abcde");
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "en-abcde-abcde is not a structurally valid language tag");
RangeError,
"en-abcde-abcde is not a structurally valid language tag"
);
expect(() => { expect(() => {
new Intl.Locale("en", { variants: "abcde-abcde" }); new Intl.Locale("en", { variants: "abcde-abcde" });

View File

@ -44,10 +44,7 @@ describe("errors", () => {
test("currency option is undefined when required ", () => { test("currency option is undefined when required ", () => {
expect(() => { expect(() => {
new Intl.NumberFormat("en", { style: "currency" }); new Intl.NumberFormat("en", { style: "currency" });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Option currency must be defined when option style is currency");
TypeError,
"Option currency must be defined when option style is currency"
);
}); });
test("currency option is invalid ", () => { test("currency option is invalid ", () => {
@ -85,10 +82,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.NumberFormat("en", { unit: "acre-per-bit-per-byte" }); new Intl.NumberFormat("en", { unit: "acre-per-bit-per-byte" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "acre-per-bit-per-byte is not a valid value for option unit");
RangeError,
"acre-per-bit-per-byte is not a valid value for option unit"
);
}); });
test("unitDisplay option is invalid ", () => { test("unitDisplay option is invalid ", () => {
@ -218,10 +212,7 @@ describe("errors", () => {
test("roundingPriority option is invalid", () => { test("roundingPriority option is invalid", () => {
expect(() => { expect(() => {
new Intl.NumberFormat("en", { roundingPriority: "hello!" }); new Intl.NumberFormat("en", { roundingPriority: "hello!" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "hello! is not a valid value for option roundingPriority");
RangeError,
"hello! is not a valid value for option roundingPriority"
);
}); });
test("roundingMode option is invalid", () => { test("roundingMode option is invalid", () => {
@ -249,10 +240,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.NumberFormat("en", { roundingIncrement: 5, minimumSignificantDigits: 1 }); new Intl.NumberFormat("en", { roundingIncrement: 5, minimumSignificantDigits: 1 });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "5 is not a valid rounding increment for rounding type significantDigits");
TypeError,
"5 is not a valid rounding increment for rounding type significantDigits"
);
expect(() => { expect(() => {
new Intl.NumberFormat("en", { new Intl.NumberFormat("en", {
@ -260,19 +248,13 @@ describe("errors", () => {
minimumFractionDigits: 2, minimumFractionDigits: 2,
maximumFractionDigits: 3, maximumFractionDigits: 3,
}); });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "5 is not a valid rounding increment for inequal min/max fraction digits");
RangeError,
"5 is not a valid rounding increment for inequal min/max fraction digits"
);
}); });
test("trailingZeroDisplay option is invalid", () => { test("trailingZeroDisplay option is invalid", () => {
expect(() => { expect(() => {
new Intl.NumberFormat("en", { trailingZeroDisplay: "hello!" }); new Intl.NumberFormat("en", { trailingZeroDisplay: "hello!" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "hello! is not a valid value for option trailingZeroDisplay");
RangeError,
"hello! is not a valid value for option trailingZeroDisplay"
);
}); });
}); });
@ -434,33 +416,23 @@ describe("normal behavior", () => {
}); });
test("all valid roundingMode options", () => { test("all valid roundingMode options", () => {
[ ["ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven"].forEach(
"ceil", roundingMode => {
"floor",
"expand",
"trunc",
"halfCeil",
"halfFloor",
"halfExpand",
"halfTrunc",
"halfEven",
].forEach(roundingMode => {
expect(() => {
new Intl.NumberFormat("en", { roundingMode: roundingMode });
}).not.toThrow();
});
});
test("all valid roundingIncrement options", () => {
[1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach(
roundingIncrement => {
expect(() => { expect(() => {
new Intl.NumberFormat("en", { roundingIncrement: roundingIncrement }); new Intl.NumberFormat("en", { roundingMode: roundingMode });
}).not.toThrow(); }).not.toThrow();
} }
); );
}); });
test("all valid roundingIncrement options", () => {
[1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach(roundingIncrement => {
expect(() => {
new Intl.NumberFormat("en", { roundingIncrement: roundingIncrement });
}).not.toThrow();
});
});
test("all valid trailingZeroDisplay options", () => { test("all valid trailingZeroDisplay options", () => {
["auto", "stripIfInteger"].forEach(trailingZeroDisplay => { ["auto", "stripIfInteger"].forEach(trailingZeroDisplay => {
expect(() => { expect(() => {

View File

@ -82,21 +82,11 @@ describe("style=decimal", () => {
expect(en.format(12.3456)).toBe("12.3456"); expect(en.format(12.3456)).toBe("12.3456");
expect(en.format(12.34567)).toBe("12.3457"); expect(en.format(12.34567)).toBe("12.3457");
expect(en.format(12.34561)).toBe("12.3456"); expect(en.format(12.34561)).toBe("12.3456");
expect(en.format(0.00000000000000000000000000000123)).toBe( expect(en.format(0.00000000000000000000000000000123)).toBe("0.000000000000000000000000000001230");
"0.000000000000000000000000000001230" expect(en.format(-0.00000000000000000000000000000123)).toBe("-0.000000000000000000000000000001230");
); expect(en.format(12344501000000000000000000000000000)).toBe("12,344,500,000,000,000,000,000,000,000,000,000");
expect(en.format(-0.00000000000000000000000000000123)).toBe( expect(en.format(-12344501000000000000000000000000000)).toBe("-12,344,500,000,000,000,000,000,000,000,000,000");
"-0.000000000000000000000000000001230" expect(en.format(12344501000000000000000000000000000n)).toBe("12,344,500,000,000,000,000,000,000,000,000,000");
);
expect(en.format(12344501000000000000000000000000000)).toBe(
"12,344,500,000,000,000,000,000,000,000,000,000"
);
expect(en.format(-12344501000000000000000000000000000)).toBe(
"-12,344,500,000,000,000,000,000,000,000,000,000"
);
expect(en.format(12344501000000000000000000000000000n)).toBe(
"12,344,500,000,000,000,000,000,000,000,000,000"
);
expect(en.format(-12344501000000000000000000000000000n)).toBe( expect(en.format(-12344501000000000000000000000000000n)).toBe(
"-12,344,500,000,000,000,000,000,000,000,000,000" "-12,344,500,000,000,000,000,000,000,000,000,000"
); );
@ -211,9 +201,7 @@ describe("style=decimal", () => {
expect(ar.format(123)).toBe("\u0661\u0662\u0663\u0623\u0633\u0660"); expect(ar.format(123)).toBe("\u0661\u0662\u0663\u0623\u0633\u0660");
expect(ar.format(1234)).toBe("\u0661\u066b\u0662\u0663\u0664\u0623\u0633\u0663"); expect(ar.format(1234)).toBe("\u0661\u066b\u0662\u0663\u0664\u0623\u0633\u0663");
expect(ar.format(12345)).toBe("\u0661\u0662\u066b\u0663\u0664\u0665\u0623\u0633\u0663"); expect(ar.format(12345)).toBe("\u0661\u0662\u066b\u0663\u0664\u0665\u0623\u0633\u0663");
expect(ar.format(123456)).toBe( expect(ar.format(123456)).toBe("\u0661\u0662\u0663\u066b\u0664\u0665\u0666\u0623\u0633\u0663");
"\u0661\u0662\u0663\u066b\u0664\u0665\u0666\u0623\u0633\u0663"
);
expect(ar.format(1234567)).toBe("\u0661\u066b\u0662\u0663\u0665\u0623\u0633\u0666"); expect(ar.format(1234567)).toBe("\u0661\u066b\u0662\u0663\u0665\u0623\u0633\u0666");
expect(ar.format(0.1)).toBe("\u0661\u0660\u0660\u0623\u0633\u061c-\u0663"); expect(ar.format(0.1)).toBe("\u0661\u0660\u0660\u0623\u0633\u061c-\u0663");
expect(ar.format(0.12)).toBe("\u0661\u0662\u0660\u0623\u0633\u061c-\u0663"); expect(ar.format(0.12)).toBe("\u0661\u0662\u0660\u0623\u0633\u061c-\u0663");
@ -563,16 +551,10 @@ describe("style=decimal", () => {
expect(nf("en", undefined, 2, undefined, 2).format(1.23)).toBe("1.2"); expect(nf("en", undefined, 2, undefined, 2).format(1.23)).toBe("1.2");
expect(nf("en", undefined, 3, undefined, 1).format(1.23)).toBe("1.2"); expect(nf("en", undefined, 3, undefined, 1).format(1.23)).toBe("1.2");
expect(nf("ar-u-nu-arab", 2, undefined, 2, undefined).format(1)).toBe( expect(nf("ar-u-nu-arab", 2, undefined, 2, undefined).format(1)).toBe("\u0661\u066b\u0660\u0660");
"\u0661\u066b\u0660\u0660"
);
expect(nf("ar-u-nu-arab", 3, undefined, 1, undefined).format(1)).toBe("\u0661\u066b\u0660"); expect(nf("ar-u-nu-arab", 3, undefined, 1, undefined).format(1)).toBe("\u0661\u066b\u0660");
expect(nf("ar-u-nu-arab", undefined, 2, undefined, 2).format(1.23)).toBe( expect(nf("ar-u-nu-arab", undefined, 2, undefined, 2).format(1.23)).toBe("\u0661\u066b\u0662");
"\u0661\u066b\u0662" expect(nf("ar-u-nu-arab", undefined, 3, undefined, 1).format(1.23)).toBe("\u0661\u066b\u0662");
);
expect(nf("ar-u-nu-arab", undefined, 3, undefined, 1).format(1.23)).toBe(
"\u0661\u066b\u0662"
);
}); });
test("roundingPriority=morePrecision", () => { test("roundingPriority=morePrecision", () => {
@ -592,15 +574,9 @@ describe("style=decimal", () => {
expect(nf("en", undefined, 3, undefined, 1).format(1.23)).toBe("1.23"); expect(nf("en", undefined, 3, undefined, 1).format(1.23)).toBe("1.23");
expect(nf("ar-u-nu-arab", 2, undefined, 2, undefined).format(1)).toBe("\u0661\u066b\u0660"); expect(nf("ar-u-nu-arab", 2, undefined, 2, undefined).format(1)).toBe("\u0661\u066b\u0660");
expect(nf("ar-u-nu-arab", 3, undefined, 1, undefined).format(1)).toBe( expect(nf("ar-u-nu-arab", 3, undefined, 1, undefined).format(1)).toBe("\u0661\u066b\u0660\u0660");
"\u0661\u066b\u0660\u0660" expect(nf("ar-u-nu-arab", undefined, 2, undefined, 2).format(1.23)).toBe("\u0661\u066b\u0662\u0663");
); expect(nf("ar-u-nu-arab", undefined, 3, undefined, 1).format(1.23)).toBe("\u0661\u066b\u0662\u0663");
expect(nf("ar-u-nu-arab", undefined, 2, undefined, 2).format(1.23)).toBe(
"\u0661\u066b\u0662\u0663"
);
expect(nf("ar-u-nu-arab", undefined, 3, undefined, 1).format(1.23)).toBe(
"\u0661\u066b\u0662\u0663"
);
}); });
test("roundingMode=ceil", () => { test("roundingMode=ceil", () => {

View File

@ -301,9 +301,7 @@ describe("style=decimal", () => {
expect(enIn.formatToParts(1234567)).toEqual([{ type: "integer", value: "1234567" }]); expect(enIn.formatToParts(1234567)).toEqual([{ type: "integer", value: "1234567" }]);
const ar = new Intl.NumberFormat("ar-u-nu-arab", { useGrouping: false }); const ar = new Intl.NumberFormat("ar-u-nu-arab", { useGrouping: false });
expect(ar.formatToParts(123456)).toEqual([ expect(ar.formatToParts(123456)).toEqual([{ type: "integer", value: "\u0661\u0662\u0663\u0664\u0665\u0666" }]);
{ type: "integer", value: "\u0661\u0662\u0663\u0664\u0665\u0666" },
]);
expect(ar.formatToParts(1234567)).toEqual([ expect(ar.formatToParts(1234567)).toEqual([
{ type: "integer", value: "\u0661\u0662\u0663\u0664\u0665\u0666\u0667" }, { type: "integer", value: "\u0661\u0662\u0663\u0664\u0665\u0666\u0667" },
]); ]);
@ -1623,9 +1621,7 @@ describe("bigint", () => {
expect(en.formatToParts(123456n)).toEqual([{ type: "integer", value: "123456" }]); expect(en.formatToParts(123456n)).toEqual([{ type: "integer", value: "123456" }]);
const ar = new Intl.NumberFormat("ar-u-nu-arab", { useGrouping: false }); const ar = new Intl.NumberFormat("ar-u-nu-arab", { useGrouping: false });
expect(ar.formatToParts(123456n)).toEqual([ expect(ar.formatToParts(123456n)).toEqual([{ type: "integer", value: "\u0661\u0662\u0663\u0664\u0665\u0666" }]);
{ type: "integer", value: "\u0661\u0662\u0663\u0664\u0665\u0666" },
]);
}); });
test("significant digits", () => { test("significant digits", () => {

View File

@ -346,32 +346,22 @@ describe("correct behavior", () => {
const en1 = new Intl.NumberFormat("en"); const en1 = new Intl.NumberFormat("en");
expect(en1.resolvedOptions().roundingMode).toBe("halfExpand"); expect(en1.resolvedOptions().roundingMode).toBe("halfExpand");
[ ["ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven"].forEach(
"ceil", roundingMode => {
"floor", const en2 = new Intl.NumberFormat("en", { roundingMode: roundingMode });
"expand", expect(en2.resolvedOptions().roundingMode).toBe(roundingMode);
"trunc", }
"halfCeil", );
"halfFloor",
"halfExpand",
"halfTrunc",
"halfEven",
].forEach(roundingMode => {
const en2 = new Intl.NumberFormat("en", { roundingMode: roundingMode });
expect(en2.resolvedOptions().roundingMode).toBe(roundingMode);
});
}); });
test("rounding increment", () => { test("rounding increment", () => {
const en1 = new Intl.NumberFormat("en"); const en1 = new Intl.NumberFormat("en");
expect(en1.resolvedOptions().roundingIncrement).toBe(1); expect(en1.resolvedOptions().roundingIncrement).toBe(1);
[1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach( [1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach(roundingIncrement => {
roundingIncrement => { const en2 = new Intl.NumberFormat("en", { roundingIncrement: roundingIncrement });
const en2 = new Intl.NumberFormat("en", { roundingIncrement: roundingIncrement }); expect(en2.resolvedOptions().roundingIncrement).toBe(roundingIncrement);
expect(en2.resolvedOptions().roundingIncrement).toBe(roundingIncrement); });
}
);
}); });
test("trailing zero display", () => { test("trailing zero display", () => {

View File

@ -21,9 +21,9 @@ describe("correct behavior", () => {
for (const [input, expected] of values) { for (const [input, expected] of values) {
expect(Intl.NumberFormat.supportedLocalesOf(input)).toEqual(expected); expect(Intl.NumberFormat.supportedLocalesOf(input)).toEqual(expected);
// "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment // "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment
expect( expect(Intl.NumberFormat.supportedLocalesOf(input, { localeMatcher: "best fit" })).toEqual(
Intl.NumberFormat.supportedLocalesOf(input, { localeMatcher: "best fit" }) Intl.NumberFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })
).toEqual(Intl.NumberFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })); );
} }
}); });
}); });

View File

@ -126,10 +126,7 @@ describe("errors", () => {
test("roundingPriority option is invalid", () => { test("roundingPriority option is invalid", () => {
expect(() => { expect(() => {
new Intl.PluralRules("en", { roundingPriority: "hello!" }); new Intl.PluralRules("en", { roundingPriority: "hello!" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "hello! is not a valid value for option roundingPriority");
RangeError,
"hello! is not a valid value for option roundingPriority"
);
}); });
test("roundingMode option is invalid", () => { test("roundingMode option is invalid", () => {
@ -157,10 +154,7 @@ describe("errors", () => {
expect(() => { expect(() => {
new Intl.PluralRules("en", { roundingIncrement: 5, minimumSignificantDigits: 1 }); new Intl.PluralRules("en", { roundingIncrement: 5, minimumSignificantDigits: 1 });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "5 is not a valid rounding increment for rounding type significantDigits");
TypeError,
"5 is not a valid rounding increment for rounding type significantDigits"
);
expect(() => { expect(() => {
new Intl.PluralRules("en", { new Intl.PluralRules("en", {
@ -168,19 +162,13 @@ describe("errors", () => {
minimumFractionDigits: 2, minimumFractionDigits: 2,
maximumFractionDigits: 3, maximumFractionDigits: 3,
}); });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "5 is not a valid rounding increment for inequal min/max fraction digits");
RangeError,
"5 is not a valid rounding increment for inequal min/max fraction digits"
);
}); });
test("trailingZeroDisplay option is invalid", () => { test("trailingZeroDisplay option is invalid", () => {
expect(() => { expect(() => {
new Intl.PluralRules("en", { trailingZeroDisplay: "hello!" }); new Intl.PluralRules("en", { trailingZeroDisplay: "hello!" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "hello! is not a valid value for option trailingZeroDisplay");
RangeError,
"hello! is not a valid value for option trailingZeroDisplay"
);
}); });
}); });
@ -262,33 +250,23 @@ describe("normal behavior", () => {
}); });
test("all valid roundingMode options", () => { test("all valid roundingMode options", () => {
[ ["ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven"].forEach(
"ceil", roundingMode => {
"floor",
"expand",
"trunc",
"halfCeil",
"halfFloor",
"halfExpand",
"halfTrunc",
"halfEven",
].forEach(roundingMode => {
expect(() => {
new Intl.PluralRules("en", { roundingMode: roundingMode });
}).not.toThrow();
});
});
test("all valid roundingIncrement options", () => {
[1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach(
roundingIncrement => {
expect(() => { expect(() => {
new Intl.PluralRules("en", { roundingIncrement: roundingIncrement }); new Intl.PluralRules("en", { roundingMode: roundingMode });
}).not.toThrow(); }).not.toThrow();
} }
); );
}); });
test("all valid roundingIncrement options", () => {
[1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach(roundingIncrement => {
expect(() => {
new Intl.PluralRules("en", { roundingIncrement: roundingIncrement });
}).not.toThrow();
});
});
test("all valid trailingZeroDisplay options", () => { test("all valid trailingZeroDisplay options", () => {
["auto", "stripIfInteger"].forEach(trailingZeroDisplay => { ["auto", "stripIfInteger"].forEach(trailingZeroDisplay => {
expect(() => { expect(() => {

View File

@ -116,32 +116,22 @@ describe("correct behavior", () => {
const en1 = new Intl.PluralRules("en"); const en1 = new Intl.PluralRules("en");
expect(en1.resolvedOptions().roundingMode).toBe("halfExpand"); expect(en1.resolvedOptions().roundingMode).toBe("halfExpand");
[ ["ceil", "floor", "expand", "trunc", "halfCeil", "halfFloor", "halfExpand", "halfTrunc", "halfEven"].forEach(
"ceil", roundingMode => {
"floor", const en2 = new Intl.PluralRules("en", { roundingMode: roundingMode });
"expand", expect(en2.resolvedOptions().roundingMode).toBe(roundingMode);
"trunc", }
"halfCeil", );
"halfFloor",
"halfExpand",
"halfTrunc",
"halfEven",
].forEach(roundingMode => {
const en2 = new Intl.PluralRules("en", { roundingMode: roundingMode });
expect(en2.resolvedOptions().roundingMode).toBe(roundingMode);
});
}); });
test("rounding increment", () => { test("rounding increment", () => {
const en1 = new Intl.PluralRules("en"); const en1 = new Intl.PluralRules("en");
expect(en1.resolvedOptions().roundingIncrement).toBe(1); expect(en1.resolvedOptions().roundingIncrement).toBe(1);
[1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach( [1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach(roundingIncrement => {
roundingIncrement => { const en2 = new Intl.PluralRules("en", { roundingIncrement: roundingIncrement });
const en2 = new Intl.PluralRules("en", { roundingIncrement: roundingIncrement }); expect(en2.resolvedOptions().roundingIncrement).toBe(roundingIncrement);
expect(en2.resolvedOptions().roundingIncrement).toBe(roundingIncrement); });
}
);
}); });
test("trailing zero display", () => { test("trailing zero display", () => {

View File

@ -21,9 +21,9 @@ describe("correct behavior", () => {
for (const [input, expected] of values) { for (const [input, expected] of values) {
expect(Intl.PluralRules.supportedLocalesOf(input)).toEqual(expected); expect(Intl.PluralRules.supportedLocalesOf(input)).toEqual(expected);
// "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment // "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment
expect( expect(Intl.PluralRules.supportedLocalesOf(input, { localeMatcher: "best fit" })).toEqual(
Intl.PluralRules.supportedLocalesOf(input, { localeMatcher: "best fit" }) Intl.PluralRules.supportedLocalesOf(input, { localeMatcher: "lookup" })
).toEqual(Intl.PluralRules.supportedLocalesOf(input, { localeMatcher: "lookup" })); );
} }
}); });
}); });

View File

@ -2,10 +2,7 @@ describe("errors", () => {
test("called without new", () => { test("called without new", () => {
expect(() => { expect(() => {
Intl.RelativeTimeFormat(); Intl.RelativeTimeFormat();
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Intl.RelativeTimeFormat constructor must be called with 'new'");
TypeError,
"Intl.RelativeTimeFormat constructor must be called with 'new'"
);
}); });
test("structurally invalid tag", () => { test("structurally invalid tag", () => {

View File

@ -61,9 +61,7 @@ describe("correct behavior", () => {
{ type: "literal", value: " seconds" }, { type: "literal", value: " seconds" },
]); ]);
expect(ar.formatToParts(-1, "second")).toEqual([ expect(ar.formatToParts(-1, "second")).toEqual([{ type: "literal", value: "قبل ثانية واحدة" }]);
{ type: "literal", value: "قبل ثانية واحدة" },
]);
}); });
test("minute", () => { test("minute", () => {
@ -73,9 +71,7 @@ describe("correct behavior", () => {
{ type: "literal", value: " minutes" }, { type: "literal", value: " minutes" },
]); ]);
expect(ar.formatToParts(-1, "minute")).toEqual([ expect(ar.formatToParts(-1, "minute")).toEqual([{ type: "literal", value: "قبل دقيقة واحدة" }]);
{ type: "literal", value: "قبل دقيقة واحدة" },
]);
}); });
test("hour", () => { test("hour", () => {
@ -85,9 +81,7 @@ describe("correct behavior", () => {
{ type: "literal", value: " hours" }, { type: "literal", value: " hours" },
]); ]);
expect(ar.formatToParts(-1, "hour")).toEqual([ expect(ar.formatToParts(-1, "hour")).toEqual([{ type: "literal", value: "قبل ساعة واحدة" }]);
{ type: "literal", value: "قبل ساعة واحدة" },
]);
}); });
test("day", () => { test("day", () => {
@ -107,9 +101,7 @@ describe("correct behavior", () => {
{ type: "literal", value: " weeks" }, { type: "literal", value: " weeks" },
]); ]);
expect(ar.formatToParts(-1, "week")).toEqual([ expect(ar.formatToParts(-1, "week")).toEqual([{ type: "literal", value: "الأسبوع الماضي" }]);
{ type: "literal", value: "الأسبوع الماضي" },
]);
}); });
test("month", () => { test("month", () => {
@ -129,9 +121,7 @@ describe("correct behavior", () => {
{ type: "literal", value: " quarters" }, { type: "literal", value: " quarters" },
]); ]);
expect(ar.formatToParts(-1, "quarter")).toEqual([ expect(ar.formatToParts(-1, "quarter")).toEqual([{ type: "literal", value: "الربع الأخير" }]);
{ type: "literal", value: "الربع الأخير" },
]);
}); });
test("year", () => { test("year", () => {

View File

@ -21,9 +21,7 @@ describe("correct behavior", () => {
for (const [input, expected] of values) { for (const [input, expected] of values) {
expect(Intl.RelativeTimeFormat.supportedLocalesOf(input)).toEqual(expected); expect(Intl.RelativeTimeFormat.supportedLocalesOf(input)).toEqual(expected);
// "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment // "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment
expect( expect(Intl.RelativeTimeFormat.supportedLocalesOf(input, { localeMatcher: "best fit" })).toEqual(
Intl.RelativeTimeFormat.supportedLocalesOf(input, { localeMatcher: "best fit" })
).toEqual(
Intl.RelativeTimeFormat.supportedLocalesOf(input, { localeMatcher: "lookup" }) Intl.RelativeTimeFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })
); );
} }

View File

@ -12,10 +12,7 @@ describe("errors", () => {
test("cannot set the built-in Iterator's toStringTag", () => { test("cannot set the built-in Iterator's toStringTag", () => {
expect(() => { expect(() => {
Iterator.prototype[Symbol.toStringTag] = sentinel; Iterator.prototype[Symbol.toStringTag] = sentinel;
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Cannot write to non-writable property '[object IteratorPrototype]'");
TypeError,
"Cannot write to non-writable property '[object IteratorPrototype]'"
);
}); });
}); });

View File

@ -12,10 +12,7 @@ describe("errors", () => {
test("cannot set the built-in Iterator's constructor", () => { test("cannot set the built-in Iterator's constructor", () => {
expect(() => { expect(() => {
Iterator.prototype.constructor = sentinel; Iterator.prototype.constructor = sentinel;
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Cannot write to non-writable property '[object IteratorPrototype]'");
TypeError,
"Cannot write to non-writable property '[object IteratorPrototype]'"
);
}); });
}); });

View File

@ -1,9 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`; let string = `{"var1":10,"var2":"hello","var3":{"nested":5}}`;
let object = JSON.parse(string, (key, value) => let object = JSON.parse(string, (key, value) => (typeof value === "number" ? value * 2 : value));
typeof value === "number" ? value * 2 : value
);
expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } }); expect(object).toEqual({ var1: 20, var2: "hello", var3: { nested: 10 } });
object = JSON.parse(string, (key, value) => (typeof value === "number" ? undefined : value)); object = JSON.parse(string, (key, value) => (typeof value === "number" ? undefined : value));

View File

@ -17,19 +17,12 @@ test("JSON.rawJSON basic functionality", () => {
expect(JSON.stringify({ 42: JSON.rawJSON(37) })).toBe('{"42":37}'); expect(JSON.stringify({ 42: JSON.rawJSON(37) })).toBe('{"42":37}');
expect(JSON.stringify({ x: JSON.rawJSON(1), y: JSON.rawJSON(2) })).toBe('{"x":1,"y":2}'); expect(JSON.stringify({ x: JSON.rawJSON(1), y: JSON.rawJSON(2) })).toBe('{"x":1,"y":2}');
expect(JSON.stringify({ x: { x: JSON.rawJSON(1), y: JSON.rawJSON(2) } })).toBe( expect(JSON.stringify({ x: { x: JSON.rawJSON(1), y: JSON.rawJSON(2) } })).toBe('{"x":{"x":1,"y":2}}');
'{"x":{"x":1,"y":2}}'
);
expect(JSON.stringify([JSON.rawJSON(1), JSON.rawJSON(1.1)])).toBe("[1,1.1]"); expect(JSON.stringify([JSON.rawJSON(1), JSON.rawJSON(1.1)])).toBe("[1,1.1]");
expect( expect(JSON.stringify([JSON.rawJSON('"1"'), JSON.rawJSON(true), JSON.rawJSON(null), JSON.rawJSON(false)])).toBe(
JSON.stringify([ '["1",true,null,false]'
JSON.rawJSON('"1"'), );
JSON.rawJSON(true),
JSON.rawJSON(null),
JSON.rawJSON(false),
])
).toBe('["1",true,null,false]');
expect(JSON.stringify([{ x: JSON.rawJSON(1), y: JSON.rawJSON(1) }])).toBe('[{"x":1,"y":1}]'); expect(JSON.stringify([{ x: JSON.rawJSON(1), y: JSON.rawJSON(1) }])).toBe('[{"x":1,"y":1}]');
}); });

View File

@ -24,7 +24,5 @@ test("basic functionality", () => {
o.key1 = "key1"; o.key1 = "key1";
expect(JSON.stringify(o)).toBe( expect(JSON.stringify(o)).toBe('{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}');
'{"0":0,"1":1,"2":2,"key2":"key2","defined":"defined","key4":"key4","key1":"key1"}'
);
}); });

View File

@ -26,9 +26,7 @@ test("basic functionality", () => {
return value; return value;
}); });
expect(string).toBe( expect(string).toBe('{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}');
'{"var1":"foo","var2":42,"arr":[1,2,{"nested":{},"x":20}],"obj":{"subarr":[3,4,5]}}'
);
string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]); string = JSON.stringify(o, ["var1", "var1", "var2", "obj"]);
expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}'); expect(string).toBe('{"var1":"foo","var2":42,"obj":{}}');

View File

@ -8,89 +8,72 @@ test("basic functionality", () => {
expect(Math.sumPrecise([0.1])).toBe(0.1); expect(Math.sumPrecise([0.1])).toBe(0.1);
expect(Math.sumPrecise([0.1, 0.1])).toBe(0.2); expect(Math.sumPrecise([0.1, 0.1])).toBe(0.2);
expect(Math.sumPrecise([0.1, -0.1])).toBe(0); expect(Math.sumPrecise([0.1, -0.1])).toBe(0);
expect(Math.sumPrecise([1e308, 1e308, 0.1, 0.1, 1e30, 0.1, -1e30, -1e308, -1e308])).toBe( expect(Math.sumPrecise([1e308, 1e308, 0.1, 0.1, 1e30, 0.1, -1e30, -1e308, -1e308])).toBe(0.30000000000000004);
0.30000000000000004
);
expect(Math.sumPrecise([1e30, 0.1, -1e30])).toBe(0.1); expect(Math.sumPrecise([1e30, 0.1, -1e30])).toBe(0.1);
expect( expect(Math.sumPrecise([8.98846567431158e307, 8.988465674311579e307, -1.7976931348623157e308])).toBe(
Math.sumPrecise([8.98846567431158e307, 8.988465674311579e307, -1.7976931348623157e308]) 9.9792015476736e291
).toBe(9.9792015476736e291); );
expect( expect(Math.sumPrecise([-5.630637621603525e255, 9.565271205476345e307, 2.9937604643020797e292])).toBe(
Math.sumPrecise([-5.630637621603525e255, 9.565271205476345e307, 2.9937604643020797e292]) 9.565271205476347e307
).toBe(9.565271205476347e307); );
expect( expect(
Math.sumPrecise([ Math.sumPrecise([
6.739986666787661e66, 2, -1.2689709186578243e-116, 1.7046015739467354e308, 6.739986666787661e66, 2, -1.2689709186578243e-116, 1.7046015739467354e308, -9.979201547673601e291,
-9.979201547673601e291, 6.160926733208294e307, -3.179557053031852e234, 6.160926733208294e307, -3.179557053031852e234, -7.027282978772846e307, -0.7500000000000001,
-7.027282978772846e307, -0.7500000000000001,
]) ])
).toBe(1.61796594939028e308); ).toBe(1.61796594939028e308);
expect( expect(
Math.sumPrecise([ Math.sumPrecise([
0.31150493246968836, -8.988465674311582e307, 1.8315037361673755e-270, 0.31150493246968836, -8.988465674311582e307, 1.8315037361673755e-270, -15.999999999999996,
-15.999999999999996, 2.9999999999999996, 7.345200721499384e164, -2.033582473639399, 2.9999999999999996, 7.345200721499384e164, -2.033582473639399, -8.98846567431158e307,
-8.98846567431158e307, -3.5737295155405993e292, 4.13894772383715e-124, -3.5737295155405993e292, 4.13894772383715e-124, -3.6111186457260667e-35, 2.387234887098013e180,
-3.6111186457260667e-35, 2.387234887098013e180, 7.645295562778372e-298, 7.645295562778372e-298, 3.395189016861822e-103, -2.6331611115768973e-149,
3.395189016861822e-103, -2.6331611115768973e-149,
]) ])
).toBe(-Infinity); ).toBe(-Infinity);
expect( expect(
Math.sumPrecise([ Math.sumPrecise([
-1.1442589134409902e308, 9.593842098384855e138, 4.494232837155791e307, -1.1442589134409902e308, 9.593842098384855e138, 4.494232837155791e307, -1.3482698511467367e308,
-1.3482698511467367e308, 4.494232837155792e307, 4.494232837155792e307,
]) ])
).toBe(-1.5936821971565685e308); ).toBe(-1.5936821971565685e308);
expect( expect(
Math.sumPrecise([ Math.sumPrecise([
-1.1442589134409902e308, 4.494232837155791e307, -1.3482698511467367e308, -1.1442589134409902e308, 4.494232837155791e307, -1.3482698511467367e308, 4.494232837155792e307,
4.494232837155792e307,
]) ])
).toBe(-1.5936821971565687e308); ).toBe(-1.5936821971565687e308);
expect( expect(
Math.sumPrecise([ Math.sumPrecise([9.593842098384855e138, -6.948356297254111e307, -1.3482698511467367e308, 4.494232837155792e307])
9.593842098384855e138, -6.948356297254111e307, -1.3482698511467367e308,
4.494232837155792e307,
])
).toBe(-1.5936821971565685e308); ).toBe(-1.5936821971565685e308);
expect( expect(
Math.sumPrecise([-2.534858246857893e115, 8.988465674311579e307, 8.98846567431158e307]), Math.sumPrecise([-2.534858246857893e115, 8.988465674311579e307, 8.98846567431158e307]),
1.7976931348623157e308 1.7976931348623157e308
); );
expect(Math.sumPrecise([1.3588124894186193e308, 1.4803986201152006e223, 6.741349255733684e307])).toBe(Infinity);
expect(Math.sumPrecise([6.741349255733684e307, 1.7976931348623155e308, -7.388327292663961e41])).toBe(Infinity);
expect(Math.sumPrecise([-1.9807040628566093e28, 1.7976931348623157e308, 9.9792015476736e291])).toBe(
1.7976931348623157e308
);
expect( expect(
Math.sumPrecise([1.3588124894186193e308, 1.4803986201152006e223, 6.741349255733684e307]) Math.sumPrecise([-1.0214557991173964e61, 1.7976931348623157e308, 8.98846567431158e307, -8.988465674311579e307])
).toBe(Infinity);
expect(
Math.sumPrecise([6.741349255733684e307, 1.7976931348623155e308, -7.388327292663961e41])
).toBe(Infinity);
expect(
Math.sumPrecise([-1.9807040628566093e28, 1.7976931348623157e308, 9.9792015476736e291])
).toBe(1.7976931348623157e308); ).toBe(1.7976931348623157e308);
expect( expect(
Math.sumPrecise([ Math.sumPrecise([
-1.0214557991173964e61, 1.7976931348623157e308, 8.98846567431158e307, 1.7976931348623157e308, 7.999999999999999, -1.908963895403937e-230, 1.6445950082320264e292,
-8.988465674311579e307, 2.0734856707605806e205,
])
).toBe(1.7976931348623157e308);
expect(
Math.sumPrecise([
1.7976931348623157e308, 7.999999999999999, -1.908963895403937e-230,
1.6445950082320264e292, 2.0734856707605806e205,
]) ])
).toBe(Infinity); ).toBe(Infinity);
expect( expect(Math.sumPrecise([6.197409167220438e-223, -9.979201547673601e291, -1.7976931348623157e308])).toBe(-Infinity);
Math.sumPrecise([6.197409167220438e-223, -9.979201547673601e291, -1.7976931348623157e308])
).toBe(-Infinity);
expect( expect(
Math.sumPrecise([ Math.sumPrecise([
4.49423283715579e307, 8.944251746776101e307, -0.0002441406250000001, 4.49423283715579e307, 8.944251746776101e307, -0.0002441406250000001, 1.1752060710043817e308,
1.1752060710043817e308, 4.940846717201632e292, -1.6836699406454528e308, 4.940846717201632e292, -1.6836699406454528e308,
]) ])
).toBe(8.353845887521184e307); ).toBe(8.353845887521184e307);
expect( expect(
Math.sumPrecise([ Math.sumPrecise([
8.988465674311579e307, 7.999999999999998, 7.029158107234023e-308, 8.988465674311579e307, 7.999999999999998, 7.029158107234023e-308, -2.2303483759420562e-172,
-2.2303483759420562e-172, -1.7976931348623157e308, -8.98846567431158e307, -1.7976931348623157e308, -8.98846567431158e307,
]) ])
).toBe(-1.7976931348623157e308); ).toBe(-1.7976931348623157e308);
expect(Math.sumPrecise([8.98846567431158e307, 8.98846567431158e307])).toBe(Infinity); expect(Math.sumPrecise([8.98846567431158e307, 8.98846567431158e307])).toBe(Infinity);

View File

@ -37,9 +37,7 @@ describe("styles", () => {
test("percent", () => { test("percent", () => {
expect((0.234).toLocaleString("en", { style: "percent" })).toBe("23%"); expect((0.234).toLocaleString("en", { style: "percent" })).toBe("23%");
expect((0.234).toLocaleString("ar-u-nu-arab", { style: "percent" })).toBe( expect((0.234).toLocaleString("ar-u-nu-arab", { style: "percent" })).toBe("\u0662\u0663\u066a\u061c");
"\u0662\u0663\u066a\u061c"
);
}); });
test("currency", () => { test("currency", () => {

View File

@ -21,10 +21,7 @@ describe("errors", () => {
[-Infinity, 0, 101, Infinity].forEach(value => { [-Infinity, 0, 101, Infinity].forEach(value => {
expect(() => { expect(() => {
(0).toPrecision(value); (0).toPrecision(value);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Precision must be an integer no less than 1, and no greater than 100");
RangeError,
"Precision must be an integer no less than 1, and no greater than 100"
);
}); });
}); });
}); });

View File

@ -86,10 +86,7 @@ describe("correct behavior", () => {
3, 3,
"122200222200200002020000221212111212020212021222122122201112112001202200202210122011020121220102211210120110", "122200222200200002020000221212111212020212021222122122201112112001202200202210122011020121220102211210120110",
], ],
[ [4, "11323100002023111300233213100000000000000000000000000000000000000000000000000000000000"],
4,
"11323100002023111300233213100000000000000000000000000000000000000000000000000000000000",
],
[5, "20213333043100433442123113244334300004432332001224240433304410013422100304"], [5, "20213333043100433442123113244334300004432332001224240433304410013422100304"],
[6, "550003524220341511224004404200404220224024020444420402442220220420"], [6, "550003524220341511224004404200404220224024020444420402442220220420"],
[7, "4235625635040541506562064422461122351652161506062250163366335"], [7, "4235625635040541506562064422461122351652161506062250163366335"],

View File

@ -29,14 +29,11 @@ describe("normal behavior", () => {
test("merges objects", () => { test("merges objects", () => {
const s = Symbol(); const s = Symbol();
expect( expect(Object.assign({}, { foo: 0, bar: "baz" }, { [s]: [1, 2, 3] }, { foo: 1 }, { [42]: "test" })).toEqual({
Object.assign( foo: 1,
{}, bar: "baz",
{ foo: 0, bar: "baz" }, [s]: [1, 2, 3],
{ [s]: [1, 2, 3] }, 42: "test",
{ foo: 1 }, });
{ [42]: "test" }
)
).toEqual({ foo: 1, bar: "baz", [s]: [1, 2, 3], 42: "test" });
}); });
}); });

View File

@ -4,10 +4,7 @@ test("length is 2", () => {
describe("errors", () => { describe("errors", () => {
test("non-object prototype value", () => { test("non-object prototype value", () => {
expect(() => Object.create(42)).toThrowWithMessage( expect(() => Object.create(42)).toThrowWithMessage(TypeError, "Prototype must be an object or null");
TypeError,
"Prototype must be an object or null"
);
}); });
}); });

View File

@ -4,10 +4,7 @@ test("length is 2", () => {
describe("errors", () => { describe("errors", () => {
test("non-object argument", () => { test("non-object argument", () => {
expect(() => Object.defineProperties(42, {})).toThrowWithMessage( expect(() => Object.defineProperties(42, {})).toThrowWithMessage(TypeError, "Object argument is not an object");
TypeError,
"Object argument is not an object"
);
}); });
}); });

View File

@ -188,10 +188,7 @@ describe("errors", () => {
get() {}, get() {},
value: 9, value: 9,
}); });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key");
TypeError,
"Accessor property descriptor cannot specify a value or writable key"
);
}); });
test("cannot define 'value' and 'set' in the same descriptor", () => { test("cannot define 'value' and 'set' in the same descriptor", () => {
@ -202,10 +199,7 @@ describe("errors", () => {
set() {}, set() {},
writable: true, writable: true,
}); });
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Accessor property descriptor cannot specify a value or writable key");
TypeError,
"Accessor property descriptor cannot specify a value or writable key"
);
}); });
test("redefine non-configurable accessor", () => { test("redefine non-configurable accessor", () => {

View File

@ -1,8 +1,7 @@
test("basic functionality", () => { test("basic functionality", () => {
[Array, BigInt, Boolean, Date, Error, Function, Number, Object, String].forEach(constructor => { [Array, BigInt, Boolean, Date, Error, Function, Number, Object, String].forEach(constructor => {
expect(constructor.prototype.constructor).toBe(constructor); expect(constructor.prototype.constructor).toBe(constructor);
if (constructor !== BigInt) if (constructor !== BigInt) expect(Reflect.construct(constructor, []).constructor).toBe(constructor);
expect(Reflect.construct(constructor, []).constructor).toBe(constructor);
}); });
let o = {}; let o = {};

View File

@ -1,13 +1,8 @@
describe("[Call][GetOwnProperty]] trap normal behavior", () => { describe("[Call][GetOwnProperty]] trap normal behavior", () => {
test("forwarding when not defined in handler", () => { test("forwarding when not defined in handler", () => {
expect(Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: null }), "a")).toBeUndefined();
expect( expect(
Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: null }), "a") Object.getOwnPropertyDescriptor(new Proxy({}, { getOwnPropertyDescriptor: undefined }), "a")
).toBeUndefined();
expect(
Object.getOwnPropertyDescriptor(
new Proxy({}, { getOwnPropertyDescriptor: undefined }),
"a"
)
).toBeUndefined(); ).toBeUndefined();
expect(Object.getOwnPropertyDescriptor(new Proxy({}, {}), "a")).toBeUndefined(); expect(Object.getOwnPropertyDescriptor(new Proxy({}, {}), "a")).toBeUndefined();
}); });

View File

@ -7,33 +7,21 @@ test("constructs properly", () => {
test("constructor argument count", () => { test("constructor argument count", () => {
expect(() => { expect(() => {
new Proxy(); new Proxy();
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Expected target argument of Proxy constructor to be object, got undefined");
TypeError,
"Expected target argument of Proxy constructor to be object, got undefined"
);
expect(() => { expect(() => {
new Proxy({}); new Proxy({});
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Expected handler argument of Proxy constructor to be object, got undefined");
TypeError,
"Expected handler argument of Proxy constructor to be object, got undefined"
);
}); });
test("constructor requires objects", () => { test("constructor requires objects", () => {
expect(() => { expect(() => {
new Proxy(1, {}); new Proxy(1, {});
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Expected target argument of Proxy constructor to be object, got 1");
TypeError,
"Expected target argument of Proxy constructor to be object, got 1"
);
expect(() => { expect(() => {
new Proxy({}, 1); new Proxy({}, 1);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Expected handler argument of Proxy constructor to be object, got 1");
TypeError,
"Expected handler argument of Proxy constructor to be object, got 1"
);
}); });
test("constructor must be invoked with 'new'", () => { test("constructor must be invoked with 'new'", () => {

View File

@ -6,33 +6,21 @@ describe("errors", () => {
test("constructor argument count", () => { test("constructor argument count", () => {
expect(() => { expect(() => {
Proxy.revocable(); Proxy.revocable();
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Expected target argument of Proxy constructor to be object, got undefined");
TypeError,
"Expected target argument of Proxy constructor to be object, got undefined"
);
expect(() => { expect(() => {
Proxy.revocable({}); Proxy.revocable({});
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Expected handler argument of Proxy constructor to be object, got undefined");
TypeError,
"Expected handler argument of Proxy constructor to be object, got undefined"
);
}); });
test("constructor requires objects", () => { test("constructor requires objects", () => {
expect(() => { expect(() => {
Proxy.revocable(1, {}); Proxy.revocable(1, {});
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Expected target argument of Proxy constructor to be object, got 1");
TypeError,
"Expected target argument of Proxy constructor to be object, got 1"
);
expect(() => { expect(() => {
Proxy.revocable({}, 1); Proxy.revocable({}, 1);
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Expected handler argument of Proxy constructor to be object, got 1");
TypeError,
"Expected handler argument of Proxy constructor to be object, got 1"
);
}); });
}); });

View File

@ -23,9 +23,7 @@ describe("errors", () => {
describe("normal behavior", () => { describe("normal behavior", () => {
test("calling built-in functions", () => { test("calling built-in functions", () => {
expect(Reflect.apply(String.prototype.charAt, "foo", [0])).toBe("f"); expect(Reflect.apply(String.prototype.charAt, "foo", [0])).toBe("f");
expect(Reflect.apply(Array.prototype.indexOf, ["hello", 123, "foo", "bar"], ["foo"])).toBe( expect(Reflect.apply(Array.prototype.indexOf, ["hello", 123, "foo", "bar"], ["foo"])).toBe(2);
2
);
}); });
test("|this| argument is forwarded to called function", () => { test("|this| argument is forwarded to called function", () => {

View File

@ -45,9 +45,7 @@ describe("normal behavior", () => {
var o = {}; var o = {};
expect(o.foo).toBeUndefined(); expect(o.foo).toBeUndefined();
expect( expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: true })).toBeTrue();
Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: true })
).toBeTrue();
expect(o.foo).toBe(1); expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
expect(o.foo).toBe(2); expect(o.foo).toBe(2);
@ -57,9 +55,7 @@ describe("normal behavior", () => {
var o = {}; var o = {};
expect(o.foo).toBeUndefined(); expect(o.foo).toBeUndefined();
expect( expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: false })).toBeTrue();
Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: false })
).toBeTrue();
expect(o.foo).toBe(1); expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
expect(o.foo).toBe(2); expect(o.foo).toBe(2);
@ -69,9 +65,7 @@ describe("normal behavior", () => {
var o = {}; var o = {};
expect(o.foo).toBeUndefined(); expect(o.foo).toBeUndefined();
expect( expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: false, writable: false })).toBeTrue();
Reflect.defineProperty(o, "foo", { value: 1, configurable: false, writable: false })
).toBeTrue();
expect(o.foo).toBe(1); expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse(); expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse();
expect(o.foo).toBe(1); expect(o.foo).toBe(1);

View File

@ -2,10 +2,7 @@ describe("errors", () => {
test("invalid pattern", () => { test("invalid pattern", () => {
expect(() => { expect(() => {
RegExp("["); RegExp("[");
}).toThrowWithMessage( }).toThrowWithMessage(SyntaxError, "RegExp compile error: Error during parsing of regular expression:");
SyntaxError,
"RegExp compile error: Error during parsing of regular expression:"
);
}); });
test("invalid flag", () => { test("invalid flag", () => {
@ -116,26 +113,7 @@ test("Unicode properties of strings", () => {
}).not.toThrow(); }).not.toThrow();
} }
const matchStrings = [ const matchStrings = ["0", "1", "2", "3", "4", "5", "8", "A", "B", "D", "E", "F", "a", "b", "c", "d", "e", "f"];
"0",
"1",
"2",
"3",
"4",
"5",
"8",
"A",
"B",
"D",
"E",
"F",
"a",
"b",
"c",
"d",
"e",
"f",
];
const nonMatchStrings = [ const nonMatchStrings = [
"6\uFE0F\u20E3", "6\uFE0F\u20E3",

View File

@ -50,14 +50,10 @@ describe("normal behavior", () => {
expect(shadowRealm.evaluate("(function () {})")).toHaveLength(0); expect(shadowRealm.evaluate("(function () {})")).toHaveLength(0);
expect(shadowRealm.evaluate("(function (foo, bar) {})")).toHaveLength(2); expect(shadowRealm.evaluate("(function (foo, bar) {})")).toHaveLength(2);
expect( expect(
shadowRealm.evaluate( shadowRealm.evaluate("Object.defineProperty(function () {}, 'length', { get() { return -Infinity } })")
"Object.defineProperty(function () {}, 'length', { get() { return -Infinity } })"
)
).toHaveLength(0); ).toHaveLength(0);
expect( expect(
shadowRealm.evaluate( shadowRealm.evaluate("Object.defineProperty(function () {}, 'length', { get() { return Infinity } })")
"Object.defineProperty(function () {}, 'length', { get() { return Infinity } })"
)
).toHaveLength(Infinity); ).toHaveLength(Infinity);
for (const property of ["name", "length"]) { for (const property of ["name", "length"]) {
@ -70,18 +66,12 @@ describe("normal behavior", () => {
}); });
` `
); );
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Trying to copy target name and length did not complete normally");
TypeError,
"Trying to copy target name and length did not complete normally"
);
} }
expect(() => { expect(() => {
shadowRealm.evaluate("(function () { throw Error(); })")(); shadowRealm.evaluate("(function () { throw Error(); })")();
}).toThrowWithMessage( }).toThrowWithMessage(TypeError, "Call of wrapped target function did not complete normally");
TypeError,
"Call of wrapped target function did not complete normally"
);
}); });
}); });

View File

@ -16,22 +16,13 @@ test("basic functionality", () => {
test("errors", () => { test("errors", () => {
expect(() => { expect(() => {
String.fromCodePoint(NaN); String.fromCodePoint(NaN);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "must be an integer no less than 0 and no greater than 0x10FFFF");
RangeError,
"must be an integer no less than 0 and no greater than 0x10FFFF"
);
expect(() => { expect(() => {
String.fromCodePoint(-5); String.fromCodePoint(-5);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "must be an integer no less than 0 and no greater than 0x10FFFF");
RangeError,
"must be an integer no less than 0 and no greater than 0x10FFFF"
);
expect(() => { expect(() => {
String.fromCodePoint(0x123ffff); String.fromCodePoint(0x123ffff);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "must be an integer no less than 0 and no greater than 0x10FFFF");
RangeError,
"must be an integer no less than 0 and no greater than 0x10FFFF"
);
}); });

View File

@ -2,21 +2,7 @@ test("basic functionality", () => {
expect(String.prototype.split).toHaveLength(2); expect(String.prototype.split).toHaveLength(2);
expect("hello friends".split()).toEqual(["hello friends"]); expect("hello friends".split()).toEqual(["hello friends"]);
expect("hello friends".split("")).toEqual([ expect("hello friends".split("")).toEqual(["h", "e", "l", "l", "o", " ", "f", "r", "i", "e", "n", "d", "s"]);
"h",
"e",
"l",
"l",
"o",
" ",
"f",
"r",
"i",
"e",
"n",
"d",
"s",
]);
expect("hello friends".split(" ")).toEqual(["hello", "friends"]); expect("hello friends".split(" ")).toEqual(["hello", "friends"]);
expect("a,b,c,d".split(",")).toEqual(["a", "b", "c", "d"]); expect("a,b,c,d".split(",")).toEqual(["a", "b", "c", "d"]);

View File

@ -26,9 +26,7 @@ describe("normal behavior", () => {
expect(new SuppressedError().toString()).toBe("SuppressedError"); expect(new SuppressedError().toString()).toBe("SuppressedError");
expect(new SuppressedError(1).toString()).toBe("SuppressedError"); expect(new SuppressedError(1).toString()).toBe("SuppressedError");
expect(new SuppressedError(1, 1).toString()).toBe("SuppressedError"); expect(new SuppressedError(1, 1).toString()).toBe("SuppressedError");
expect(new SuppressedError(undefined, undefined, "Foo").toString()).toBe( expect(new SuppressedError(undefined, undefined, "Foo").toString()).toBe("SuppressedError: Foo");
"SuppressedError: Foo"
);
expect(new SuppressedError(1, 1, "Foo").toString()).toBe("SuppressedError: Foo"); expect(new SuppressedError(1, 1, "Foo").toString()).toBe("SuppressedError: Foo");
expect(Object.hasOwn(new SuppressedError(), "error")).toBeTrue(); expect(Object.hasOwn(new SuppressedError(), "error")).toBeTrue();
expect(Object.hasOwn(new SuppressedError(), "suppressed")).toBeTrue(); expect(Object.hasOwn(new SuppressedError(), "suppressed")).toBeTrue();
@ -39,10 +37,7 @@ describe("normal behavior", () => {
test("converts message to string", () => { test("converts message to string", () => {
expect(new SuppressedError(undefined, undefined, 1)).toHaveProperty("message", "1"); expect(new SuppressedError(undefined, undefined, 1)).toHaveProperty("message", "1");
expect(new SuppressedError(undefined, undefined, {})).toHaveProperty( expect(new SuppressedError(undefined, undefined, {})).toHaveProperty("message", "[object Object]");
"message",
"[object Object]"
);
}); });
test("supports options object with cause", () => { test("supports options object with cause", () => {

View File

@ -121,30 +121,21 @@ describe("errors", () => {
expect(() => { expect(() => {
Temporal.Duration.compare(duration1, duration2); Temporal.Duration.compare(duration1, duration2);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "A starting point is required for comparing calendar units");
RangeError,
"A starting point is required for comparing calendar units"
);
const duration3 = new Temporal.Duration(0, 3); const duration3 = new Temporal.Duration(0, 3);
const duration4 = new Temporal.Duration(0, 4); const duration4 = new Temporal.Duration(0, 4);
expect(() => { expect(() => {
Temporal.Duration.compare(duration3, duration4); Temporal.Duration.compare(duration3, duration4);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "A starting point is required for comparing calendar units");
RangeError,
"A starting point is required for comparing calendar units"
);
const duration5 = new Temporal.Duration(0, 0, 5); const duration5 = new Temporal.Duration(0, 0, 5);
const duration6 = new Temporal.Duration(0, 0, 6); const duration6 = new Temporal.Duration(0, 0, 6);
expect(() => { expect(() => {
Temporal.Duration.compare(duration5, duration6); Temporal.Duration.compare(duration5, duration6);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "A starting point is required for comparing calendar units");
RangeError,
"A starting point is required for comparing calendar units"
);
// Still throws if year/month/week of one the duration objects is non-zero. // Still throws if year/month/week of one the duration objects is non-zero.
const duration7 = new Temporal.Duration(0, 0, 0, 7); const duration7 = new Temporal.Duration(0, 0, 0, 7);
@ -152,20 +143,14 @@ describe("errors", () => {
expect(() => { expect(() => {
Temporal.Duration.compare(duration7, duration8); Temporal.Duration.compare(duration7, duration8);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "A starting point is required for comparing calendar units");
RangeError,
"A starting point is required for comparing calendar units"
);
const duration9 = new Temporal.Duration(0, 0, 9); const duration9 = new Temporal.Duration(0, 0, 9);
const duration10 = new Temporal.Duration(0, 0, 0, 10); const duration10 = new Temporal.Duration(0, 0, 0, 10);
expect(() => { expect(() => {
Temporal.Duration.compare(duration9, duration10); Temporal.Duration.compare(duration9, duration10);
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "A starting point is required for comparing calendar units");
RangeError,
"A starting point is required for comparing calendar units"
);
}); });
test("sub-minute time zone offset mismatch (unambiguous time zone transition)", () => { test("sub-minute time zone offset mismatch (unambiguous time zone transition)", () => {
@ -176,19 +161,13 @@ describe("errors", () => {
Temporal.Duration.compare(duration1, duration2, { Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1970-01-01T00:00:00-00:44:40[Africa/Monrovia]", relativeTo: "1970-01-01T00:00:00-00:44:40[Africa/Monrovia]",
}); });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Invalid offset for the provided date and time in the current time zone");
RangeError,
"Invalid offset for the provided date and time in the current time zone"
);
expect(() => { expect(() => {
Temporal.Duration.compare(duration1, duration2, { Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1970-01-01T00:00:00-00:45:00[Africa/Monrovia]", relativeTo: "1970-01-01T00:00:00-00:45:00[Africa/Monrovia]",
}); });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Invalid offset for the provided date and time in the current time zone");
RangeError,
"Invalid offset for the provided date and time in the current time zone"
);
}); });
test("sub-minute time zone offset mismatch (ambiguous time zone transition)", () => { test("sub-minute time zone offset mismatch (ambiguous time zone transition)", () => {
@ -199,9 +178,6 @@ describe("errors", () => {
Temporal.Duration.compare(duration1, duration2, { Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1952-10-15T23:59:59-11:19:50[Pacific/Niue]", relativeTo: "1952-10-15T23:59:59-11:19:50[Pacific/Niue]",
}); });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Invalid offset for the provided date and time in the current time zone");
RangeError,
"Invalid offset for the provided date and time in the current time zone"
);
}); });
}); });

View File

@ -17,9 +17,7 @@ describe("correct behavior", () => {
}); });
test("Duration instance argument", () => { test("Duration instance argument", () => {
const duration = Temporal.Duration.from( const duration = Temporal.Duration.from(new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
);
expectDurationOneToTen(duration); expectDurationOneToTen(duration);
}); });
@ -62,17 +60,11 @@ describe("errors", () => {
expect(() => { expect(() => {
Temporal.Duration.from({ years: "foo" }); Temporal.Duration.from({ years: "foo" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Invalid value for duration property 'years': must be an integer, got foo");
RangeError,
"Invalid value for duration property 'years': must be an integer, got foo"
);
expect(() => { expect(() => {
Temporal.Duration.from({ years: NaN }); Temporal.Duration.from({ years: NaN });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Invalid value for duration property 'years': must be an integer, got NaN");
RangeError,
"Invalid value for duration property 'years': must be an integer, got NaN"
);
}); });
test("invalid duration string", () => { test("invalid duration string", () => {

View File

@ -38,10 +38,7 @@ describe("correct behavior", () => {
["nanosecond", { nanoseconds: 1840300200300400 }], ["nanosecond", { nanoseconds: 1840300200300400 }],
["microsecond", { microseconds: 1840300200300, nanoseconds: 400 }], ["microsecond", { microseconds: 1840300200300, nanoseconds: 400 }],
["millisecond", { milliseconds: 1840300200, microseconds: 300, nanoseconds: 400 }], ["millisecond", { milliseconds: 1840300200, microseconds: 300, nanoseconds: 400 }],
[ ["second", { seconds: 1840300, milliseconds: 200, microseconds: 300, nanoseconds: 400 }],
"second",
{ seconds: 1840300, milliseconds: 200, microseconds: 300, nanoseconds: 400 },
],
[ [
"minute", "minute",
{ {
@ -143,20 +140,14 @@ describe("errors", () => {
const duration = new Temporal.Duration(1); const duration = new Temporal.Duration(1);
expect(() => { expect(() => {
duration.round({ smallestUnit: "second", roundingMode: "serenityOS" }); duration.round({ smallestUnit: "second", roundingMode: "serenityOS" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "serenityOS is not a valid value for option roundingMode");
RangeError,
"serenityOS is not a valid value for option roundingMode"
);
}); });
test("invalid smallest unit", () => { test("invalid smallest unit", () => {
const duration = new Temporal.Duration(1); const duration = new Temporal.Duration(1);
expect(() => { expect(() => {
duration.round({ smallestUnit: "serenityOS" }); duration.round({ smallestUnit: "serenityOS" });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "serenityOS is not a valid value for option smallestUnit");
RangeError,
"serenityOS is not a valid value for option smallestUnit"
);
}); });
test("increment may not be NaN", () => { test("increment may not be NaN", () => {
@ -176,10 +167,7 @@ describe("errors", () => {
}).toThrowWithMessage(RangeError, "0 is not a valid value for option roundingIncrement"); }).toThrowWithMessage(RangeError, "0 is not a valid value for option roundingIncrement");
expect(() => { expect(() => {
duration.round({ smallestUnit: "second", roundingIncrement: Infinity }); duration.round({ smallestUnit: "second", roundingIncrement: Infinity });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, "Infinity is not a valid value for option roundingIncrement");
RangeError,
"Infinity is not a valid value for option roundingIncrement"
);
}); });
test("must provide one or both of smallestUnit or largestUnit", () => { test("must provide one or both of smallestUnit or largestUnit", () => {

View File

@ -4,9 +4,7 @@ describe("correct behavior", () => {
}); });
test("basic functionality", () => { test("basic functionality", () => {
expect(new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).toJSON()).toBe( expect(new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).toJSON()).toBe("P1Y2M3W4DT5H6M7.00800901S");
"P1Y2M3W4DT5H6M7.00800901S"
);
}); });
}); });

View File

@ -25,10 +25,7 @@ describe("correct behavior", () => {
[[1, 2, 3, 4, 5, 6, 7, 8], "P1Y2M3W4DT5H6M7.008S"], [[1, 2, 3, 4, 5, 6, 7, 8], "P1Y2M3W4DT5H6M7.008S"],
[[1, 2, 3, 4, 5, 6, 7, 8, 9], "P1Y2M3W4DT5H6M7.008009S"], [[1, 2, 3, 4, 5, 6, 7, 8, 9], "P1Y2M3W4DT5H6M7.008009S"],
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "P1Y2M3W4DT5H6M7.00800901S"], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "P1Y2M3W4DT5H6M7.00800901S"],
[ [[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000], "P100Y200M300W400DT500H600M700.800901S"],
[100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],
"P100Y200M300W400DT500H600M700.800901S",
],
[[-1], "-P1Y"], [[-1], "-P1Y"],
]; ];
for (const [args, expected] of values) { for (const [args, expected] of values) {
@ -44,9 +41,7 @@ describe("correct behavior", () => {
["nanosecond", "P1Y2M3W4DT5H6M7.008010000S"], ["nanosecond", "P1Y2M3W4DT5H6M7.008010000S"],
]; ];
for (const [smallestUnit, expected] of values) { for (const [smallestUnit, expected] of values) {
expect( expect(new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 10).toString({ smallestUnit })).toBe(expected);
new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 10).toString({ smallestUnit })
).toBe(expected);
} }
}); });
@ -85,10 +80,7 @@ describe("errors", () => {
for (const smallestUnit of values) { for (const smallestUnit of values) {
expect(() => { expect(() => {
new Temporal.Duration(0).toString({ smallestUnit }); new Temporal.Duration(0).toString({ smallestUnit });
}).toThrowWithMessage( }).toThrowWithMessage(RangeError, `${smallestUnit} is not a valid value for option smallestUnit`);
RangeError,
`${smallestUnit} is not a valid value for option smallestUnit`
);
} }
}); });
}); });

View File

@ -9,14 +9,11 @@ describe("correct behavior", () => {
}); });
test("Instant string argument", () => { test("Instant string argument", () => {
expect(Temporal.Instant.from("1975-02-02T14:25:36.123456789Z").epochNanoseconds).toBe( expect(Temporal.Instant.from("1975-02-02T14:25:36.123456789Z").epochNanoseconds).toBe(160583136123456789n);
// Time zone is not validated
expect(Temporal.Instant.from("1975-02-02T14:25:36.123456789Z[Custom/TimeZone]").epochNanoseconds).toBe(
160583136123456789n 160583136123456789n
); );
// Time zone is not validated
expect(
Temporal.Instant.from("1975-02-02T14:25:36.123456789Z[Custom/TimeZone]")
.epochNanoseconds
).toBe(160583136123456789n);
// Accepts but ignores the calendar. // Accepts but ignores the calendar.
let result = null; let result = null;

View File

@ -6,21 +6,17 @@ describe("correct behavior", () => {
test("basic functionality", () => { test("basic functionality", () => {
expect(Temporal.Instant.fromEpochMilliseconds(0).epochMilliseconds).toBe(0); expect(Temporal.Instant.fromEpochMilliseconds(0).epochMilliseconds).toBe(0);
expect(Temporal.Instant.fromEpochMilliseconds(1).epochMilliseconds).toBe(1); expect(Temporal.Instant.fromEpochMilliseconds(1).epochMilliseconds).toBe(1);
expect(Temporal.Instant.fromEpochMilliseconds(999_999_999).epochMilliseconds).toBe( expect(Temporal.Instant.fromEpochMilliseconds(999_999_999).epochMilliseconds).toBe(999_999_999);
999_999_999 expect(Temporal.Instant.fromEpochMilliseconds(8_640_000_000_000_000).epochMilliseconds).toBe(
8_640_000_000_000_000
); );
expect(
Temporal.Instant.fromEpochMilliseconds(8_640_000_000_000_000).epochMilliseconds
).toBe(8_640_000_000_000_000);
expect(Temporal.Instant.fromEpochMilliseconds(-0).epochMilliseconds).toBe(0); expect(Temporal.Instant.fromEpochMilliseconds(-0).epochMilliseconds).toBe(0);
expect(Temporal.Instant.fromEpochMilliseconds(-1).epochMilliseconds).toBe(-1); expect(Temporal.Instant.fromEpochMilliseconds(-1).epochMilliseconds).toBe(-1);
expect(Temporal.Instant.fromEpochMilliseconds(-999_999_999).epochMilliseconds).toBe( expect(Temporal.Instant.fromEpochMilliseconds(-999_999_999).epochMilliseconds).toBe(-999_999_999);
-999_999_999 expect(Temporal.Instant.fromEpochMilliseconds(-8_640_000_000_000_000).epochMilliseconds).toBe(
-8_640_000_000_000_000
); );
expect(
Temporal.Instant.fromEpochMilliseconds(-8_640_000_000_000_000).epochMilliseconds
).toBe(-8_640_000_000_000_000);
}); });
}); });

View File

@ -6,21 +6,17 @@ describe("correct behavior", () => {
test("basic functionality", () => { test("basic functionality", () => {
expect(Temporal.Instant.fromEpochNanoseconds(0n).epochNanoseconds).toBe(0n); expect(Temporal.Instant.fromEpochNanoseconds(0n).epochNanoseconds).toBe(0n);
expect(Temporal.Instant.fromEpochNanoseconds(1n).epochNanoseconds).toBe(1n); expect(Temporal.Instant.fromEpochNanoseconds(1n).epochNanoseconds).toBe(1n);
expect(Temporal.Instant.fromEpochNanoseconds(999_999_999n).epochNanoseconds).toBe( expect(Temporal.Instant.fromEpochNanoseconds(999_999_999n).epochNanoseconds).toBe(999_999_999n);
999_999_999n expect(Temporal.Instant.fromEpochNanoseconds(8_640_000_000_000_000_000_000n).epochNanoseconds).toBe(
8_640_000_000_000_000_000_000n
); );
expect(
Temporal.Instant.fromEpochNanoseconds(8_640_000_000_000_000_000_000n).epochNanoseconds
).toBe(8_640_000_000_000_000_000_000n);
expect(Temporal.Instant.fromEpochNanoseconds(-0n).epochNanoseconds).toBe(0n); expect(Temporal.Instant.fromEpochNanoseconds(-0n).epochNanoseconds).toBe(0n);
expect(Temporal.Instant.fromEpochNanoseconds(-1n).epochNanoseconds).toBe(-1n); expect(Temporal.Instant.fromEpochNanoseconds(-1n).epochNanoseconds).toBe(-1n);
expect(Temporal.Instant.fromEpochNanoseconds(-999_999_999n).epochNanoseconds).toBe( expect(Temporal.Instant.fromEpochNanoseconds(-999_999_999n).epochNanoseconds).toBe(-999_999_999n);
-999_999_999n expect(Temporal.Instant.fromEpochNanoseconds(-8_640_000_000_000_000_000_000n).epochNanoseconds).toBe(
-8_640_000_000_000_000_000_000n
); );
expect(
Temporal.Instant.fromEpochNanoseconds(-8_640_000_000_000_000_000_000n).epochNanoseconds
).toBe(-8_640_000_000_000_000_000_000n);
}); });
}); });

Some files were not shown because too many files have changed in this diff Show More