Test UTF-8 character counting (codepoints, not bytes).
()
| 2000 | |
| 2001 | |
| 2002 | def test_unit_utf8_count(): |
| 2003 | """Test UTF-8 character counting (codepoints, not bytes).""" |
| 2004 | # ASCII strings: len == utf8_count |
| 2005 | assert sz.utf8_count("hello") == 5 |
| 2006 | assert sz.utf8_count("") == 0 |
| 2007 | assert sz.utf8_count("a") == 1 |
| 2008 | |
| 2009 | # Multi-byte UTF-8: character count != byte count |
| 2010 | assert sz.utf8_count("café") == 4 # é is 2 bytes but 1 char |
| 2011 | assert sz.utf8_count("日本語") == 3 # Each CJK char is 3 bytes |
| 2012 | assert sz.utf8_count("🎉") == 1 # Emoji is 4 bytes but 1 char |
| 2013 | assert sz.utf8_count("👨👩👧") == 5 # Family emoji: 3 people + 2 ZWJ |
| 2014 | |
| 2015 | # Mixed ASCII and multi-byte |
| 2016 | assert sz.utf8_count("hello世界") == 7 # 5 ASCII + 2 CJK |
| 2017 | assert sz.utf8_count("naïve") == 5 # ï is 2 bytes |
| 2018 | |
| 2019 | # Method form on Str |
| 2020 | assert sz.Str("café").utf8_count() == 4 |
| 2021 | |
| 2022 | # Bytes input |
| 2023 | assert sz.utf8_count(b"caf\xc3\xa9") == 4 # café in UTF-8 bytes |
| 2024 | |
| 2025 | # Various multi-byte sequences |
| 2026 | assert sz.utf8_count("αβγδ") == 4 # Greek letters (2 bytes each) |
| 2027 | assert sz.utf8_count("АБВГ") == 4 # Cyrillic letters (2 bytes each) |
| 2028 | assert sz.utf8_count("𐍈") == 1 # Gothic letter (4 bytes) |
| 2029 | |
| 2030 | |
| 2031 | def test_utf8_splitlines_iter(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…