MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / test_unit_utf8_count

Function test_unit_utf8_count

scripts/test_stringzilla.py:2002–2028  ·  view source on GitHub ↗

Test UTF-8 character counting (codepoints, not bytes).

()

Source from the content-addressed store, hash-verified

2000
2001
2002def 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
2031def test_utf8_splitlines_iter():

Callers

nothing calls this directly

Calls 1

utf8_countMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…