-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update string iter to not copy strings * add rune width * add missing tests
- Loading branch information
1 parent
bf7e1d0
commit 7cd2dfe
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from gojo.unicode import UnicodeString | ||
from tests.wrapper import MojoTest | ||
|
||
|
||
fn test_unicode_string(): | ||
var test = MojoTest("Testing unicode.UnicodeString") | ||
var s = UnicodeString("𡨸漢𡨸漢") | ||
test.assert_equal(s.bytecount(), 14) | ||
test.assert_equal(len(s), 4) | ||
|
||
var i = 0 | ||
var results = List[String]("𡨸", "漢", "𡨸", "漢") | ||
for c in s: | ||
test.assert_equal(String(c), results[i]) | ||
i += 1 | ||
|
||
test.assert_equal(String(s[:1]), "𡨸") | ||
test.assert_equal(String(s[:2]), "𡨸漢") | ||
# test.assert_equal(String(s[:-1]), "𡨸漢𡨸漢") | ||
|
||
|
||
fn main(): | ||
test_unicode_string() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from gojo.unicode import string_width, rune_width, UnicodeString | ||
from tests.wrapper import MojoTest | ||
|
||
|
||
fn test_string_width(): | ||
var test = MojoTest("Testing unicode.string_width and unicode.rune_width") | ||
var ascii = "Hello, World!" | ||
var s: String = "𡨸漢𡨸漢" | ||
test.assert_equal(string_width(s), 8) | ||
test.assert_equal(string_width(ascii), 13) | ||
|
||
for r in UnicodeString(s): | ||
test.assert_equal(rune_width(ord(String(r))), 2) | ||
|
||
for r in UnicodeString(ascii): | ||
test.assert_equal(rune_width(ord(String(r))), 1) | ||
|
||
|
||
fn main(): | ||
test_string_width() |