-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmod_test.ts
More file actions
121 lines (107 loc) · 3.27 KB
/
mod_test.ts
File metadata and controls
121 lines (107 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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:test@example.com' }), 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 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' }),
)
},
)