#!/usr/bin/env python3


import re
import unittest


def get_my_regex():
    return r"^\w+$"


def hit_bad_strings(val):
    """
    https://www.flake8rules.com/rules/W605.html
    https://stackoverflow.com/questions/36119167/why-doesnt-re-matchc-cat-return-true
    https://stackoverflow.com/questions/1576789/in-regex-what-does-w-mean
    https://www.codeproject.com/questions/641934/regular-expression-pattern-with-wplus-and-its-beha
    """
    if not bool(re.match(get_my_regex(), val)):
        return "hit"
    return None


def bar_the_invalid(val):
    return re.match(get_my_regex(), val)


class PythonRegexFunMatch(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def _check_for_bad_val(self, val):
        hit = hit_bad_strings(val)
        bar = bar_the_invalid(val)
        self.assertTrue(hit, hit)
        self.assertTrue(bar is None, bar)

    def _check_for_good_val(self, val):
        hit = hit_bad_strings(val)
        bar = bar_the_invalid(val)
        self.assertTrue(hit is None, hit)
        self.assertTrue(bar, bar)
        print(type(bar))

    def test_my_strings(self):
        self._check_for_bad_val("")

    def test_my_strings_semicolon(self):
        self._check_for_bad_val(";")

    def test_my_strings_closing_square_brace(self):
        self._check_for_bad_val("]")

    def test_my_strings_backslash(self):
        self._check_for_bad_val("\\")

    def test_my_strings_modulus(self):
        self._check_for_bad_val("%")

    def test_my_strings_statement(self):
        self._check_for_bad_val("; delete all my tables; ")

    def test_my_strings_statement2(self):
        self._check_for_bad_val("banana; delete all my tables;")

    def test_my_strings_statement3(self):
        self._check_for_bad_val("banana;")

    def test_my_strings_statement4(self):
        self._check_for_bad_val("banana;drop")

    def test_my_strings_trailing_modulus(self):
        self._check_for_bad_val("banana%")

    def test_my_strings_trailing_dollar(self):
        self._check_for_bad_val("banana$")

    def test_my_strings_dot(self):
        self._check_for_bad_val("b.anana")

    def test_my_strings_space1(self):
        self._check_for_bad_val("blood orange")

    def test_my_strings_space2(self):
        self._check_for_bad_val(" orange")

    def test_my_strings_space3(self):
        self._check_for_bad_val("orange ")

    def test_my_strings_alpha_and_pipe(self):
        self._check_for_bad_val("pine|apple")

    def test_my_strings_numeric(self):
        self._check_for_good_val("banana9")

    def test_my_strings_alpha(self):
        self._check_for_good_val("banana")

    def test_my_strings_capital_alpha(self):
        self._check_for_good_val("BANANA")

    def test_my_strings_alpha_and_underscore(self):
        self._check_for_good_val("pine_apple")

    def test_my_strings_underscore(self):
        self._check_for_good_val("_")

    def test_my_strings_diacretics(self):
        self._check_for_good_val("örange")


if __name__ == "__main__":
    unittest.main()
