Skip to content

Commit 904434b

Browse files
committed
east asian width test success
1 parent 50053c2 commit 904434b

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

build/ucd_generator/column.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn test_chunk(column: &Vec<usize>, a: usize, b: usize, chunk_size: usize) -> boo
2727
let b_offset = b * chunk_size;
2828

2929
for i in 0..chunk_size {
30-
if column[a_offset + i] != column[b_offset + 1] {
30+
if column[a_offset + i] != column[b_offset + i] {
3131
return false;
3232
}
3333
}

build/ucd_generator/generators.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ pub fn generate_enum_table(code_dir : &std::path::Path, name : &str, enum_values
2828
let code_path = code_dir.join(format!("{}.rs", &name));
2929
let mut fd = std::fs::File::create(&code_path)?;
3030

31+
write!(fd, "// This file was generated by the cargo-build script.\n\n")?;
32+
3133
write!(fd, "const {}_CHUNK_SIZE : usize = {};\n", upper_name, chunk_size)?;
3234
write!(fd, "const {}_COLUMN_BITS : usize = {};\n", upper_name, column_bits)?;
33-
write!(fd, "const {}_INDEX_LEN : usize = {};\n\n", upper_name, index.len())?;
35+
write!(fd, "const {}_INDEX_LEN : usize = {};\n", upper_name, index.len())?;
3436
write!(fd, "const {}_INDEX_BITS : usize = {};\n\n", upper_name, index_bits)?;
3537

3638
write!(fd, "const {}_COLUMN: [u8; {}] = [", upper_name, column_bytes.len())?;
@@ -51,21 +53,28 @@ pub fn generate_enum_table(code_dir : &std::path::Path, name : &str, enum_values
5153
}
5254
write!(fd, "\n];\n\n")?;
5355

56+
write!(fd, "/// The {} attribute for Unicode code-points.\n", camel_name)?;
5457
write!(fd, "#[derive(Debug,Clone,Copy,PartialEq)]\n")?;
55-
5658
write!(fd, "pub enum {} {{\n", camel_name)?;
5759
for (i, v) in enum_values.iter().enumerate() {
5860
write!(fd, " {} = {},\n", v, i)?;
5961
}
6062
write!(fd, "}}\n\n")?;
6163

64+
write!(fd, "/// Get the {} attribute for a Unicode code-point.\n", camel_name)?;
65+
write!(fd, "///\n")?;
66+
write!(fd, "/// # Arguments\n")?;
67+
write!(fd, "/// - `code_point` A code-point in the form of a rust `char`.\n")?;
68+
write!(fd, "///\n")?;
69+
write!(fd, "/// # Returns\n")?;
70+
write!(fd, "/// A {} attribute of the Unicode code-point.\n", camel_name)?;
6271
write!(fd, "pub const fn get_{}(code_point: char) -> {}\n", name, camel_name)?;
6372
write!(fd, "{{\n")?;
6473
write!(fd, " const INDEX_MASK : usize = (1 << {}_INDEX_BITS) - 1;\n", upper_name)?;
65-
write!(fd, " const COLUMN_MASK : usize = (1 << {}_COLUMN_BITS) - 1;\n", upper_name)?;
74+
write!(fd, " const COLUMN_MASK : usize = (1 << {}_COLUMN_BITS) - 1;\n\n", upper_name)?;
6675

6776
write!(fd, " let code_point_value = code_point as usize;\n")?;
68-
write!(fd, " let code_point_lo = code_point_value & {}_CHUNK_SIZE;\n", upper_name)?;
77+
write!(fd, " let code_point_lo = code_point_value % {}_CHUNK_SIZE;\n", upper_name)?;
6978
write!(fd, " let mut code_point_hi = code_point_value / {}_CHUNK_SIZE;\n", upper_name)?;
7079
write!(fd, " if code_point_hi > {}_INDEX_LEN - 1 {{\n", upper_name)?;
7180
write!(fd, " code_point_hi = {}_INDEX_LEN - 1;\n", upper_name)?;

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11

22
pub mod east_asian_width;
33

4+
pub use east_asian_width::EastAsianWidth;
5+
pub use east_asian_width::get_east_asian_width;
46

57
#[cfg(test)]
68
mod tests {
79
use super::*;
810

911
#[test]
1012
fn east_asian_width() {
11-
assert_eq!(east_asian_width::get_east_asian_width('a'), east_asian_width::EastAsianWidth::Na);
12-
assert_eq!(east_asian_width::get_east_asian_width('あ'), east_asian_width::EastAsianWidth::W);
13+
assert_eq!(get_east_asian_width('a'), EastAsianWidth::Na);
14+
assert_eq!(get_east_asian_width('あ'), EastAsianWidth::W);
1315
}
1416
}

0 commit comments

Comments
 (0)