<commit_before>import io

import pytest

from rich.console import Console
from rich.rule import Rule
from rich.text import Text


def test_rule():
    console = Console(
        width=16, file=io.StringIO(), force_terminal=True, legacy_windows=False
    )
    console.print(Rule())
    console.print(Rule("foo"))
    console.rule(Text("foo", style="bold"))
    console.rule("foobarbazeggfoobarbazegg")
    expected = "\x1b[92m────────────────\x1b[0m\n"
    expected += "\x1b[92m───── \x1b[0mfoo\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n"
    expected += (
        "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n"
    )
    expected += "\x1b[92m─ \x1b[0mfoobarbazeg…\x1b[92m ─\x1b[0m\n"

    result = console.file.getvalue()
    assert result == expected


# doesn't work for now
def test_rule_cjk():
    console = Console(
        width=16,
        file=io.StringIO(),
        force_terminal=True,
        color_system=None,
        legacy_windows=False,
    )
    console.rule("欢迎！")
    expected = "──── 欢迎！ ────\n"
    assert console.file.getvalue() == expected


def test_repr():
    rule = Rule("foo")
    assert isinstance(repr(rule), str)


def test_error():
    with pytest.raises(ValueError):
        Rule(characters="")
<commit_msg>add tests (rule.py coverage 100% now)<commit_after>import io

import pytest

from rich.console import Console
from rich.rule import Rule
from rich.text import Text


def test_rule():
    console = Console(
        width=16, file=io.StringIO(), force_terminal=True, legacy_windows=False
    )
    console.print(Rule())
    console.print(Rule("foo"))
    console.rule(Text("foo", style="bold"))
    console.rule("foobarbazeggfoobarbazegg")
    expected = "\x1b[92m────────────────\x1b[0m\n"
    expected += "\x1b[92m───── \x1b[0mfoo\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n"
    expected += (
        "\x1b[92m───── \x1b[0m\x1b[1mfoo\x1b[0m\x1b[92m ─────\x1b[0m\x1b[92m─\x1b[0m\n"
    )
    expected += "\x1b[92m─ \x1b[0mfoobarbazeg…\x1b[92m ─\x1b[0m\n"

    result = console.file.getvalue()
    assert result == expected


# doesn't work for now
# def test_rule_cjk():
#     console = Console(
#         width=16,
#         file=io.StringIO(),
#         force_terminal=True,
#         color_system=None,
#         legacy_windows=False,
#     )
#     console.rule("欢迎！")
#     expected = "──── 欢迎！ ────\n"
#     assert console.file.getvalue() == expected


def test_characters():
    console = Console(
        width=16,
        file=io.StringIO(),
        force_terminal=True,
        color_system=None,
        legacy_windows=False,
    )
    console.rule(characters="+*")
    console.rule("foo", characters="+*")
    expected = "+*+*+*+*+*+*+*+*\n"
    expected += "+*+*+ foo +*+*++\n"
    assert console.file.getvalue() == expected


def test_repr():
    rule = Rule("foo")
    assert isinstance(repr(rule), str)


def test_error():
    with pytest.raises(ValueError):
        Rule(characters="")

{'fraction_non_alphanumeric': 0.1870576339737108, 'fraction_numerical': 0.03741152679474216, 'mean_word_length': 3.162692847124825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3174080', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1155, 'n_words': 187}