Skip to content

Commit

Permalink
Add a bigint build test
Browse files Browse the repository at this point in the history
  • Loading branch information
tars0x9752 committed Jul 14, 2022
1 parent 1cf261e commit c2c017e
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"test": "npm run build && node --no-warnings --experimental-modules --experimental-specifier-resolution=node --icu-data-dir node_modules/full-icu --loader ./test/resolve.source.mjs ./test/all.mjs",
"test262": "TEST262=1 npm run build && ./test/test262.sh",
"testValidStrings": "npm run build && node --experimental-modules --experimental-specifier-resolution=node --no-warnings --icu-data-dir ./node_modules/full-icu/ --loader ./test/resolve.source.mjs test/validStrings.mjs",
"testBigInt": "npm run build && node test/bigintBuild.mjs",
"build": "rm -rf dist/* tsc-out/* && tsc && rollup -c rollup.config.js",
"prepare": "npm run build",
"prepublishOnly": "npm run build",
Expand Down
214 changes: 214 additions & 0 deletions test/bigintBuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
// Don't use test/resolve.source.mjs as a loader here.
// This file uses nodejs native "self-referencing a package using its name" feature and meant to import dist files instead of tsc-out.
// https://nodejs.org/api/packages.html#self-referencing-a-package-using-its-name

import Demitasse from '@pipobscure/demitasse';
const { describe, it, report } = Demitasse;

import Pretty from '@pipobscure/demitasse-pretty';
const { reporter } = Pretty;

import { strict as assert } from 'assert';
const { equal } = assert;

import { Temporal } from '@js-temporal/polyfill'; // with JSBI
import { Temporal as TemporalBigInt } from '@js-temporal/polyfill/bigint'; // without JSBI

