-
Notifications
You must be signed in to change notification settings - Fork 1
/
slugify_test.v
55 lines (49 loc) · 1.7 KB
/
slugify_test.v
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
module slugify
fn test_slugify_regexes() {
slugifier := default()
assert slugifier.make('ThIs IS a_ test?@') == 'this-is-a_-test-at'
}
fn test_slugify_make_lang() {
mut slugifier := default()
assert slugifier.make('Har du røykt sokka dine?') == 'har-du-r-ykt-sokka-dine'
slugifier.lang = 'no'
assert slugifier.make('Har du røykt sokka dine?') == 'har-du-roeykt-sokka-dine'
slugifier.lang = 'it'
assert slugifier.make('Un € o un $') == 'un-eur-o-un'
slugifier.lang = 'ru'
assert slugifier.make('любя съешь щипцы вздохнёт мэр кайф жгуч') == 'lyubya-sesh-schiptsi-vzdohnyot-mer-kayf-zhguch'
}
fn test_max_length() {
slugifier := SlugifyOptions{
max_length: 12
}
assert slugifier.make('Sugma Willy: we are your fitness family.').len == 12
}
fn test_smart_truncate() {
slugifier := SlugifyOptions{
max_length: 12
smart_truncate: true
}
assert slugifier.make('Sugma Willy: we are your fitness family.') == 'Sugma-Willy'
}
fn test_skip_transliteration() {
mut slugifier := SlugifyOptions{
transliterate: false
}
assert slugifier.make('Har du røykt sokka dine?') == 'Har-du-r-ykt-sokka-dine'
slugifier.lang = 'no'
assert slugifier.make('Har du røykt sokka dine?') == 'Har-du-r-ykt-sokka-dine'
}
fn test_is_slug() {
assert is_slug('') == false
assert is_slug('-begin') == false
assert is_slug('_begin') == false
assert is_slug('end-') == false
assert is_slug('end_') == false
assert is_slug('singleword') == true
assert is_slug('includes_underscores') == true
assert is_slug('includes whitespaces') == false
assert is_slug('includes-dashes') == true
assert is_slug('Har du røykt sokka dine?') == false
assert is_slug('Include_Capital_Letters') == true
}