|
| 1 | +from typing import List |
| 2 | + |
1 | 3 | from graphql.pyutils import suggestion_list
|
2 | 4 |
|
3 | 5 |
|
| 6 | +def expect_suggestions(input: str, options: List[str], expected: List[str]) -> None: |
| 7 | + assert suggestion_list(input, options) == expected |
| 8 | + |
| 9 | + |
4 | 10 | def describe_suggestion_list():
|
5 | 11 | def returns_results_when_input_is_empty():
|
6 |
| - assert suggestion_list("", ["a"]) == ["a"] |
| 12 | + expect_suggestions("", ["a"], ["a"]) |
7 | 13 |
|
8 | 14 | def returns_empty_array_when_there_are_no_options():
|
9 |
| - assert suggestion_list("input", []) == [] |
| 15 | + expect_suggestions("input", [], []) |
10 | 16 |
|
11 | 17 | def returns_options_with_small_lexical_distance():
|
12 |
| - assert suggestion_list("greenish", ["green"]) == ["green"] |
13 |
| - assert suggestion_list("green", ["greenish"]) == ["greenish"] |
| 18 | + expect_suggestions("greenish", ["green"], ["green"]) |
| 19 | + expect_suggestions("green", ["greenish"], ["greenish"]) |
14 | 20 |
|
15 | 21 | def returns_options_with_different_case():
|
16 |
| - assert suggestion_list("verylongstring", ["VERYLONGSTRING"]) == [ |
17 |
| - "VERYLONGSTRING" |
18 |
| - ] |
| 22 | + expect_suggestions("verylongstring", ["VERYLONGSTRING"], ["VERYLONGSTRING"]) |
19 | 23 |
|
20 |
| - assert suggestion_list("VERYLONGSTRING", ["verylongstring"]) == [ |
21 |
| - "verylongstring" |
22 |
| - ] |
| 24 | + expect_suggestions("VERYLONGSTRING", ["verylongstring"], ["verylongstring"]) |
23 | 25 |
|
24 |
| - assert suggestion_list("VERYLONGSTRING", ["VeryLongString"]) == [ |
25 |
| - "VeryLongString" |
26 |
| - ] |
| 26 | + expect_suggestions("VERYLONGSTRING", ["VeryLongString"], ["VeryLongString"]) |
27 | 27 |
|
28 | 28 | def returns_options_with_transpositions():
|
29 |
| - assert suggestion_list("agr", ["arg"]) == ["arg"] |
| 29 | + expect_suggestions("agr", ["arg"], ["arg"]) |
30 | 30 |
|
31 |
| - assert suggestion_list("214365879", ["123456789"]) == ["123456789"] |
| 31 | + expect_suggestions("214365879", ["123456789"], ["123456789"]) |
32 | 32 |
|
33 | 33 | def returns_options_sorted_based_on_lexical_distance():
|
34 |
| - assert suggestion_list("abc", ["a", "ab", "abc"]) == ["abc", "ab"] |
| 34 | + expect_suggestions("abc", ["a", "ab", "abc"], ["abc", "ab"]) |
35 | 35 |
|
36 |
| - assert suggestion_list( |
37 |
| - "GraphQl", ["graphics", "SQL", "GraphQL", "quarks", "mark"] |
38 |
| - ) == ["GraphQL", "graphics"] |
| 36 | + expect_suggestions( |
| 37 | + "GraphQl", |
| 38 | + ["graphics", "SQL", "GraphQL", "quarks", "mark"], |
| 39 | + ["GraphQL", "graphics"], |
| 40 | + ) |
39 | 41 |
|
40 | 42 | def returns_options_with_the_same_lexical_distance_sorted_lexicographically():
|
41 |
| - assert suggestion_list("a", ["az", "ax", "ay"]) == ["ax", "ay", "az"] |
| 43 | + expect_suggestions("a", ["az", "ax", "ay"], ["ax", "ay", "az"]) |
42 | 44 |
|
43 |
| - assert suggestion_list("boo", ["moo", "foo", "zoo"]) == ["foo", "moo", "zoo"] |
| 45 | + expect_suggestions("boo", ["moo", "foo", "zoo"], ["foo", "moo", "zoo"]) |
44 | 46 |
|
45 | 47 | def returns_options_sorted_first_by_lexical_distance_then_lexicographically():
|
46 |
| - assert suggestion_list( |
47 |
| - "csutomer", ["store", "customer", "stomer", "some", "more"] |
48 |
| - ) == ["customer", "stomer", "some", "store"] |
| 48 | + expect_suggestions( |
| 49 | + "csutomer", |
| 50 | + ["store", "customer", "stomer", "some", "more"], |
| 51 | + ["customer", "stomer", "some", "store"], |
| 52 | + ) |
0 commit comments