-
-
Notifications
You must be signed in to change notification settings - Fork 642
/
Copy pathhelpers.spec.ts
91 lines (74 loc) · 2.8 KB
/
helpers.spec.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
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
/*
* @adonisjs/core
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { test } from '@japa/runner'
import StringBuilder from '@poppinss/utils/string_builder'
import stringHelpers from '../src/helpers/string.js'
import { parseBindingReference } from '../src/helpers/main.js'
test.group('String helpers', () => {
test('check if string is empty', ({ assert }) => {
assert.isTrue(stringHelpers.isEmpty(''))
assert.isTrue(stringHelpers.isEmpty(' '))
})
test('escape html entities', ({ assert }) => {
assert.equal(stringHelpers.escapeHTML('<p> foo © bar </p>'), '<p> foo © bar </p>')
})
test('escape html entities and encode symbols', ({ assert }) => {
assert.equal(
stringHelpers.escapeHTML('<p> foo © bar </p>', { encodeSymbols: true }),
'<p> foo © bar </p>'
)
})
test('prettify hrtime', async ({ assert }) => {
const startTime = process.hrtime()
await new Promise((resolve) => setTimeout(resolve, 1200))
const endTime = process.hrtime(startTime)
assert.match(stringHelpers.prettyHrTime(endTime), /^\d(\.\d+)? s$/)
})
test('create string builder instance', async ({ assert }) => {
assert.instanceOf(stringHelpers.create('foo'), StringBuilder)
})
})
test.group('Parse binding reference', () => {
test('parse magic string value', async ({ assert }) => {
assert.deepEqual(await parseBindingReference('#controllers/home_controller'), {
moduleNameOrPath: '#controllers/home_controller',
method: 'handle',
})
assert.deepEqual(await parseBindingReference('#controllers/home_controller.index'), {
moduleNameOrPath: '#controllers/home_controller',
method: 'index',
})
assert.deepEqual(await parseBindingReference('#controllers/home.controller.index'), {
moduleNameOrPath: '#controllers/home.controller',
method: 'index',
})
})
test('parse class reference', async ({ assert }) => {
class HomeController {}
assert.deepEqual(await parseBindingReference([HomeController]), {
moduleNameOrPath: 'HomeController',
method: 'handle',
})
assert.deepEqual(await parseBindingReference([HomeController, 'index']), {
moduleNameOrPath: 'HomeController',
method: 'index',
})
})
test('parse lazy import reference', async ({ assert }) => {
const HomeController = () => import('#controllers/home_controller' as any)
assert.deepEqual(await parseBindingReference([HomeController]), {
moduleNameOrPath: '#controllers/home_controller',
method: 'handle',
})
assert.deepEqual(await parseBindingReference([HomeController, 'index']), {
moduleNameOrPath: '#controllers/home_controller',
method: 'index',
})
})
})