Skip to content

Commit cbc2650

Browse files
committed
Add tests for date and number formatting functions
1 parent 55b060a commit cbc2650

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

extensions/ql-vscode/src/pure/number.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Contains an assortment of helper constants and functions for working with numbers.
33
*/
44

5-
const numberFormatter = new Intl.NumberFormat('en');
5+
const numberFormatter = new Intl.NumberFormat('en-US');
66

77
export function formatDecimal(value: number): string {
88
return numberFormatter.format(value);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect } from 'chai';
2+
import 'mocha';
3+
4+
import { formatDate } from '../../src/pure/date';
5+
6+
describe('Date', () => {
7+
it('should return a formatted date', () => {
8+
expect(formatDate(new Date(1663326904000))).to.eq('Sep 16, 1:15 PM');
9+
expect(formatDate(new Date(1631783704000))).to.eq('Sep 16, 2021, 11:15 AM');
10+
});
11+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect } from 'chai';
2+
import 'mocha';
3+
4+
import { formatDecimal } from '../../src/pure/number';
5+
6+
describe('Number', () => {
7+
it('should return a formatted decimal', () => {
8+
expect(formatDecimal(9)).to.eq('9');
9+
expect(formatDecimal(10_000)).to.eq('10,000');
10+
expect(formatDecimal(100_000_000_000)).to.eq('100,000,000,000');
11+
});
12+
});

extensions/ql-vscode/test/pure-tests/time.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import { humanizeRelativeTime, humanizeUnit } from '../../src/pure/time';
55

66
describe('Time', () => {
77
it('should return a humanized unit', () => {
8-
expect(humanizeUnit(undefined)).to.eq('Less than a minute');
9-
expect(humanizeUnit(0)).to.eq('Less than a minute');
10-
expect(humanizeUnit(-1)).to.eq('Less than a minute');
11-
expect(humanizeUnit(1000 * 60 - 1)).to.eq('Less than a minute');
8+
expect(humanizeUnit(undefined)).to.eq('Less than a second');
9+
expect(humanizeUnit(0)).to.eq('Less than a second');
10+
expect(humanizeUnit(-1)).to.eq('Less than a second');
11+
expect(humanizeUnit(1000 - 1)).to.eq('Less than a second');
12+
expect(humanizeUnit(1000)).to.eq('1 second');
13+
expect(humanizeUnit(1000 * 2)).to.eq('2 seconds');
14+
expect(humanizeUnit(1000 * 60 - 1)).to.eq('59 seconds');
1215
expect(humanizeUnit(1000 * 60)).to.eq('1 minute');
1316
expect(humanizeUnit(1000 * 60 * 2 - 1)).to.eq('1 minute');
1417
expect(humanizeUnit(1000 * 60 * 2)).to.eq('2 minutes');

0 commit comments

Comments
 (0)