Commit 6404b0723d7838012e4e8b50c2145803a51d53b5
1 parent
e5eb1a0b
Exists in
master
and in
5 other branches
Improved test name [skip ci]
Showing
1 changed file
with
17 additions
and
17 deletions
Show diff stats
test/misspellings_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | class MisspellingsTest < Minitest::Test | 3 | class MisspellingsTest < Minitest::Test |
4 | - def test_misspellings | 4 | + def test_false |
5 | store_names ["abc", "abd", "aee"] | 5 | store_names ["abc", "abd", "aee"] |
6 | assert_search "abc", ["abc"], misspellings: false | 6 | assert_search "abc", ["abc"], misspellings: false |
7 | end | 7 | end |
8 | 8 | ||
9 | - def test_misspellings_distance | 9 | + def test_distance |
10 | store_names ["abbb", "aabb"] | 10 | store_names ["abbb", "aabb"] |
11 | assert_search "aaaa", ["aabb"], misspellings: {distance: 2} | 11 | assert_search "aaaa", ["aabb"], misspellings: {distance: 2} |
12 | end | 12 | end |
13 | 13 | ||
14 | - def test_misspellings_prefix_length | 14 | + def test_prefix_length |
15 | store_names ["ap", "api", "apt", "any", "nap", "ah", "ahi"] | 15 | store_names ["ap", "api", "apt", "any", "nap", "ah", "ahi"] |
16 | assert_search "ap", ["ap"], misspellings: {prefix_length: 2} | 16 | assert_search "ap", ["ap"], misspellings: {prefix_length: 2} |
17 | assert_search "api", ["ap", "api", "apt"], misspellings: {prefix_length: 2} | 17 | assert_search "api", ["ap", "api", "apt"], misspellings: {prefix_length: 2} |
18 | end | 18 | end |
19 | 19 | ||
20 | - def test_misspellings_prefix_length_operator | 20 | + def test_prefix_length_operator |
21 | store_names ["ap", "api", "apt", "any", "nap", "ah", "aha"] | 21 | store_names ["ap", "api", "apt", "any", "nap", "ah", "aha"] |
22 | assert_search "ap ah", ["ap", "ah"], operator: "or", misspellings: {prefix_length: 2} | 22 | assert_search "ap ah", ["ap", "ah"], operator: "or", misspellings: {prefix_length: 2} |
23 | assert_search "api ahi", ["ap", "api", "apt", "ah", "aha"], operator: "or", misspellings: {prefix_length: 2} | 23 | assert_search "api ahi", ["ap", "api", "apt", "ah", "aha"], operator: "or", misspellings: {prefix_length: 2} |
24 | end | 24 | end |
25 | 25 | ||
26 | - def test_misspellings_fields_operator | 26 | + def test_fields_operator |
27 | store [ | 27 | store [ |
28 | {name: "red", color: "red"}, | 28 | {name: "red", color: "red"}, |
29 | {name: "blue", color: "blue"}, | 29 | {name: "blue", color: "blue"}, |
@@ -34,55 +34,55 @@ class MisspellingsTest < Minitest::Test | @@ -34,55 +34,55 @@ class MisspellingsTest < Minitest::Test | ||
34 | assert_search "red blue", ["red", "blue", "cyan", "magenta"], operator: "or", fields: ["color"], misspellings: false | 34 | assert_search "red blue", ["red", "blue", "cyan", "magenta"], operator: "or", fields: ["color"], misspellings: false |
35 | end | 35 | end |
36 | 36 | ||
37 | - def test_misspellings_below_unmet | 37 | + def test_below_unmet |
38 | store_names ["abc", "abd", "aee"] | 38 | store_names ["abc", "abd", "aee"] |
39 | assert_search "abc", ["abc", "abd"], misspellings: {below: 2} | 39 | assert_search "abc", ["abc", "abd"], misspellings: {below: 2} |
40 | end | 40 | end |
41 | 41 | ||
42 | - def test_misspellings_below_unmet_result | 42 | + def test_below_unmet_result |
43 | store_names ["abc", "abd", "aee"] | 43 | store_names ["abc", "abd", "aee"] |
44 | assert Product.search("abc", misspellings: {below: 2}).misspellings? | 44 | assert Product.search("abc", misspellings: {below: 2}).misspellings? |
45 | end | 45 | end |
46 | 46 | ||
47 | - def test_misspellings_below_met | 47 | + def test_below_met |
48 | store_names ["abc", "abd", "aee"] | 48 | store_names ["abc", "abd", "aee"] |
49 | assert_search "abc", ["abc"], misspellings: {below: 1} | 49 | assert_search "abc", ["abc"], misspellings: {below: 1} |
50 | end | 50 | end |
51 | 51 | ||
52 | - def test_misspellings_below_met_result | 52 | + def test_below_met_result |
53 | store_names ["abc", "abd", "aee"] | 53 | store_names ["abc", "abd", "aee"] |
54 | assert !Product.search("abc", misspellings: {below: 1}).misspellings? | 54 | assert !Product.search("abc", misspellings: {below: 1}).misspellings? |
55 | end | 55 | end |
56 | 56 | ||
57 | - def test_misspellings_field_correct_spelling_still_works | 57 | + def test_field_correct_spelling_still_works |
58 | store [{name: "Sriracha", color: "blue"}] | 58 | store [{name: "Sriracha", color: "blue"}] |
59 | assert_misspellings "Sriracha", ["Sriracha"], {fields: [:name, :color]} | 59 | assert_misspellings "Sriracha", ["Sriracha"], {fields: [:name, :color]} |
60 | assert_misspellings "blue", ["Sriracha"], {fields: [:name, :color]} | 60 | assert_misspellings "blue", ["Sriracha"], {fields: [:name, :color]} |
61 | end | 61 | end |
62 | 62 | ||
63 | - def test_misspellings_field_enabled | 63 | + def test_field_enabled |
64 | store [{name: "Sriracha", color: "blue"}] | 64 | store [{name: "Sriracha", color: "blue"}] |
65 | assert_misspellings "siracha", ["Sriracha"], {fields: [:name]} | 65 | assert_misspellings "siracha", ["Sriracha"], {fields: [:name]} |
66 | assert_misspellings "clue", ["Sriracha"], {fields: [:color]} | 66 | assert_misspellings "clue", ["Sriracha"], {fields: [:color]} |
67 | end | 67 | end |
68 | 68 | ||
69 | - def test_misspellings_field_disabled | 69 | + def test_field_disabled |
70 | store [{name: "Sriracha", color: "blue"}] | 70 | store [{name: "Sriracha", color: "blue"}] |
71 | assert_misspellings "siracha", [], {fields: [:color]} | 71 | assert_misspellings "siracha", [], {fields: [:color]} |
72 | assert_misspellings "clue", [], {fields: [:name]} | 72 | assert_misspellings "clue", [], {fields: [:name]} |
73 | end | 73 | end |
74 | 74 | ||
75 | - def test_misspellings_field_with_transpositions | 75 | + def test_field_with_transpositions |
76 | store [{name: "Sriracha", color: "blue"}] | 76 | store [{name: "Sriracha", color: "blue"}] |
77 | assert_misspellings "lbue", [], {transpositions: false, fields: [:color]} | 77 | assert_misspellings "lbue", [], {transpositions: false, fields: [:color]} |
78 | end | 78 | end |
79 | 79 | ||
80 | - def test_misspellings_field_with_edit_distance | 80 | + def test_field_with_edit_distance |
81 | store [{name: "Sriracha", color: "blue"}] | 81 | store [{name: "Sriracha", color: "blue"}] |
82 | assert_misspellings "crue", ["Sriracha"], {edit_distance: 2, fields: [:color]} | 82 | assert_misspellings "crue", ["Sriracha"], {edit_distance: 2, fields: [:color]} |
83 | end | 83 | end |
84 | 84 | ||
85 | - def test_misspellings_field_multiple | 85 | + def test_field_multiple |
86 | store [ | 86 | store [ |
87 | {name: "Greek Yogurt", color: "white"}, | 87 | {name: "Greek Yogurt", color: "white"}, |
88 | {name: "Green Onions", color: "yellow"} | 88 | {name: "Green Onions", color: "yellow"} |
@@ -91,14 +91,14 @@ class MisspellingsTest < Minitest::Test | @@ -91,14 +91,14 @@ class MisspellingsTest < Minitest::Test | ||
91 | assert_misspellings "mellow", ["Green Onions"], {fields: [:name, :color]} | 91 | assert_misspellings "mellow", ["Green Onions"], {fields: [:name, :color]} |
92 | end | 92 | end |
93 | 93 | ||
94 | - def test_misspellings_field_requires_explicit_search_fields | 94 | + def test_field_requires_explicit_search_fields |
95 | store_names ["Sriracha"] | 95 | store_names ["Sriracha"] |
96 | assert_raises(ArgumentError) do | 96 | assert_raises(ArgumentError) do |
97 | assert_search "siracha", ["Sriracha"], {misspellings: {fields: [:name]}} | 97 | assert_search "siracha", ["Sriracha"], {misspellings: {fields: [:name]}} |
98 | end | 98 | end |
99 | end | 99 | end |
100 | 100 | ||
101 | - def test_misspellings_field_word_start | 101 | + def test_field_word_start |
102 | store_names ["Sriracha"] | 102 | store_names ["Sriracha"] |
103 | assert_search "siracha", ["Sriracha"], fields: [{name: :word_middle}], misspellings: {fields: [:name]} | 103 | assert_search "siracha", ["Sriracha"], fields: [{name: :word_middle}], misspellings: {fields: [:name]} |
104 | end | 104 | end |