File: test_suggestion_list.py

package info (click to toggle)
graphql-core 3.2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,384 kB
  • sloc: python: 45,812; makefile: 26; sh: 13
file content (61 lines) | stat: -rw-r--r-- 2,222 bytes parent folder | download
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
56
57
58
59
60
61
from typing import List

from graphql.pyutils import suggestion_list


def expect_suggestions(input_: str, options: List[str], expected: List[str]) -> None:
    assert suggestion_list(input_, options) == expected


def describe_suggestion_list():
    def returns_results_when_input_is_empty():
        expect_suggestions("", ["a"], ["a"])

    def returns_empty_array_when_there_are_no_options():
        expect_suggestions("input", [], [])

    def returns_options_with_small_lexical_distance():
        expect_suggestions("greenish", ["green"], ["green"])
        expect_suggestions("green", ["greenish"], ["greenish"])

    def rejects_options_with_distance_that_exceeds_threshold():
        expect_suggestions("aaaa", ["aaab"], ["aaab"])
        expect_suggestions("aaaa", ["aabb"], ["aabb"])
        expect_suggestions("aaaa", ["abbb"], [])

        expect_suggestions("ab", ["ca"], [])

    def returns_options_with_different_case():
        expect_suggestions("verylongstring", ["VERYLONGSTRING"], ["VERYLONGSTRING"])

        expect_suggestions("VERYLONGSTRING", ["verylongstring"], ["verylongstring"])

        expect_suggestions("VERYLONGSTRING", ["VeryLongString"], ["VeryLongString"])

    def returns_options_with_transpositions():
        expect_suggestions("agr", ["arg"], ["arg"])

        expect_suggestions("214365879", ["123456789"], ["123456789"])

    def returns_options_sorted_based_on_lexical_distance():
        expect_suggestions("abc", ["a", "ab", "abc"], ["abc", "ab", "a"])

        expect_suggestions(
            "GraphQl",
            ["graphics", "SQL", "GraphQL", "quarks", "mark"],
            ["GraphQL", "graphics"],
        )

    def returns_options_with_the_same_lexical_distance_sorted_naturally():
        expect_suggestions("a", ["az", "ax", "ay"], ["ax", "ay", "az"])

        expect_suggestions("boo", ["moo", "foo", "zoo"], ["foo", "moo", "zoo"])

        expect_suggestions("abc", ["a1", "a12", "a2"], ["a1", "a2", "a12"])

    def returns_options_sorted_first_by_lexical_distance_then_naturally():
        expect_suggestions(
            "csutomer",
            ["store", "customer", "stomer", "some", "more"],
            ["customer", "stomer", "some", "store"],
        )