# Path: pytablewriter/sanitizer/_javascript.py
# def sanitize_js_var_name(var_name: str, replacement_text: str = "") -> str:
#     """
#     Make a valid JavaScript variable name from ``var_name``.
# 
#     To make a valid name:
# 
#     - Replace invalid characters for a JavaScript variable name within
#       the ``var_name`` with the ``replacement_text``
#     - Delete invalid chars for the beginning of the variable name
#     - Append underscore (``"_"``) at the tail of the name if sanitized name
#       is one of the JavaScript reserved names
# 
#     :JavaScriptstr filename: Name to sanitize.
#     :param str replacement_text: Replacement text.
#     :return: A replacement string.
#     :rtype: str
#     :raises ValueError: If ``var_name`` or ``replacement_text`` is invalid.
# 
#     :Example:
#         :ref:`example-sanitize-var-name`
# 
#     .. note::
#         Currently, not supported Unicode variable names.
# 
#     .. seealso::
#         :py:func:`.validate_js_var_name`
#     """
# 
#     return JavaScriptVarNameSanitizer(var_name).sanitize(replacement_text)
# 
# def validate_js_var_name(var_name: str) -> None:
#     """
#     :param str var_name: Name to validate.
#     :raises pathvalidate.ValidationError (ErrorReason.INVALID_CHARACTER):
#         If the ``var_name`` is invalid as a JavaScript identifier.
#     :raises pathvalidate.ValidationError (ErrorReason.RESERVED_NAME):
#         If the ``var_name`` is equals to
#         `JavaScript reserved keywords
#         <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords>`__.
# 
#     .. note::
# 
#         Currently, not supported unicode variable names.
#     """
# 
#     JavaScriptVarNameSanitizer(var_name).validate()
# 
# Path: test/sanitizer/_common.py
# INVALID_JS_VAR_CHARS = INVALID_WIN_FILENAME_CHARS + [
#     "!",
#     "#",
#     "&",
#     "'",
#     "=",
#     "~",
#     "^",
#     "@",
#     "`",
#     "[",
#     "]",
#     "+",
#     "-",
#     ";",
#     "{",
#     "}",
#     ",",
#     ".",
#     "(",
#     ")",
#     "%",
#     " ",
#     "\t",
#     "\n",
#     "\r",
#     "\f",
#     "\v",
# ]


import itertools
import string
import pytest
from pathvalidate.error import ErrorReason, ValidationError
from pytablewriter.sanitizer import sanitize_js_var_name, validate_js_var_name
from ._common import INVALID_JS_VAR_CHARS
    def test_normal_invalid_first_char_x1(self, value, replace_text, expected):
        sanitized_name = sanitize_js_var_name(value, replace_text)
        assert sanitized_name == expected
        validate_js_var_name(sanitized_name)

    @pytest.mark.parametrize(
        ["value", "replace_text", "expected"],
        [[invalid_char * 2 + "hoge_123", "_", "hoge_123"] for invalid_char in string.digits + "_"]
        + [
            [invalid_char * 2 + "hoge_123", "a", "aahoge_123"]
            for invalid_char in string.digits + "_"
        ],
    )
    def test_normal_invalid_first_char_x2(self, value, replace_text, expected):
        sanitized_name = sanitize_js_var_name(value, replace_text)
        assert sanitized_name == expected
        validate_js_var_name(sanitized_name)

    @pytest.mark.parametrize(
        ["value", "expected"],
        [[reserved_keyword, reserved_keyword + "_"] for reserved_keyword in RESERVED_KEYWORDS],
    )
    def test_normal_reserved(self, value, expected):
        assert sanitize_js_var_name(value) == expected

    @pytest.mark.parametrize(
        ["value", "expected"], [[None, ValueError], [1, TypeError], [True, TypeError]]
    )
    def test_exception_type(self, value, expected):
        with pytest.raises(expected):

