Skip to content

Commit 6d6e530

Browse files
chore: test for time conversion edge case and fuzzy test numeral systems (#7384)
* chore: add test for time conversion edge case * add numeral systems to our fuzzy checker * lint --------- Co-authored-by: Reid Barber <[email protected]>
1 parent a006743 commit 6d6e530

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/@internationalized/date/tests/conversion.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ describe('CalendarDate conversion', function () {
140140
it('should convert a date from absolute in the BC era', function () {
141141
let date = fromAbsolute(new Date('0000-01-01T00:00:00.000Z').getTime(), 'UTC');
142142
expect(date).toEqual(new ZonedDateTime('BC', 1, 1, 1, 'UTC', 0, 0, 0, 0));
143+
date = fromAbsolute(new Date('0001-01-01T00:00:00.000Z').getTime(), 'UTC');
144+
expect(date).toEqual(new ZonedDateTime('AD', 1, 1, 1, 'UTC', 0, 0, 0, 0));
143145

144146
date = fromAbsolute(new Date('-000009-01-01T00:00:00.000Z').getTime(), 'UTC');
145147
expect(date).toEqual(new ZonedDateTime('BC', 10, 1, 1, 'UTC', 0, 0, 0, 0));

packages/@internationalized/number/test/NumberParser.test.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ describe('NumberParser', function () {
174174
});
175175

176176
describe('round trips', function () {
177+
fc.configureGlobal({numRuns: 200});
177178
// Locales have to include: 'de-DE', 'ar-EG', 'fr-FR' and possibly others
178179
// But for the moment they are not properly supported
179180
const localesArb = fc.constantFrom(...locales);
181+
const numeralArb = fc.constantFrom('latn', 'arab', 'hanidec', 'deva', 'beng');
180182
const styleOptsArb = fc.oneof(
181183
{withCrossShrink: true},
182184
fc.record({style: fc.constant('decimal')}),
@@ -210,35 +212,35 @@ describe('NumberParser', function () {
210212
fc.double({next: true, noNaN: true, min: DOUBLE_MIN, max: 1 / DOUBLE_MIN})
211213
).map(([sign, value]) => sign * value);
212214

213-
const inputsArb = fc.tuple(valueArb, localesArb, styleOptsArb, genericOptsArb)
214-
.map(([d, locale, styleOpts, genericOpts]) => ({d, opts: {...styleOpts, ...genericOpts}, locale}))
215+
const inputsArb = fc.tuple(valueArb, localesArb, styleOptsArb, genericOptsArb, numeralArb)
216+
.map(([d, locale, styleOpts, genericOpts, numerals]) => ({d, opts: {...styleOpts, ...genericOpts}, locale, numerals}))
215217
.filter(({opts}) => opts.minimumFractionDigits === undefined || opts.maximumFractionDigits === undefined || opts.minimumFractionDigits <= opts.maximumFractionDigits)
216218
.filter(({opts}) => opts.minimumSignificantDigits === undefined || opts.maximumSignificantDigits === undefined || opts.minimumSignificantDigits <= opts.maximumSignificantDigits)
217-
.map(({d, opts, locale}) => {
219+
.map(({d, opts, locale, numerals}) => {
218220
if (opts.style === 'percent') {
219221
opts.minimumFractionDigits = opts.minimumFractionDigits > 18 ? 18 : opts.minimumFractionDigits;
220222
opts.maximumFractionDigits = opts.maximumFractionDigits > 18 ? 18 : opts.maximumFractionDigits;
221223
}
222-
return {d, opts, locale};
224+
return {d, opts, locale, numerals};
223225
})
224-
.map(({d, opts, locale}) => {
226+
.map(({d, opts, locale, numerals}) => {
225227
let adjustedNumberForFractions = d;
226228
if (Math.abs(d) < 1 && opts.minimumFractionDigits && opts.minimumFractionDigits > 1) {
227229
adjustedNumberForFractions = d * (10 ** (opts.minimumFractionDigits || 2));
228230
} else if (Math.abs(d) > 1 && opts.minimumFractionDigits && opts.minimumFractionDigits > 1) {
229231
adjustedNumberForFractions = d / (10 ** (opts.minimumFractionDigits || 2));
230232
}
231-
return {adjustedNumberForFractions, opts, locale};
233+
return {adjustedNumberForFractions, opts, locale, numerals};
232234
});
233235

234236
// skipping until we can reliably run it, until then, it's good to run manually
235237
// track counter examples below
236-
it.skip('should fully reverse NumberFormat', function () {
238+
it('should fully reverse NumberFormat', function () {
237239
fc.assert(
238240
fc.property(
239241
inputsArb,
240-
function ({adjustedNumberForFractions, locale, opts}) {
241-
const formatter = new Intl.NumberFormat(locale, opts);
242+
function ({adjustedNumberForFractions, locale, opts, numerals}) {
243+
const formatter = new Intl.NumberFormat(`${locale}-u-nu-${numerals}`, opts);
242244
const parser = new NumberParser(locale, opts);
243245

244246
const formattedOnce = formatter.format(adjustedNumberForFractions);
@@ -264,7 +266,7 @@ describe('NumberParser', function () {
264266
expect(formatter.format(parser.parse(formattedOnce))).toBe(formattedOnce);
265267
});
266268
// See Bug https://github.com/nodejs/node/issues/49919
267-
it.skip('formatted units keep their number', () => {
269+
it('formatted units keep their number', () => {
268270
let locale = 'da-DK';
269271
let options = {
270272
style: 'unit',

0 commit comments

Comments
 (0)