Beispiel #1
0
def test_highlight_text():
    s1 = "hello world"
    s2 = "hello {}orld".format(internals.bold("w"))
    assert internals.highlight_text(s1, "w") == s2

    s3 = "hell{}orld".format(internals.bold("o w"))
    assert internals.highlight_text(s2, "o ") == s3
Beispiel #2
0
def test_highlight_match_case_insensitive():
    # Testing issue #69
    text = "Turn-taking"
    entry = {"fields": {"title": "Turn-Taking"}}
    match = {"fields": {"title": set(["Turn-Taking"])}}
    result = models.SearchResult(entry, match)

    text, extra_match_info = internals.highlight_match(text, result)
    assert text == internals.bold("Turn-taking")
    assert extra_match_info == {}
Beispiel #3
0
def test_highlight_match():
    text = "my name is Moshe, 40"
    entry = {
        "name": "Moshe",
        "fields": {
            "age": "40",
            "address": "London, UK",
        },
    }
    match = {
        "name": ["Mosh"],
        "fields": {
            "address": ["London"],
        },
    }
    result = models.SearchResult(entry, match)

    text, extra_match_info = internals.highlight_match(text, result)
    assert text == "my name is {}e, 40".format(internals.bold("Mosh"))
    assert extra_match_info == {
        "address": "{}, UK".format(internals.bold("London"))
    }
Beispiel #4
0
def test_highlight_text_with_color():
    s1 = "hello world"
    s2 = "hello {}orld".format(internals.bold("w"))
    f = lambda s: click.style(s, fg="green")
    assert internals.highlight_text(f(s1), "w") == f(s2)