From efa0430624acf7c821482d896ff45cd2a9658b57 Mon Sep 17 00:00:00 2001 From: kwantam Date: Tue, 14 Apr 2015 15:26:19 -0400 Subject: [PATCH] rename to unicode-width ; add tests from libcoretests for char.width() --- Cargo.toml | 8 ++++---- README.md | 6 +++--- src/lib.rs | 32 +++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 156a5a2..d68b90f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "unicode_width" +name = "unicode-width" version = "0.0.1" authors = ["kwantam "] -homepage = "https://github.com/unicode-rs/unicode_width" -repository = "https://github.com/unicode-rs/unicode_width" -documentation = "https://unicode-rs.github.io/unicode_width/unicode_width" +homepage = "https://github.com/unicode-rs/unicode-width" +repository = "https://github.com/unicode-rs/unicode-width" +documentation = "https://unicode-rs.github.io/unicode-width/unicode-width" license = "MIT/Apache-2.0" keywords = ["text", "width", "unicode"] readme = "README.md" diff --git a/README.md b/README.md index a7485a3..9f05880 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# unicode_width +# unicode-width Determine displayed width of `char` and `str` types according to [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/) rules. -[![Build Status](https://travis-ci.org/unicode-rs/unicode_width.svg?branch=master)](https://travis-ci.org/unicode-rs/unicode_width) +[![Build Status](https://travis-ci.org/unicode-rs/unicode-width.svg?branch=master)](https://travis-ci.org/unicode-rs/unicode-width) ```rust extern crate unicode_width; @@ -21,4 +21,4 @@ fn main() { } ``` -[Documentation](http://unicode-rs.github.io/unicode_width/unicode_width/) +[Documentation](http://unicode-rs.github.io/unicode-width/unicode-width/) diff --git a/src/lib.rs b/src/lib.rs index 229c7bf..6b450a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ //! //! ```toml //! [dependencies] -//! unicode_width = "0.0.1" +//! unicode-width = "0.0.1" //! ``` #![deny(missing_docs, unsafe_code)] @@ -144,4 +144,34 @@ mod tests { assert_eq!(UnicodeWidthChar::width('\u{2081}'), Some(1)); assert_eq!('\u{2081}'.width_cjk(), Some(2)); } + + #[test] + fn test_char2() { + use super::UnicodeWidthChar; + use core::option::Option::{Some, None}; + + assert_eq!(UnicodeWidthChar::width('\x00'),Some(0)); + assert_eq!('\x00'.width_cjk(),Some(0)); + + assert_eq!(UnicodeWidthChar::width('\x0A'),None); + assert_eq!('\x0A'.width_cjk(),None); + + assert_eq!(UnicodeWidthChar::width('w'),Some(1)); + assert_eq!('w'.width_cjk(),Some(1)); + + assert_eq!(UnicodeWidthChar::width('h'),Some(2)); + assert_eq!('h'.width_cjk(),Some(2)); + + assert_eq!(UnicodeWidthChar::width('\u{AD}'),Some(1)); + assert_eq!('\u{AD}'.width_cjk(),Some(1)); + + assert_eq!(UnicodeWidthChar::width('\u{1160}'),Some(0)); + assert_eq!('\u{1160}'.width_cjk(),Some(0)); + + assert_eq!(UnicodeWidthChar::width('\u{a1}'),Some(1)); + assert_eq!('\u{a1}'.width_cjk(),Some(2)); + + assert_eq!(UnicodeWidthChar::width('\u{300}'),Some(0)); + assert_eq!('\u{300}'.width_cjk(),Some(0)); + } }