-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_test.ts
40 lines (36 loc) · 1.18 KB
/
utils_test.ts
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
import { assertEquals, assertThrows, describe, it } from './dev_deps.ts'
import { parseUrl, toUint8Array } from './utils.ts'
describe('parseUrl', () => {
describe('should return the correct parsed URL', () => {
it('with protocol', () => {
const url = 'https://example.com/path'
const parsedUrl = parseUrl(url)
assertEquals(parsedUrl.protocol, 'https:')
assertEquals(parsedUrl.hostname, 'example.com')
})
it('with port', () => {
const url = 'http://example.com:8080/path'
const parsedUrl = parseUrl(url)
assertEquals(parsedUrl.port, 8080)
})
})
it('should throw error for invalid URL', () => {
const url = 'not a valid url'
assertThrows(() => {
parseUrl(url)
})
})
})
const te = new TextEncoder()
describe('toUint8Array', () => {
it('should convert a UTF-8 string to Uint8Array', () => {
const input = 'Hello, World!'
const uint8Array = toUint8Array(input)
assertEquals(uint8Array, te.encode(input))
})
it('should convert an ArrayBuffer to Uint8Array', () => {
const buffer = new ArrayBuffer(8)
const uint8Array = toUint8Array(buffer)
assertEquals(uint8Array, new Uint8Array(buffer))
})
})