import unittest
from username_safety.checker import UsernameChecker

class TestUsernameChecker(unittest.TestCase):
    def setUp(self):
        self.checker = UsernameChecker()

    def test_length(self):
        self.assertTrue(self.checker.check_length("valid")[0])
        self.assertFalse(self.checker.check_length("no")[0])
        self.assertFalse(self.checker.check_length("thisiswaytoolongforausernamewhichshouldfail")[0])

    def test_unsafe_chars(self):
        self.assertTrue(self.checker.check_unsafe_chars("valid_user-123")[0])
        self.assertFalse(self.checker.check_unsafe_chars("invalid user")[0])
        self.assertFalse(self.checker.check_unsafe_chars("user@name")[0])

    def test_profanity(self):
        self.assertTrue(self.checker.check_profanity("cleanuser")[0])
        self.assertFalse(self.checker.check_profanity("shit123")[0])

    def test_similarity(self):
        self.assertTrue(self.checker.check_similarity("different", "John Doe")[0])
        self.assertFalse(self.checker.check_similarity("johndoe", "John Doe")[0])

    def test_validate(self):
        valid, _ = self.checker.validate("gooduser")
        self.assertTrue(valid)

        valid, errors = self.checker.validate("badword", real_name="Bad Word")
        self.assertFalse(valid)
        self.assertTrue(len(errors) > 0)

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