-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4747878
commit 928f00d
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {Thyme} from '/mod.ts'; | ||
|
||
import {assert, assertEquals, assertStringIncludes} from 'std/testing/asserts.ts'; | ||
|
||
Deno.test('constructor consistency', () => { | ||
const margin = 1; // leave room for possible time differences. | ||
|
||
const date = new Date(); | ||
const thyme1 = new Thyme(); | ||
const thyme2 = new Thyme(date); | ||
const thyme3 = new Thyme(Date.now()); | ||
|
||
assert(Math.abs(+thyme1 - +thyme2) <= margin); | ||
assert(Math.abs(+thyme2 - +thyme3) <= margin); | ||
assert(Math.abs(+thyme1 - +thyme3) <= margin); | ||
}); | ||
|
||
Deno.test('formatSimple', () => { | ||
const moonLanding = new Thyme(Date.UTC(1969, 6, 20, 0, 20, 18)); | ||
assertEquals( | ||
moonLanding.formatSimple('YYYY-MM-DD @ hh:mm:ss.iii'), | ||
'1969-07-20 @ 00:20:18.000' | ||
); | ||
assertEquals( | ||
moonLanding.formatSimple('Y;M;D;h;m;s;i;E;C'), | ||
'69;7;20;0;20;18;0;CE;AD' | ||
); | ||
assertEquals(moonLanding.formatSimple(''), ''); | ||
assertEquals(moonLanding.formatSimple('CCCC'), 'AD '); | ||
for (const key of [...'YMDhmsiCE']) { | ||
// Repeating a key X times, must result in a string with length >= X. | ||
// We only need to check for equality here because 100 is very large. | ||
assertEquals(moonLanding.formatSimple(key.repeat(100)).length, 100); | ||
} | ||
}); | ||
|
||
Deno.test('custom inspect', () => { | ||
const test = 123456789; | ||
const thyme = new Thyme(test); | ||
assertStringIncludes(Deno.inspect(thyme), test.toString()); | ||
}); |