1 | var test = require('tape')
|
2 | var GithubSlugger = require('../')
|
3 |
|
4 | test('simple stuff', function (t) {
|
5 | var slugger = new GithubSlugger()
|
6 |
|
7 | t.equals('foo', slugger.slug('foo'))
|
8 | t.equals('foo-bar', slugger.slug('foo bar'))
|
9 | t.equals('foo-1', slugger.slug('foo'))
|
10 |
|
11 | slugger.reset()
|
12 | t.equals('foo', slugger.slug('foo'))
|
13 |
|
14 | t.end()
|
15 | })
|
16 |
|
17 | test('github test cases', function (t) {
|
18 | var slugger = new GithubSlugger()
|
19 |
|
20 | testCases.forEach(function (test) {
|
21 | t.equals(slugger.slug(test.text), test.slug, test.mesg)
|
22 | })
|
23 | t.end()
|
24 | })
|
25 |
|
26 | var testCases = [
|
27 | {
|
28 | mesg: 'allows a dash',
|
29 | text: 'heading with a - dash',
|
30 | slug: 'heading-with-a---dash'
|
31 | },
|
32 | {
|
33 | mesg: 'allows underscores',
|
34 | text: 'heading with an _ underscore',
|
35 | slug: 'heading-with-an-_-underscore'
|
36 | },
|
37 | {
|
38 | mesg: 'filters periods',
|
39 | text: 'heading with a period.txt',
|
40 | slug: 'heading-with-a-periodtxt'
|
41 | },
|
42 | {
|
43 | mesg: 'allows two spaces even after filtering',
|
44 | text: 'exchange.bind_headers(exchange, routing [, bindCallback])',
|
45 | slug: 'exchangebind_headersexchange-routing--bindcallback'
|
46 | },
|
47 | {
|
48 | mesg: 'empty',
|
49 | text: '',
|
50 | slug: ''
|
51 | },
|
52 | {
|
53 | mesg: 'a space',
|
54 | text: ' ',
|
55 | slug: '-1'
|
56 | },
|
57 | {
|
58 | mesg: 'initial space',
|
59 | text: ' initial space',
|
60 | slug: 'initial-space'
|
61 | },
|
62 | {
|
63 | mesg: 'final space',
|
64 | text: 'final space ',
|
65 | slug: 'final-space'
|
66 | },
|
67 | {
|
68 | mesg: 'deals with prototype properties',
|
69 | text: 'length',
|
70 | slug: 'length'
|
71 | },
|
72 | {
|
73 | mesg: 'deals with duplicates correctly',
|
74 | text: 'duplicates',
|
75 | slug: 'duplicates'
|
76 | },
|
77 | {
|
78 | mesg: 'deals with duplicates correctly-1',
|
79 | text: 'duplicates',
|
80 | slug: 'duplicates-1'
|
81 | },
|
82 | {
|
83 | mesg: 'deals with duplicates correctly-2',
|
84 | text: 'duplicates',
|
85 | slug: 'duplicates-2'
|
86 | },
|
87 | {
|
88 | mesg: 'deals with non-latin chars',
|
89 | text: 'Привет',
|
90 | slug: 'Привет'
|
91 | },
|
92 |
|
93 | {
|
94 | mesg: 'gh-and-npm-slug-generation-1',
|
95 | text: 'I ♥ unicode',
|
96 | slug: 'i--unicode'
|
97 | },
|
98 | {
|
99 | mesg: 'gh-and-npm-slug-generation-2',
|
100 | text: 'Dash-dash',
|
101 | slug: 'dash-dash'
|
102 | },
|
103 | {
|
104 | mesg: 'gh-and-npm-slug-generation-3',
|
105 | text: 'en–dash!',
|
106 | slug: 'endash'
|
107 | },
|
108 | {
|
109 | mesg: 'gh-and-npm-slug-generation-4',
|
110 | text: 'em–dash',
|
111 | slug: 'emdash'
|
112 | },
|
113 | {
|
114 | mesg: 'gh-and-npm-slug-generation-5',
|
115 | text: '😄 unicode emoji',
|
116 | slug: '-unicode-emoji'
|
117 | },
|
118 | {
|
119 | mesg: 'gh-and-npm-slug-generation-6',
|
120 | text: '😄-😄 unicode emoji',
|
121 | slug: '--unicode-emoji'
|
122 | },
|
123 | {
|
124 | mesg: 'gh-and-npm-slug-generation-7',
|
125 | text: '😄_😄 unicode emoji',
|
126 | slug: '_-unicode-emoji'
|
127 | },
|
128 | {
|
129 | mesg: 'gh-and-npm-slug-generation-8',
|
130 | text: '😄 - an emoji',
|
131 | slug: '---an-emoji'
|
132 | },
|
133 | {
|
134 | mesg: 'gh-and-npm-slug-generation-9',
|
135 | text: ':smile: - a gemoji',
|
136 | slug: 'smile---a-gemoji'
|
137 | },
|
138 | {
|
139 | mesg: 'gh-and-npm-slug-generation-10',
|
140 | text: ' Initial spaces',
|
141 | slug: 'initial-spaces'
|
142 | },
|
143 | {
|
144 | mesg: 'gh-and-npm-slug-generation-11',
|
145 | text: 'Final spaces ',
|
146 | slug: 'final-spaces'
|
147 | },
|
148 | {
|
149 | mesg: 'gh-and-npm-slug-generation-12',
|
150 | text: 'duplicate',
|
151 | slug: 'duplicate'
|
152 | },
|
153 | {
|
154 | mesg: 'gh-and-npm-slug-generation-13',
|
155 | text: 'duplicate',
|
156 | slug: 'duplicate-1'
|
157 | },
|
158 | {
|
159 | mesg: 'gh-and-npm-slug-generation-14',
|
160 | text: 'Привет non-latin 你好',
|
161 | slug: 'Привет-non-latin-你好'
|
162 | },
|
163 |
|
164 | {
|
165 | mesg: 'emoji-slug-example-1',
|
166 | text: ':ok: No underscore',
|
167 | slug: 'ok-no-underscore'
|
168 | },
|
169 | {
|
170 | mesg: 'emoji-slug-example-2',
|
171 | text: ':ok_hand: Single',
|
172 | slug: 'ok_hand-single'
|
173 | },
|
174 | {
|
175 | mesg: 'emoji-slug-example-3',
|
176 | text: ':ok_hand::hatched_chick: Two in a row with no spaces',
|
177 | slug: 'ok_handhatched_chick-two-in-a-row-with-no-spaces'
|
178 | },
|
179 | {
|
180 | mesg: 'emoji-slug-example-4',
|
181 | text: ':ok_hand: :hatched_chick: Two in a row',
|
182 | slug: 'ok_hand-hatched_chick-two-in-a-row'
|
183 | }
|
184 | ]
|