describe('BigInt build and JSBI build', () => {
describe('Exports', () => {
const named = Object.keys(Temporal);
const namedBigInt = Object.keys(TemporalBigInt);
it('should be 11 things', () => {
equal(named.length, 11);
equal(namedBigInt.length, 11);
});
it('should contain `Instant`', () => {
assert(named.includes('Instant'));
assert(namedBigInt.includes('Instant'));
});
it('should contain `TimeZone`', () => {
assert(named.includes('TimeZone'));
assert(namedBigInt.includes('TimeZone'));
});
it('should contain `PlainDate`', () => {
assert(named.includes('PlainDate'));
assert(namedBigInt.includes('PlainDate'));
});
it('should contain `PlainTime`', () => {
assert(named.includes('PlainTime'));
assert(namedBigInt.includes('PlainTime'));
});
it('should contain `PlainDateTime`', () => {
assert(named.includes('PlainDateTime'));
assert(namedBigInt.includes('PlainDateTime'));
});
it('should contain `ZonedDateTime`', () => {
assert(named.includes('ZonedDateTime'));
assert(namedBigInt.includes('ZonedDateTime'));
});
it('should contain `PlainYearMonth`', () => {
assert(named.includes('PlainYearMonth'));
assert(namedBigInt.includes('PlainYearMonth'));
});
it('should contain `PlainMonthDay`', () => {
assert(named.includes('PlainMonthDay'));
assert(namedBigInt.includes('PlainMonthDay'));
});
it('should contain `Duration`', () => {
assert(named.includes('Duration'));
assert(namedBigInt.includes('Duration'));
});
it('should contain `Calendar`', () => {
assert(named.includes('Calendar'));
assert(namedBigInt.includes('Calendar'));
});
it('should contain `Now`', () => {
assert(named.includes('Now'));
assert(namedBigInt.includes('Now'));
});
});

describe('Construction', () => {
it('Instant', () => {
const { Instant } = Temporal;
const { Instant: InstantBigInt } = TemporalBigInt;

assert(Instant.from('1976-11-18T15:23:30.1Z') instanceof Instant);
assert(InstantBigInt.from('1976-11-18T15:23:30.1Z') instanceof InstantBigInt);
});

it('TimeZone', () => {
const { TimeZone } = Temporal;
const { TimeZone: TimeZoneBigInt } = TemporalBigInt;

assert(new TimeZone('Asia/Tokyo') instanceof TimeZone);
assert(new TimeZoneBigInt('Asia/Tokyo') instanceof TimeZoneBigInt);
});

it('PlainDate', () => {
const { PlainDate } = Temporal;
const { PlainDate: PlainDateBigInt } = TemporalBigInt;

assert(PlainDate.from('2019-11-18') instanceof PlainDate);
assert(PlainDateBigInt.from('2019-11-18') instanceof PlainDateBigInt);
});

it('PlainTime', () => {
const { PlainTime } = Temporal;
const { PlainDate: PlainTimeBigInt } = TemporalBigInt;

assert(PlainTime.from('1976-11-18T15:23:30') instanceof PlainTime);
assert(PlainTimeBigInt.from('1976-11-18T15:23:30') instanceof PlainTimeBigInt);
});

it('PlainDateTime', () => {
const { PlainDateTime } = Temporal;
const { PlainDateTime: PlainDateTimeBigInt } = TemporalBigInt;

assert(PlainDateTime.from('1976-11-18T15:23:30') instanceof PlainDateTime);
assert(PlainDateTimeBigInt.from('1976-11-18T15:23:30') instanceof PlainDateTimeBigInt);
});

it('PlainMonthDay', () => {
const { PlainMonthDay } = Temporal;
const { PlainMonthDay: PlainMonthDayBigInt } = TemporalBigInt;

assert(PlainMonthDay.from('1976-11-18T15:23:30') instanceof PlainMonthDay);
assert(PlainMonthDayBigInt.from('1976-11-18T15:23:30') instanceof PlainMonthDayBigInt);
});

it('PlainYearMonth', () => {
const { PlainYearMonth } = Temporal;
const { PlainYearMonth: PlainYearMonthBigInt } = TemporalBigInt;

assert(PlainYearMonth.from('1976-11-18T15:23:30') instanceof PlainYearMonth);
assert(PlainYearMonthBigInt.from('1976-11-18T15:23:30') instanceof PlainYearMonthBigInt);
});

it('ZonedDateTime', () => {
const { ZonedDateTime } = Temporal;
const { ZonedDateTime: ZonedDateTimeBigInt } = TemporalBigInt;

assert(new ZonedDateTime(1657807657736657736n, 'Asia/Tokyo') instanceof ZonedDateTime);
assert(new ZonedDateTimeBigInt(1657807657736657736n, 'Asia/Tokyo') instanceof ZonedDateTimeBigInt);
});

it('Duration', () => {
const { Duration } = Temporal;
const { Duration: DurationBigInt } = TemporalBigInt;

assert(new Duration(1, 1) instanceof Duration);
assert(new DurationBigInt(1, 1) instanceof DurationBigInt);
});

it('Calendar', () => {
const { Calendar } = Temporal;
const { Calendar: CalendarBigInt } = TemporalBigInt;

assert(new Calendar('japanese') instanceof Calendar);
assert(new CalendarBigInt('japanese') instanceof CalendarBigInt);
});
});

describe('Compat', () => {
it('add', () => {
const { PlainDate } = Temporal;
const { Duration: DurationBigInt } = TemporalBigInt;

const a = PlainDate.from('2022-01-01')
const duration = DurationBigInt.from({ years: 1 })

const res = a.add(duration)

equal(res.toString(), '2023-01-01');
});

it('subtract', () => {
const { PlainDate } = Temporal;
const { Duration: DurationBigInt } = TemporalBigInt;

const a = PlainDate.from('2022-01-01')
const duration = DurationBigInt.from({ years: 1 })

const res = a.subtract(duration)

equal(res.toString(), '2021-01-01');
});

it('since', () => {
const { PlainDate } = Temporal;
const { PlainDate: PlainDateBigInt } = TemporalBigInt;

const a = PlainDate.from('2022-01-01').withCalendar('iso8601')
const b = PlainDateBigInt.from('2022-01-01').withCalendar('iso8601')

const res = b.since(a)

equal(res, 'PT0S');
});

it('until', () => {
const { PlainDate } = Temporal;
const { PlainDate: PlainDateBigInt } = TemporalBigInt;

const a = PlainDate.from('2022-01-01').withCalendar('iso8601')
const b = PlainDateBigInt.from('2022-01-01').withCalendar('iso8601')

const res = b.until(a)

equal(res, 'PT0S');
});

it('equals', () => {
const { PlainDate } = Temporal;
const { PlainDate: PlainDateBigInt } = TemporalBigInt;

const a = PlainDate.from('2022-01-01').withCalendar('iso8601')
const b = PlainDateBigInt.from('2022-01-01').withCalendar('iso8601')

assert(b.equals(a));
});
})
});

report(reporter).then((failed) => process.exit(failed ? 1 : 0));

0 comments on commit c2c017e

Please sign in to comment.