# Path: pytablewriter/sanitizer/_javascript.py
# def sanitize_js_var_name(var_name: str, replacement_text: str = "") -> str:
#     """
#     Make a valid JavaScript variable name from ``var_name``.
# 
#     To make a valid name:
# 
#     - Replace invalid characters for a JavaScript variable name within
#       the ``var_name`` with the ``replacement_text``
#     - Delete invalid chars for the beginning of the variable name
#     - Append underscore (``"_"``) at the tail of the name if sanitized name
#       is one of the JavaScript reserved names
# 
#     :JavaScriptstr filename: Name to sanitize.
#     :param str replacement_text: Replacement text.
#     :return: A replacement string.
#     :rtype: str
#     :raises ValueError: If ``var_name`` or ``replacement_text`` is invalid.
# 
#     :Example:
#         :ref:`example-sanitize-var-name`
# 
#     .. note::
#         Currently, not supported Unicode variable names.
# 
#     .. seealso::
#         :py:func:`.validate_js_var_name`
#     """
# 
#     return JavaScriptVarNameSanitizer(var_name).sanitize(replacement_text)
# 
# def validate_js_var_name(var_name: str) -> None:
#     """
#     :param str var_name: Name to validate.
#     :raises pathvalidate.ValidationError (ErrorReason.INVALID_CHARACTER):
#         If the ``var_name`` is invalid as a JavaScript identifier.
#     :raises pathvalidate.ValidationError (ErrorReason.RESERVED_NAME):
#         If the ``var_name`` is equals to
#         `JavaScript reserved keywords
#         <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords>`__.
# 
#     .. note::
# 
#         Currently, not supported unicode variable names.
#     """
# 
#     JavaScriptVarNameSanitizer(var_name).validate()
# 
# Path: test/sanitizer/_common.py
# INVALID_JS_VAR_CHARS = INVALID_WIN_FILENAME_CHARS + [
#     "!",
#     "#",
#     "&",
#     "'",
#     "=",
#     "~",
#     "^",
#     "@",
#     "`",
#     "[",
#     "]",
#     "+",
#     "-",
#     ";",
#     "{",
#     "}",
#     ",",
#     ".",
#     "(",
#     ")",
#     "%",
#     " ",
#     "\t",
#     "\n",
#     "\r",
#     "\f",
#     "\v",
# ]


# Path: test/sanitizer/test_js_var_name.py
import itertools
import string
import pytest
from pathvalidate.error import ErrorReason, ValidationError
from pytablewriter.sanitizer import sanitize_js_var_name, validate_js_var_name
from ._common import INVALID_JS_VAR_CHARS

    def test_normal_invalid_first_char_x1(self, value, replace_text, expected):
        sanitized_name = sanitize_js_var_name(value, replace_text)
        assert sanitized_name == expected
        validate_js_var_name(sanitized_name)

    @pytest.mark.parametrize(
        ["value", "replace_text", "expected"],
        [[invalid_char * 2 + "hoge_123", "_", "hoge_123"] for invalid_char in string.digits + "_"]
        + [
            [invalid_char * 2 + "hoge_123", "a", "aahoge_123"]
            for invalid_char in string.digits + "_"
        ],
    )
    def test_normal_invalid_first_char_x2(self, value, replace_text, expected):
        sanitized_name = sanitize_js_var_name(value, replace_text)
        assert sanitized_name == expected
        validate_js_var_name(sanitized_name)

    @pytest.mark.parametrize(
        ["value", "expected"],
        [[reserved_keyword, reserved_keyword + "_"] for reserved_keyword in RESERVED_KEYWORDS],
    )
    def test_normal_reserved(self, value, expected):
        assert sanitize_js_var_name(value) == expected

    @pytest.mark.parametrize(
        ["value", "expected"], [[None, ValueError], [1, TypeError], [True, TypeError]]
    )
    def test_exception_type(self, value, expected):
        with pytest.raises(expected):

            sanitize_js_var_name(value)