Skip to content

Commit 6602390

Browse files
author
theindigamer
committed
Add a possible issue to the README.
1 parent 9bc5375 commit 6602390

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ fn main() {
2323
}
2424
```
2525

26+
**NOTE:** The computed width values may not match the actual rendered column
27+
width. For example, the woman scientist emoji comprises of a woman emoji, a
28+
zero-width joiner and a microscope emoji.
29+
30+
```rust
31+
assert_eq!(UnicodeWidthStr::width("👩"), 2); // Woman
32+
assert_eq!(UnicodeWidthStr::width("🔬"), 2); // Microscope
33+
assert_eq!(UnicodeWidthStr::width("👩‍🔬"), 4); // Woman scientist
34+
```
35+
2636
## features
2737

2838
unicode-width does not depend on libstd, so it can be used in crates

src/tests.rs

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ fn test_str() {
108108
assert_eq!("\u{2081}\u{2082}\u{2083}\u{2084}".width_cjk(), 8);
109109
}
110110

111+
#[test]
112+
fn test_emoji() {
113+
// Example from the README.
114+
use super::UnicodeWidthStr;
115+
116+
assert_eq!(UnicodeWidthStr::width("👩"), 2); // Woman
117+
assert_eq!(UnicodeWidthStr::width("🔬"), 2); // Microscope
118+
assert_eq!(UnicodeWidthStr::width("👩‍🔬"), 4); // Woman scientist
119+
}
120+
111121
#[test]
112122
fn test_char() {
113123
use super::UnicodeWidthChar;

0 commit comments

Comments
 (0)