"""pytest unit tests for pyfind
"""
from pathlib import Path

import pytest
from click.testing import CliRunner

import config
from pyfind import highlight_match, Search, textfile_to_list
from pyfind import cli, Match, is_notebook, search_file, pad_string

LONG_TEXT = (
    "START Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
    "Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar "
    "ultricies, purus lectus malesuada libero, sit amet commodo magna eros "
    "quis urna. Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus. "
    "Pellentesque habitant morbi tristique senectus et netus et malesuada fames "
    "ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. END"
)

#-------------------------------------------------------------------------------
# The following are unit tests that test a single function or method.
# To only run these tests: pytest -m unit_test
#-------------------------------------------------------------------------------

@pytest.mark.unit_test
@pytest.mark.parametrize(
    "string, length, expected",
    [
        (
            "abcdef",
            10,
            "abcdef    ",
        ),
        (
            "abcdef",
            6,
            "abcdef",
        ),
        (
            "abcdef",
            4,
            "abcd",
        ),
    ],
)
def test_pad_string(string, length, expected):
    """function: pad_string()
    """
    assert pad_string(string, length) == expected


@pytest.mark.unit_test
@pytest.mark.parametrize(
    "searchfor,maxchars,expected",
    [
        (
            "START",
            11,
            [("START", config.COLOR_MATCH_TEXT), (" Lorem", config.COLOR_MATCH_LINE)],
        ),
        (
            "Lorem",
            23,
            [
                ("START ", config.COLOR_MATCH_LINE),
                ("Lorem", config.COLOR_MATCH_TEXT),
                (" ipsum dolor", config.COLOR_MATCH_LINE),
            ],
        ),
        (
            "viverra",
            20,
            [
                (". Nunc ", config.COLOR_MATCH_LINE),
                ("viverra", config.COLOR_MATCH_TEXT),
                (" imper", config.COLOR_MATCH_LINE),
            ],
        ),