from srs2std.util import (
    find_and_split_by_regex,
    is_now_string,
    now_string,
    recover_broken_sentences,
    sent_tokenize_with_newlines,
)


def test_sent_tokenize_with_newlines():
    text_list = [
        "Hello, world! This is the second sentence.",
        "",
        "This is the forth sentence",
        "(here is the part of the forth).",
    ]
    text = "\n".join(text_list)

    expected = [
        "Hello, world!",
        "This is the second sentence.",
        "\n",
        "\n",
        "This is the forth sentence",
        "\n",
        "(here is the part of the forth).",
    ]

    actual = sent_tokenize_with_newlines(text)
    assert actual == expected


def test_recover_broken_sentences():
    text = "This is the broken\nsentence."
    expected = "This is the broken sentence."
    assert recover_broken_sentences(text) == expected


def test_find_and_split_by_regex_simple():
    pattern = "B|C|D"
    string = "aDaaCaaaBaaaa"

    expected_separators = ["D", "C", "B"]
    expected_separated = ["a", "aa", "aaa", "aaaa"]

    actual_separators, actual_separated = find_and_split_by_regex(pattern, string)
    assert actual_separators == expected_separators
    assert actual_separated == expected_separated


def test_find_and_split_by_regex_none():
    pattern = "X"
    string = "aDaaCaaaBaaaa"

    expected_separators = []
    expected_separated = ["aDaaCaaaBaaaa"]

    actual_separators, actual_separated = find_and_split_by_regex(pattern, string)
    assert actual_separators == expected_separators
    assert actual_separated == expected_separated


def test_now_string_and_is_now_string():
    now_str = now_string()
    assert is_now_string(now_str)
