from g_gremlin.lint import (
    check_error_values,
    check_iferror_args,
    check_offset_args,
    check_unquoted_sheet_refs,
)


def test_unquoted_sheet_ref_with_space():
    issues = check_unquoted_sheet_refs("=A1/My Sheet!B10")
    assert len(issues) == 1
    assert issues[0]["type"] == "unquoted_sheet_ref"
    assert issues[0]["suggested_fix"] == "=A1/'My Sheet'!B10"


def test_unquoted_sheet_ref_with_hyphen():
    issues = check_unquoted_sheet_refs("=A1/FY-26!B10")
    assert len(issues) == 1
    assert issues[0]["suggested_fix"] == "=A1/'FY-26'!B10"


def test_unquoted_sheet_ref_with_underscore_ok():
    issues = check_unquoted_sheet_refs("=A1/My_Sheet!B10")
    assert len(issues) == 0


def test_offset_too_few_args():
    issues = check_offset_args("=OFFSET(A1, 1)")
    assert len(issues) == 1
    assert issues[0]["args_found"] == 2


def test_offset_correct_args():
    issues = check_offset_args("=OFFSET(A1, 0, -2, 1, 1)")
    assert len(issues) == 0


def test_iferror_missing_fallback():
    issues = check_iferror_args("=IFERROR(OFFSET(A1,0,-2))")
    assert len(issues) == 1


def test_iferror_with_fallback():
    issues = check_iferror_args("=IFERROR(OFFSET(A1,0,-2), 0)")
    assert len(issues) == 0


def test_error_values():
    assert check_error_values("#REF!")["type"] == "ref_error"
    assert check_error_values("#NAME?")["type"] == "name_error"
    assert check_error_values(123) is None
