|
1 |
| -Before: |
2 |
| - if exists('expected') |
3 |
| - unlet expected |
4 |
| - endif |
5 |
| - |
6 | 1 | Execute (count one word):
|
7 |
| - let phrase = 'word' |
8 |
| - let expected = {'word': 1} |
9 |
| - AssertEqual expected, WordCount(phrase) |
| 2 | + let g:sentence = "word" |
| 3 | + let g:expected = {'word': 1} |
| 4 | + AssertEqual g:expected, WordCount(g:sentence) |
10 | 5 |
|
11 | 6 | Execute (count one of each word):
|
12 |
| - let phrase = 'one of each' |
13 |
| - let expected = {'one': 1, 'of': 1, 'each': 1} |
14 |
| - AssertEqual expected, WordCount(phrase) |
| 7 | + let g:sentence = "one of each" |
| 8 | + let g:expected = {'of': 1, 'one': 1, 'each': 1} |
| 9 | + AssertEqual g:expected, WordCount(g:sentence) |
15 | 10 |
|
16 | 11 | Execute (multiple occurrences of a word):
|
17 |
| - let phrase = 'one fish two fish red fish blue fish' |
18 |
| - let expected = {'one': 1, 'fish': 4, 'two': 1, 'red': 1, 'blue': 1} |
19 |
| - AssertEqual expected, WordCount(phrase) |
| 12 | + let g:sentence = "one fish two fish red fish blue fish" |
| 13 | + let g:expected = {'one': 1, 'blue': 1, 'two': 1, 'fish': 4, 'red': 1} |
| 14 | + AssertEqual g:expected, WordCount(g:sentence) |
20 | 15 |
|
21 | 16 | Execute (handles cramped lists):
|
22 |
| - let phrase = 'one,two,three' |
23 |
| - let expected = {'one': 1, 'two': 1, 'three': 1} |
24 |
| - AssertEqual expected, WordCount(phrase) |
| 17 | + let g:sentence = "one,two,three" |
| 18 | + let g:expected = {'one': 1, 'two': 1, 'three': 1} |
| 19 | + AssertEqual g:expected, WordCount(g:sentence) |
25 | 20 |
|
26 | 21 | Execute (handles expanded lists):
|
27 |
| - let phrase = "one,\ntwo,\nthree" |
28 |
| - let expected = {'one': 1, 'two': 1, 'three': 1} |
29 |
| - AssertEqual expected, WordCount(phrase) |
| 22 | + let g:sentence = "one,\ntwo,\nthree" |
| 23 | + let g:expected = {'one': 1, 'two': 1, 'three': 1} |
| 24 | + AssertEqual g:expected, WordCount(g:sentence) |
30 | 25 |
|
31 | 26 | Execute (ignore punctuation):
|
32 |
| - let phrase = 'car: carpet as java: javascript!!&@$%^&' |
33 |
| - let expected = {'car': 1, 'carpet': 1, 'as': 1, 'java': 1, 'javascript': 1} |
34 |
| - AssertEqual expected, WordCount(phrase) |
| 27 | + let g:sentence = "car: carpet as java: javascript!!&@$%^&" |
| 28 | + let g:expected = {'car': 1, 'carpet': 1, 'as': 1, 'java': 1, 'javascript': 1} |
| 29 | + AssertEqual g:expected, WordCount(g:sentence) |
35 | 30 |
|
36 | 31 | Execute (include numbers):
|
37 |
| - let phrase = 'testing, 1, 2 testing' |
38 |
| - let expected = {'testing': 2, '1': 1, '2': 1} |
39 |
| - AssertEqual expected, WordCount(phrase) |
| 32 | + let g:sentence = "testing, 1, 2 testing" |
| 33 | + let g:expected = {'1': 1, 'testing': 2, '2': 1} |
| 34 | + AssertEqual g:expected, WordCount(g:sentence) |
40 | 35 |
|
41 | 36 | Execute (normalize case):
|
42 |
| - let phrase = 'go Go GO Stop stop' |
43 |
| - let expected = {'go': 3, 'stop': 2} |
44 |
| - AssertEqual expected, WordCount(phrase) |
| 37 | + let g:sentence = "go Go GO Stop stop" |
| 38 | + let g:expected = {'go': 3, 'stop': 2} |
| 39 | + AssertEqual g:expected, WordCount(g:sentence) |
| 40 | + |
| 41 | +Execute (with apostrophes): |
| 42 | + let g:sentence = "First: don't laugh. Then: don't cry." |
| 43 | + let g:expected = {'first': 1, 'laugh': 1, 'then': 1, "don't": 2, 'cry': 1} |
| 44 | + AssertEqual g:expected, WordCount(g:sentence) |
45 | 45 |
|
46 | 46 | Execute (with apostrophes):
|
47 |
| - let phrase = "First: don't laugh. Then: don't cry." |
48 |
| - let expected = {'first': 1, 'don''t': 2, 'laugh': 1, 'then': 1, 'cry': 1} |
49 |
| - AssertEqual expected, WordCount(phrase) |
| 47 | + let g:sentence = "'First: don't laugh. Then: don't cry. You're getting it.'" |
| 48 | + let g:expected = {'first': 1, 'laugh': 1, 'then': 1, 'getting': 1, 'it': 1, "you're": 1, "don't": 2, 'cry': 1} |
| 49 | + AssertEqual g:expected, WordCount(g:sentence) |
50 | 50 |
|
51 | 51 | Execute (with quotations):
|
52 |
| - let phrase = "Joe can't tell between 'large' and large." |
53 |
| - let expected = {'joe': 1, 'can''t': 1, 'tell': 1, 'between': 1, 'large': 2, 'and': 1} |
54 |
| - AssertEqual expected, WordCount(phrase) |
| 52 | + let g:sentence = "Joe can't tell between 'large' and large." |
| 53 | + let g:expected = {'large': 2, "can't": 1, 'and': 1, 'tell': 1, 'joe': 1, 'between': 1} |
| 54 | + AssertEqual g:expected, WordCount(g:sentence) |
| 55 | + |
| 56 | +Execute (substrings from the beginning): |
| 57 | + let g:sentence = "Joe can't tell between app, apple and a." |
| 58 | + let g:expected = {'a': 1, 'apple': 1, 'and': 1, "can't": 1, 'app': 1, 'tell': 1, 'joe': 1, 'between': 1} |
| 59 | + AssertEqual g:expected, WordCount(g:sentence) |
| 60 | + |
| 61 | +Execute (multiple spaces not detected as a word): |
| 62 | + let g:sentence = " multiple whitespaces" |
| 63 | + let g:expected = {'whitespaces': 1, 'multiple': 1} |
| 64 | + AssertEqual g:expected, WordCount(g:sentence) |
| 65 | + |
| 66 | +Execute (alternating word separators not detected as a word): |
| 67 | + let g:sentence = ",\n,one,\n ,two \n 'three'" |
| 68 | + let g:expected = {'one': 1, 'two': 1, 'three': 1} |
| 69 | + AssertEqual g:expected, WordCount(g:sentence) |
| 70 | + |
| 71 | +Execute (quotation for word with apostrophe): |
| 72 | + let g:sentence = "can, can't, 'can't'" |
| 73 | + let g:expected = {"can't": 2, "can": 1} |
| 74 | + AssertEqual g:expected, WordCount(g:sentence) |
0 commit comments