-
Notifications
You must be signed in to change notification settings - Fork 632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(fmt): handle missing group separator for 1000.1 in some locales #6117
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6117 +/- ##
=======================================
Coverage 96.58% 96.59%
=======================================
Files 536 536
Lines 40679 40679
Branches 6110 6110
=======================================
+ Hits 39291 39292 +1
+ Misses 1344 1343 -1
Partials 44 44 ☔ View full report in Codecov by Sentry. |
This still won't make the tests fully locale independent — at a minimum, it'll fail for locales like There's currently only one test that uses import { format } from "./bytes.ts";
import { assertEquals } from "@std/assert";
import { stub } from "@std/testing/mock";
Deno.test("format() handles group separators", async (t) => {
const tests: { locale: string; expected: string }[] = [
{ locale: "en-US", expected: "1,000,000 YB" },
// narrow non-breaking space
{ locale: "fr-FR", expected: "1\u202f000\u202f000 YB" },
{ locale: "es-ES", expected: "1.000.000 YB" },
// https://en.wikipedia.org/wiki/Indian_numbering_system
{ locale: "hi-IN", expected: "10,00,000 YB" },
{ locale: "gu-IN", expected: "10,00,000 YB" },
];
for (const { locale, expected } of tests) {
await t.step(locale, () => {
const toLocaleString = Number.prototype.toLocaleString;
using _ = stub(
Number.prototype,
"toLocaleString",
function (l) {
return toLocaleString.call(this, l ?? locale);
},
);
// explicitly supplying the locale
assertEquals(format(1e30, { locale }), expected);
// using the default locale (mocked with stub)
assertEquals(format(1e30, { locale: true }), expected);
});
}
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
In some locales there is no group separator in parts which cause error during tests.
Change to 10000.1 fix this issue.