add PrefixIdentifier() and some tests

This commit is contained in:
Yusur 2025-07-19 11:31:01 +02:00
parent e5ca63953d
commit 8a16fe159f
6 changed files with 162 additions and 6 deletions

38
tests/test_strtools.py Normal file
View file

@ -0,0 +1,38 @@
import unittest
from suou.strtools import PrefixIdentifier
class TestStrtools(unittest.TestCase):
def setUp(self) -> None:
...
def tearDown(self) -> None:
...
def test_PrefixIdentifier_empty(self):
pi = PrefixIdentifier(None)
self.assertEqual(pi.hello, 'hello')
self.assertEqual(pi['with spaces'], 'with spaces')
self.assertEqual(pi['\x1b\x00'], '\x1b\0')
self.assertEqual(pi.same_thing, pi['same_thing'])
with self.assertRaises(TypeError):
pi[0]
self.assertEqual(PrefixIdentifier(None), PrefixIdentifier(''))
def test_PrefixIdentifier_invalid(self):
with self.assertRaises(TypeError):
pi = PrefixIdentifier(1)
pi.hello
with self.assertRaises(TypeError):
PrefixIdentifier([99182])
with self.assertRaises(TypeError):
PrefixIdentifier(b'alpha_')