-
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
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
import { parse } from '~/index'
import {
bold,
channel,
code,
command,
emoji,
italic,
pre,
quote,
root,
strike,
text,
url,
user
} from './helpers'
describe('Text parser', () => {
it('Should parse "foo bar" as text', () => {
expect(parse('foo bar')).toEqual(root([text('foo bar')]))
})
})
describe('Code parser', () => {
it('Should parse "`foo`" as code', () => {
expect(parse('`foo`')).toEqual(root([code('foo')]))
})
it('Should parse "` foo `" as code', () => {
expect(parse('` foo `')).toEqual(root([code(' foo ')]))
})
})
describe('PreText parser', () => {
it('Should parse "```foo```" as pretext', () => {
expect(parse('```foo```')).toEqual(root([pre('foo')]))
})
it('Should parse "``` foo ```" as pretext', () => {
expect(parse('``` foo ```')).toEqual(root([pre(' foo ')]))
})
it('Should parse "``` foo ``` bar ``` baz ```" as two pretexts', () => {
expect(parse('``` foo ``` bar ``` baz ```')).toEqual(
root([pre(' foo '), text(' bar '), pre(' baz ')])
)
})
it('Should not parse "``` ```" as pretext', () => {
expect(parse('``` ```')).toEqual(root([text('``` ```')]))
})
it('Should not parse "foo```bar```baz" as pretext', () => {
expect(parse('foo```bar```baz')).toEqual(root([text('foo```bar```baz')]))
})
})
describe('Bold parser', () => {
it('Should parse "*foo*" as bold', () => {
expect(parse('*foo*')).toEqual(root([bold([text('foo')])]))
})
it('Should parse "foo *bar* baz" as bold', () => {
expect(parse('foo *bar* baz')).toEqual(
root([text('foo '), bold([text('bar')]), text(' baz')])
)
})
it('Should not parse "foo*bar*baz" as bold', () => {
expect(parse('foo*bar*baz')).toEqual(root([text('foo*bar*baz')]))
})
it('Should not parse "*foo*bar" as bold', () => {
expect(parse('*foo*bar')).toEqual(root([text('*foo*bar')]))
})
it('Should not parse "foo * bar * baz" as bold', () => {
expect(parse('foo * bar * baz')).toEqual(root([text('foo * bar * baz')]))
})
})
describe('Link parser', () => {
it('Should parse "Hey, <@FOO>!" as user link', () => {
expect(parse('Hey, <@FOO>!')).toEqual(
root([text('Hey, '), user('FOO'), text('!')])
)
})
it('Should parse "Goto <#FOO>?" as channel link', () => {
expect(parse('Goto <#FOO>?')).toEqual(
root([text('Goto '), channel('FOO'), text('?')])
)
})
it('Should parse "foo <!bar> baz" as command', () => {
expect(parse('foo <!bar> baz')).toEqual(
root([text('foo '), command('bar', []), text(' baz')])
)
})
it('Should parse command arguments', () => {
expect(parse('<!foo^bar>')).toEqual(root([command('foo', ['bar'])]))
})
it('Should parse "Visit <http://foo.bar> or email to <mailto:foo@bar>" as url', () => {
const expected = root([
text('Visit '),
url('http://foo.bar'),
text(' or email to '),
url('mailto:foo@bar')
])
expect(
parse('Visit <http://foo.bar> or email to <mailto:foo@bar>')
).toEqual(expected)
})
it('Should not allow nested link', () => {
expect(parse('<http://foo|<http://bar>>')).toEqual(
root([text('<http://foo|'), url('http://bar'), text('>')])
)
})
it('Should parse label', () => {
expect(parse('<http://foo|bar>')).toEqual(
root([url('http://foo', [text('bar')])])
)
})
it('Should allow formated text in label', () => {
const expected = root([
url('http://foo', [bold([text('bar '), strike([text('baz')])])])
])
expect(parse('<http://foo|*bar ~baz~*>')).toEqual(expected)
})
})
describe('Emoji parser', () => {
it('Should parse "foo :bar: baz" as emoji', () => {
expect(parse('foo :bar: baz')).toEqual(
root([text('foo '), emoji('bar'), text(' baz')])
)
})
it('Should parse emoji with variation', () => {
expect(parse(':foo::bar:')).toEqual(root([emoji('foo', 'bar')]))
})
it('Should not parse "foo:bar:baz" as emoji', () => {
expect(parse('foo:bar:baz')).toEqual(root([text('foo:bar:baz')]))
})
})
describe('Quote parser', () => {
it('Should parse quote text', () => {
expect(parse('> foo *bar*')).toEqual(
root([quote([text(' foo '), bold([text('bar')])])])
)
})
it('Should parse quote locate in second line', () => {
expect(parse('foo\n>bar')).toEqual(
root([text('foo\n'), quote([text('bar')])])
)
})
it('Should parse multiline quote', () => {
expect(parse('foo\n>>>bar\n\nbaz')).toEqual(
root([text('foo\n'), quote([text('bar\n\nbaz')])])
)
})
it('Should not parse "foo>bar" as quote', () => {
expect(parse('foo>bar')).toEqual(root([text('foo>bar')]))
})
it('Should parse ">>>" as quoted ">>"', () => {
expect(parse('>>>')).toEqual(root([quote([text('>>')])]))
})
})
describe('Root parser', () => {
it('Should parse slack message', () => {
const expected = root([
user('FOO', [
text('abc '),
strike([
text('def '),
italic([
text('ghi '),
bold([text('jkl '), emoji('+1')]),
text(' mno')
]),
text(' pqr')
]),
text(' stu '),
pre('vwx')
])
])
expect(
parse('<@FOO|abc ~def _ghi *jkl :+1:* mno_ pqr~ stu ```vwx```>')
).toEqual(expected)
})
})