#
# Copyright (c) 2025 Jared Crapo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# pylint: disable=protected-access, missing-function-docstring, redefined-outer-name
# pylint: disable=missing-module-docstring, unused-variable

from dye import Dye


#
# test the print command
#
def test_print_basic(dye_cmdline, capsys):
    strings = "Hello there. General Kenobi."
    exit_code = dye_cmdline(f"print {strings}")
    out, err = capsys.readouterr()
    assert exit_code == Dye.EXIT_SUCCESS
    assert not err
    assert out == f"{strings}\n"


def test_print_no_newline(dye_cmdline, capsys):
    strings = "Hello there. General Kenobi."
    exit_code = dye_cmdline(f"print -n {strings}")
    out, err = capsys.readouterr()
    assert exit_code == Dye.EXIT_SUCCESS
    assert not err
    assert out == f"{strings}"


def test_print_theme_style(dye_cmdline, capsys):
    theme_str = """
    [styles]
    bright_green = "#99e343 bold"
    """
    strings = "Hello there. General Kenobi."
    exit_code = dye_cmdline(f"print -s bright_green {strings}", theme_str)
    out, err = capsys.readouterr()
    assert exit_code == Dye.EXIT_SUCCESS
    assert not err
    assert strings in out
    # there better be some ansi codes in there, but we aren't going to test which ones
    assert len(out) > len(f"{strings}\n")


def test_print_theme_invalid_style(dye_cmdline, capsys):
    theme_str = """
    [styles]
    bright_green = "#99e343 bold"
    """
    strings = "Hello there. General Kenobi."
    exit_code = dye_cmdline(f"print -s bbright_green {strings}", theme_str)
    out, err = capsys.readouterr()
    assert exit_code == Dye.EXIT_SUCCESS
    assert not err
    assert out == f"{strings}\n"
