Add tests for date and number formatting functions
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Contains an assortment of helper constants and functions for working with numbers.
|
||||
*/
|
||||
|
||||
const numberFormatter = new Intl.NumberFormat('en');
|
||||
const numberFormatter = new Intl.NumberFormat('en-US');
|
||||
|
||||
export function formatDecimal(value: number): string {
|
||||
return numberFormatter.format(value);
|
||||
|
||||
11
extensions/ql-vscode/test/pure-tests/date.test.ts
Normal file
11
extensions/ql-vscode/test/pure-tests/date.test.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { expect } from 'chai';
|
||||
import 'mocha';
|
||||
|
||||
import { formatDate } from '../../src/pure/date';
|
||||
|
||||
describe('Date', () => {
|
||||
it('should return a formatted date', () => {
|
||||
expect(formatDate(new Date(1663326904000))).to.eq('Sep 16, 1:15 PM');
|
||||
expect(formatDate(new Date(1631783704000))).to.eq('Sep 16, 2021, 11:15 AM');
|
||||
});
|
||||
});
|
||||
12
extensions/ql-vscode/test/pure-tests/number.test.ts
Normal file
12
extensions/ql-vscode/test/pure-tests/number.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { expect } from 'chai';
|
||||
import 'mocha';
|
||||
|
||||
import { formatDecimal } from '../../src/pure/number';
|
||||
|
||||
describe('Number', () => {
|
||||
it('should return a formatted decimal', () => {
|
||||
expect(formatDecimal(9)).to.eq('9');
|
||||
expect(formatDecimal(10_000)).to.eq('10,000');
|
||||
expect(formatDecimal(100_000_000_000)).to.eq('100,000,000,000');
|
||||
});
|
||||
});
|
||||
@@ -5,10 +5,13 @@ import { humanizeRelativeTime, humanizeUnit } from '../../src/pure/time';
|
||||
|
||||
describe('Time', () => {
|
||||
it('should return a humanized unit', () => {
|
||||
expect(humanizeUnit(undefined)).to.eq('Less than a minute');
|
||||
expect(humanizeUnit(0)).to.eq('Less than a minute');
|
||||
expect(humanizeUnit(-1)).to.eq('Less than a minute');
|
||||
expect(humanizeUnit(1000 * 60 - 1)).to.eq('Less than a minute');
|
||||
expect(humanizeUnit(undefined)).to.eq('Less than a second');
|
||||
expect(humanizeUnit(0)).to.eq('Less than a second');
|
||||
expect(humanizeUnit(-1)).to.eq('Less than a second');
|
||||
expect(humanizeUnit(1000 - 1)).to.eq('Less than a second');
|
||||
expect(humanizeUnit(1000)).to.eq('1 second');
|
||||
expect(humanizeUnit(1000 * 2)).to.eq('2 seconds');
|
||||
expect(humanizeUnit(1000 * 60 - 1)).to.eq('59 seconds');
|
||||
expect(humanizeUnit(1000 * 60)).to.eq('1 minute');
|
||||
expect(humanizeUnit(1000 * 60 * 2 - 1)).to.eq('1 minute');
|
||||
expect(humanizeUnit(1000 * 60 * 2)).to.eq('2 minutes');
|
||||
|
||||
Reference in New Issue
Block a user