-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathInterpolation.vimspec
More file actions
74 lines (67 loc) · 3.04 KB
/
Interpolation.vimspec
File metadata and controls
74 lines (67 loc) · 3.04 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
Describe Data.String.Interpolation
Before all
let g:I = vital#vital#new().import('Data.String.Interpolation')
function! InterpolationFunc() abort
let year = 2015
return g:I.interpolate('Happy new year, ${year}!', l:)
endfunction
function! InterpolationFuncA(x, y, ...) abort
return g:I.interpolate('x is ${x}. y is ${y}', a:)
endfunction
End
After all
delfunction InterpolationFunc
delfunction InterpolationFuncA
End
Describe .interpolate()
It evaluate lots of patterns
let r = InterpolationFunc()
Assert Equals(r, 'Happy new year, 2015!')
Assert Equals(g:I.interpolate('It handles Function as well: ${InterpolationFunc()}')
\ , 'It handles Function as well: Happy new year, 2015!')
Assert Equals(g:I.interpolate('Hi, my name is ${name}.', {'name': 'haya14busa'})
\ , 'Hi, my name is haya14busa.')
Assert Equals(g:I.interpolate('1 + 1 = ${1 + 1}'), '1 + 1 = 2')
Assert Equals(g:I.interpolate('${repeat} and ${repeat}', {'repeat': 'again'}), 'again and again')
Assert Equals(g:I.interpolate('${0}'), '0')
Assert Equals(g:I.interpolate('${string({})}'), '{}')
Assert Equals(g:I.interpolate('${string({"a": "hello"})}'), "{'a': 'hello'}")
let x = '1 + 2 + 3 + 4 + 5'
Assert Equals(g:I.interpolate('${x} = ${eval(x)} ${"${x}"}', l:)
\ , '1 + 2 + 3 + 4 + 5 = 15 ${x}')
let y = '${y}'
Assert Equals(g:I.interpolate('${y}', l:), '${y}')
Assert Equals(g:I.interpolate('${repeat}${repeat}', {'repeat': 'again'}), 'againagain')
Assert Equals(g:I.interpolate('${1}${2}${3}'), '123')
Assert Equals(g:I.interpolate('${x}${y}', {'x': '${y}', 'y': '${x}'}), '${y}${x}')
Assert Equals(g:I.interpolate('hi${string({"a": {}})}foo'), "hi{'a': {}}foo")
Assert Equals(g:I.interpolate('hi${string({"a": {"b": {}}})}foo'), "hi{'a': {'b': {}}}foo")
" line-break for syntax
Assert Equals(g:I.interpolate('${1 + 1 . "}{''"}'),
\"2}{'")
Assert Equals(g:I.interpolate("${'}'}"), '}')
Assert Equals(g:I.interpolate("${'{'}"), '{')
Assert Equals(g:I.interpolate("${'{}}}{{}{}'}"), '{}}}{{}{}')
Assert Equals(g:I.interpolate("${'hoge\"{'}"), 'hoge"{')
End
It handle reassignment different type
Assert Equals(g:I.interpolate('${a} ${b}', {'a': 1, 'b': '1'}), '1 1')
Assert Equals(g:I.interpolate('${a} ${b}', {'a': 1, 'b': 1.0E-6}), '1 1.0e-6')
End
It doesn't raise Vim(let):E704: Funcref variable name must start with a capital
Throws /Vim(let):E729:/ g:I.interpolate('${Funcref}', {'Funcref': function('InterpolationFunc')})
End
It doens't throw error with invalid key in {context}
let context = {
\ 'name': 'vital(valid)',
\ 'f': function('InterpolationFunc'),
\ '000': 'digit',
\ 'v i m': 'space',
\ }
Assert Equals(g:I.interpolate("${name} is awesome", context), "vital(valid) is awesome")
End
It can accept a:
Assert Equals(InterpolationFuncA('X', 'Y'), 'x is X. y is Y')
End
End
End