1 | require './setup'
|
2 |
|
3 | describe 'Pre tag', ->
|
4 | {parseTags, parseCodeText} = require('../lib/utils')
|
5 |
|
6 | describe 'parseTags', ->
|
7 | it 'key-value', ->
|
8 | obj = parseTags('name=hello')
|
9 | expect(obj.name).eq 'hello'
|
10 |
|
11 | it 'key-value duo', ->
|
12 | obj = parseTags('name=hello age=2')
|
13 | expect(obj.name).eq 'hello'
|
14 | expect(obj.age).eq '2'
|
15 |
|
16 | it 'key only', ->
|
17 | obj = parseTags('isolate')
|
18 | expect(obj.isolate).eq true
|
19 |
|
20 | it 'quoted, single', ->
|
21 | obj = parseTags("name='Johnny Cage'")
|
22 | expect(obj.name).eq 'Johnny Cage'
|
23 |
|
24 | it 'quoted, double', ->
|
25 | obj = parseTags('name="Johnny Cage"')
|
26 | expect(obj.name).eq 'Johnny Cage'
|
27 |
|
28 | it 'key + key-value', ->
|
29 | obj = parseTags('isolate name=hello')
|
30 | expect(obj.isolate).eq true
|
31 | expect(obj.name).eq 'hello'
|
32 |
|
33 | it 'key only, twice', ->
|
34 | obj = parseTags('isolate no-code')
|
35 | expect(obj.isolate).eq true
|
36 | expect(obj['no-code']).eq true
|
37 |
|
38 | it 'starts with spaces', ->
|
39 | obj = parseTags(' isolate no-code')
|
40 | expect(obj.isolate).eq true
|
41 | expect(obj['no-code']).eq true
|
42 |
|
43 | it 'multiple', ->
|
44 | obj = parseTags('example name="Bruce Willis" role=actor')
|
45 | expect(obj.example).eq true
|
46 | expect(obj.name).eq "Bruce Willis"
|
47 | expect(obj.role).eq 'actor'
|
48 |
|
49 | it 'classes', ->
|
50 | obj = parseTags('example .padded')
|
51 | expect(obj.class).eq 'padded'
|
52 |
|
53 | it 'classes, multiple, spaced', ->
|
54 | obj = parseTags('example .padded .a .b')
|
55 | expect(obj.class).eq 'padded a b'
|
56 |
|
57 | it 'classes, multiple, no spaces', ->
|
58 | obj = parseTags('example .padded.a.b')
|
59 | expect(obj.class).eq 'padded a b'
|
60 |
|
61 | describe 'parseCodeText', ->
|
62 | it 'with tags', ->
|
63 | out = parseCodeText '''
|
64 | @example width=500
|
65 | div.button
|
66 | '''
|
67 |
|
68 | expect(out.tag).eql 'example width=500'
|
69 | expect(out.code).eql 'div.button'
|
70 |
|
71 | it 'no tags', ->
|
72 | out = parseCodeText '''
|
73 | div.button
|
74 | '''
|
75 |
|
76 | expect(out.tag).null
|
77 | expect(out.code).eql 'div.button'
|
78 |
|
79 | describe 'tag parsing', ->
|
80 | beforeEach ->
|
81 | @load '''
|
82 | ### hello
|
83 |
|
84 | @example
|
85 | div.button
|
86 | '''
|
87 |
|
88 | it 'should work', ->
|
89 | expect(@$).have.selector 'pre'
|
90 |
|
91 | it 'no tags', ->
|
92 | expect(@$("pre").text()).eql '<div class="button"></div>'
|