from typing import Callable
from unittest import expectedFailure

import pytest

from contractme.contracting import par_inner, show_source

"""
This tests mainly the heuristics for displaying a nice source, as
the source parsing sacrifices precision in favor of accepting many
difference callable type.
"""


@pytest.mark.parametrize(
    "i,expected",
    [
        ("1 + 2", "1 + 2"),
        ("1 + 2)", "1 + 2"),
        ("(1 + 2)", "1 + 2"),
        ("( (1 + 2)", "1 + 2"),
        ("( ( 1 + 2 ) ) ", "1 + 2"),
        ("1 + (2)", "1 + (2)"),
        ("1 + (2))", "1 + (2)"),
    ],
)
def test_par_inner(i: str, expected: str):
    assert par_inner(i) == expected


@pytest.mark.parametrize("f,expected", [((lambda a: a), "a")])
def test_show_source(f: Callable, expected: str):
    assert show_source(f) == expected
    assert show_source((lambda a: a)) == "a"

    # trying to add some confusion
    def lambdaa(f):
        return f

    assert show_source(lambdaa(lambda a: a)) == "a"
    assert show_source(lambda f: (lambda a: a)) == "lambda a: a"
