-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from andostronaut/develop
feat: move test inside mod_test
- Loading branch information
Showing
3 changed files
with
130 additions
and
124 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
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,129 @@ | ||
import { assert } from './deps.ts' | ||
import { | ||
generateFileName, | ||
getCurrentMonth, | ||
getTimestamp, | ||
humanizeDuration, | ||
isValidHttpUrl, | ||
} from './src/utils.ts' | ||
|
||
Deno.test('isValidHttpUrl should return true for valid HTTP URLs', () => { | ||
assert.assertEquals(isValidHttpUrl({ url: 'http://example.com' }), true) | ||
assert.assertEquals(isValidHttpUrl({ url: 'https://www.google.com' }), true) | ||
assert.assertEquals(isValidHttpUrl({ url: 'http://localhost:8080' }), true) | ||
}) | ||
|
||
Deno.test('isValidHttpUrl should return false for invalid URLs', () => { | ||
assert.assertEquals(isValidHttpUrl({ url: 'example.com' }), false) | ||
assert.assertEquals(isValidHttpUrl({ url: 'ftp://example.com' }), false) | ||
assert.assertEquals(isValidHttpUrl({ url: 'mailto:[email protected]' }), false) | ||
}) | ||
|
||
Deno.test('isValidHttpUrl should handle empty', () => { | ||
assert.assertEquals(isValidHttpUrl({ url: '' }), false) | ||
}) | ||
|
||
Deno.test( | ||
'getTimestamp should return "log" timestamp format for default type', | ||
() => { | ||
const timestamp = getTimestamp({ type: 'log' }) | ||
assert.assert(timestamp.match(/^\d{4}-\d{2}-\d{2}$/)) | ||
}, | ||
) | ||
|
||
Deno.test( | ||
'getTimestamp should return "pdf" timestamp format for type "pdf"', | ||
() => { | ||
const timestamp = getTimestamp({ type: 'pdf' }) | ||
assert.assert(timestamp.match(/^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}$/)) | ||
}, | ||
) | ||
|
||
Deno.test( | ||
'generateFileName should return correct filename for pdf type', | ||
() => { | ||
const timestamp = /^prefix_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\.pdf$/ | ||
assert.assert(generateFileName('prefix', 'pdf').match(timestamp)) | ||
}, | ||
) | ||
|
||
Deno.test('generateFileName should handle empty prefix', () => { | ||
const tm = getTimestamp({ type: 'log' }) | ||
assert.assertEquals(generateFileName('', 'log'), `_${tm}.log`) | ||
const timestamp = /^_\d{4}-\d{2}-\d{2}\.log$/ | ||
assert.assert(generateFileName('', 'log').match(timestamp)) | ||
}) | ||
|
||
Deno.test( | ||
'humanizeDuration should return correct duration string for 0 milliseconds', | ||
() => { | ||
assert.assertEquals(humanizeDuration(0), '0s') | ||
}, | ||
) | ||
|
||
Deno.test( | ||
'humanizeDuration should return correct duration string for less than a minute', | ||
() => { | ||
assert.assertEquals(humanizeDuration(5000), '5s') | ||
assert.assertEquals(humanizeDuration(59000), '59s') | ||
}, | ||
) | ||
|
||
Deno.test( | ||
'humanizeDuration should return correct duration string for minutes', | ||
() => { | ||
assert.assertEquals(humanizeDuration(60000), '1m') | ||
assert.assertEquals(humanizeDuration(120000), '2m') | ||
}, | ||
) | ||
|
||
Deno.test( | ||
'humanizeDuration should return correct duration string for hours', | ||
() => { | ||
assert.assertEquals(humanizeDuration(3600000), '1h') | ||
assert.assertEquals(humanizeDuration(7200000), '2h') | ||
}, | ||
) | ||
|
||
Deno.test( | ||
'humanizeDuration should return correct duration string for days', | ||
() => { | ||
assert.assertEquals(humanizeDuration(86400000), '1d') | ||
assert.assertEquals(humanizeDuration(172800000), '2d') | ||
}, | ||
) | ||
|
||
Deno.test( | ||
'humanizeDuration should return correct duration string for combined units', | ||
() => { | ||
assert.assertEquals(humanizeDuration(90000), '1m 30s') | ||
assert.assertEquals( | ||
humanizeDuration(7200000 + 120000), | ||
'2h 2m', | ||
) | ||
assert.assertEquals( | ||
humanizeDuration(172800000 + 7200000 + 120000), | ||
'2d 2h 2m', | ||
) | ||
}, | ||
) | ||
|
||
Deno.test( | ||
'getCurrentMonth should return correct month name for long type', | ||
() => { | ||
assert.assertEquals( | ||
getCurrentMonth({ type: 'long' }), | ||
new Date().toLocaleString('en-US', { month: 'long' }), | ||
) | ||
}, | ||
) | ||
|
||
Deno.test( | ||
'getCurrentMonth should return correct month abbreviation for short type', | ||
() => { | ||
assert.assertEquals( | ||
getCurrentMonth({ type: 'short' }), | ||
new Date().toLocaleString('en-US', { month: 'short' }), | ||
) | ||
}, | ||
) |
This file was deleted.
Oops, something went wrong.