Skip to content

Commit

Permalink
Fix and add tests
Browse files Browse the repository at this point in the history
Related to rfc3986 / pretty modes
  • Loading branch information
Zertz-Lenovo committed Dec 19, 2014
1 parent 380967a commit bb278ca
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/slug.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ describe 'slug', ->
[slug 'foo- bar baz'].should.eql ['foo-bar-baz']
[slug 'foo] bar baz'].should.eql ['foo-bar-baz']

it 'should leave allowed chars', ->
it 'should leave allowed chars in rfc3986 mode', ->
allowed = ['.', '_', '~']
for a in allowed
[slug "foo #{a} bar baz"].should.eql ["foo-#{a}-bar-baz"]
[slug "foo #{a} bar baz",
mode: "rfc3986"].should.eql ["foo-#{a}-bar-baz"]

it 'should replace latin chars', ->
char_map = {
Expand Down Expand Up @@ -121,17 +122,36 @@ describe 'slug', ->
replacement = replacement.replace ' ', '-'
[slug "foo #{char} bar baz"].should.eql ["foo-#{replacement}-bar-baz"]

it 'should replace symbols', ->
it 'should replace symbols in rfc3986 mode', ->
char_map = {
'©':'c', 'œ': 'oe', 'Œ': 'OE', '': 'sum', '®': 'r',
'': 'd', 'ƒ': 'f', '': 'tm',
'': 'sm', '': '...', '˚': 'o', 'º': 'o', 'ª': 'a'
'': 'delta', '': 'infinity', '': 'love', '&': 'and', '|': 'or',
'<': 'less', '>': 'greater'
}
for char, replacement of char_map
[slug "foo #{char} bar baz",
mode: "rfc3986"].should.eql ["foo-#{replacement}-bar-baz"]

it 'should replace symbols in pretty mode', ->
char_map = {
'©':'c', 'œ': 'oe', 'Œ': 'OE', '': 'sum', '®': 'r',
'': 'd', 'ƒ': 'f', '': 'tm',
'': 'sm', '˚': 'o', 'º': 'o', 'ª': 'a'
'': 'delta', '': 'infinity', '': 'love', '&': 'and', '|': 'or',
'<': 'less', '>': 'greater'
}
for char, replacement of char_map
[slug "foo #{char} bar baz"].should.eql ["foo-#{replacement}-bar-baz"]

it 'should remove ellipsis in pretty mode', ->
char_map = {
'': '...'
}
for char, replacement of char_map
[slug "foo #{char} bar baz"].should.eql ["foo-bar-baz"]

it 'should strip symbols', ->
char_map = [
'', '', '', '', '', ''
Expand Down

0 comments on commit bb278ca

Please sign in to comment.