Debian Codegraph @

tests/pyutils/test_suggestion_list.py

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