# Path: dataproperty/_function.py
# def calc_ascii_char_width(unicode_str: str, east_asian_ambiguous_width: int = 1) -> int:
#     import unicodedata
# 
#     width = 0
#     for char in unicode_str:
#         char_width = unicodedata.east_asian_width(char)
#         if char_width in "WF":
#             width += 2
#         elif char_width == "A":
#             _validate_eaaw(east_asian_ambiguous_width)
#             width += east_asian_ambiguous_width
#         else:
#             width += 1
# 
#     return width
# 
# def is_multibyte_str(text) -> bool:
#     from typepy import StrictLevel, String
# 
#     if not String(text, strict_level=StrictLevel.MIN).is_type():
#         return False
# 
#     try:
#         unicode_text = MultiByteStrDecoder(text).unicode_str
#     except ValueError:
#         return False
# 
#     try:
#         unicode_text.encode("ascii")
#     except UnicodeEncodeError:
#         return True
# 
#     return False


import itertools
import pytest
from dataproperty import calc_ascii_char_width, is_multibyte_str
    def test_normal(self, value, expected):
        assert is_multibyte_str(value) == expected


class Test_calc_ascii_char_width:
    @pytest.mark.parametrize(
        ["value", "expected"], [["吾輩は猫である", 14], ["いaろbはc", 9], ["abcdef", 6], ["", 0]]
    )
    def test_normal(self, value, expected):
        assert calc_ascii_char_width(value) == expected

    @pytest.mark.parametrize(
        ["value", "ambiguous_width"],
        itertools.product(["Ø", "α", "β", "γ", "θ", "κ", "λ", "π", "ǎ"], [1, 2]),
    )
    def test_normal_east_asian_ambiguous(self, value, ambiguous_width):
        assert calc_ascii_char_width(value, ambiguous_width) == ambiguous_width

    @pytest.mark.parametrize(
        ["value", "expected"],
        [
            [b"abcdef", TypeError],
            [None, TypeError],
            [True, TypeError],
            [1, TypeError],
            [nan, TypeError],
        ],
    )
    def test_exception(self, value, expected):
        with pytest.raises(expected):

# Path: dataproperty/_function.py
# def calc_ascii_char_width(unicode_str: str, east_asian_ambiguous_width: int = 1) -> int:
#     import unicodedata
# 
#     width = 0
#     for char in unicode_str:
#         char_width = unicodedata.east_asian_width(char)
#         if char_width in "WF":
#             width += 2
#         elif char_width == "A":
#             _validate_eaaw(east_asian_ambiguous_width)
#             width += east_asian_ambiguous_width
#         else:
#             width += 1
# 
#     return width
# 
# def is_multibyte_str(text) -> bool:
#     from typepy import StrictLevel, String
# 
#     if not String(text, strict_level=StrictLevel.MIN).is_type():
#         return False
# 
#     try:
#         unicode_text = MultiByteStrDecoder(text).unicode_str
#     except ValueError:
#         return False
# 
#     try:
#         unicode_text.encode("ascii")
#     except UnicodeEncodeError:
#         return True
# 
#     return False


# Path: test/test_str_function.py
import itertools
import pytest
from dataproperty import calc_ascii_char_width, is_multibyte_str

    def test_normal(self, value, expected):
        assert is_multibyte_str(value) == expected


class Test_calc_ascii_char_width:
    @pytest.mark.parametrize(
        ["value", "expected"], [["吾輩は猫である", 14], ["いaろbはc", 9], ["abcdef", 6], ["", 0]]
    )
    def test_normal(self, value, expected):
        assert calc_ascii_char_width(value) == expected

    @pytest.mark.parametrize(
        ["value", "ambiguous_width"],
        itertools.product(["Ø", "α", "β", "γ", "θ", "κ", "λ", "π", "ǎ"], [1, 2]),
    )
    def test_normal_east_asian_ambiguous(self, value, ambiguous_width):
        assert calc_ascii_char_width(value, ambiguous_width) == ambiguous_width

    @pytest.mark.parametrize(
        ["value", "expected"],
        [
            [b"abcdef", TypeError],
            [None, TypeError],
            [True, TypeError],
            [1, TypeError],
            [nan, TypeError],
        ],
    )
    def test_exception(self, value, expected):
        with pytest.raises(expected):

            calc_ascii_char_width(value)