Skip to content

Commit

Permalink
[core][tui] Update dep to latest unicode-width crate
Browse files Browse the repository at this point in the history
This change to unicode-width 2.0.0 breaks lots of tests because it
changes the width values of certain emoji. The tests have been updated
to reflect this.

To make even more robust tests, perhaps in the future, it might be good
to store the width of characters used in variables, rather than hard
coding their values.
  • Loading branch information
nazmulidris committed Oct 19, 2024
1 parent 414022e commit 50d5e89
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 81 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
- [v0.3.1 2024-04-17](#v031-2024-04-17)
- [v0.3.0 2024-04-15](#v030-2024-04-15)
- [r3bl_ansi_color](#r3bl_ansi_color)
- [v0.7.0 2024-10-18](#v070-2024-10-18)
- [v0.6.10 2024-09-12](#v0610-2024-09-12)
- [v0.6.9 2023-10-21](#v069-2023-10-21)
- [v0.6.8 2023-10-16](#v068-2023-10-16)
Expand Down Expand Up @@ -404,6 +405,9 @@ which can carry state around between "applets".
- Changed:
- Refactor lots of styling related code in preparation for the move to `core`. This will
make it easier to maintain and test the codebase, and clean up the dependencies.
- The latest version of `unicode-width` crate `v2.0.0` changes the widths of many of the
emoji. This requires lots of tests to be changed in order to work w/ the new constant
width values.

- Removed:
- Move the `color_wheel` module into `r3bl_core` crate. This is to ensure that it is
Expand Down Expand Up @@ -738,6 +742,9 @@ in the real world.
`console_log_impl.rs` file.
- Reorganize the `src` folder to make sure that there aren't any top level files, and that
everything is in a module. This is to make it easier to add new modules in the future.
- The latest version of `unicode-width` crate `v2.0.0` changes the widths of many of the
emoji. This requires lots of tests to be changed in order to work w/ the new constant
width values.

- Added:
- Simplify the actual logging API into a single function, and allow use of tokio
Expand Down Expand Up @@ -1088,7 +1095,10 @@ This is the first release of this crate.

## `r3bl_ansi_color`

### next-release-ansi-color
### v0.7.0 (2024-10-18)

This is part of a total reorganization of the `r3bl-open-core` repo. This is a breaking
change for almost every crate in the repo.

- Added:
- Move code from `r3bl_core`'s `term.rs` to detect whether `stdin`, `stdout`, `stderr`
Expand Down
22 changes: 11 additions & 11 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ path = "src/lib.rs"

[dependencies]
# r3bl-open-core.
r3bl_ansi_color = { path = "../ansi_color", version = "0.6.9" } # Convert between ansi and rgb.
r3bl_ansi_color = { path = "../ansi_color", version = "0.7.0" } # Convert between ansi and rgb.

# https://github.com/serde-rs/serde.
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
serde_json = "1.0.131"

# Unicode, grapheme clusters.
unicode-width = "0.1.13"
unicode-segmentation = "1.11.0"
unicode-width = "0.2.0"
unicode-segmentation = "1.12.0"

# Time
chrono = "0.4.38"
Expand Down Expand Up @@ -63,15 +63,15 @@ tracing-core = "0.1.32"

# Terminal output.
crossterm = { version = "0.28.1", features = ["event-stream"] } # EventStream
futures-util = "0.3.30" # Needed for crossterm EventStream
futures-util = "0.3.31" # Needed for crossterm EventStream

# Color gradients.
colorgrad = "0.7.0"

# Error handling.
thiserror = "1.0.63"
thiserror = "1.0.64"
miette = { version = "7.2.0", features = ["fancy"] }
pretty_assertions = "1.4.0"
pretty_assertions = "1.4.1"

# Enum to string generation.
strum = "0.26.3"
Expand All @@ -85,16 +85,16 @@ bincode = { version = "1.3.3" }
kv = { version = "0.24.0", features = ["json-value", "bincode-value"] }

# Async stream for DI and testing.
futures-core = "0.3.30"
async-stream = "0.3.5"
futures-core = "0.3.31"
async-stream = "0.3.6"

[dev-dependencies]
# for assert_eq! macro
pretty_assertions = "1.4.0"
pretty_assertions = "1.4.1"
serial_test = "3.1.1"

# Testing - temp files and folders.
tempfile = "3.12.0"
tempfile = "3.13.0"

# Bin targets for testing stdout and stderr.
assert_cmd = "2.0.16"
Expand Down
76 changes: 30 additions & 46 deletions core/src/tui_core/graphemes/test_unicode_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod tests {
assert_eq2!(u_s.len(), 11);
assert_eq2!(u_s.grapheme_cluster_segment_count, 11);
assert_eq2!(u_s.byte_size, test_string.len());
assert_eq2!(u_s.display_width, ch!(25));
assert_eq2!(u_s.display_width, ch!(15));
}

#[allow(clippy::zero_prefixed_literal)]
Expand Down Expand Up @@ -63,9 +63,9 @@ mod tests {
assert_segment(&u_s[04], 07, 01.into(), 04, 01, " ");
assert_segment(&u_s[05], 08, 02.into(), 05, 04, "📦");
assert_segment(&u_s[06], 12, 01.into(), 06, 01, " ");
assert_segment(&u_s[07], 13, 04.into(), 07, 08, "🙏🏽");
assert_segment(&u_s[07], 13, 02.into(), 07, 08, "🙏🏽");
assert_segment(&u_s[08], 21, 01.into(), 08, 01, " ");
assert_segment(&u_s[09], 22, 10.into(), 09, 26, "👨🏾‍🤝‍👨🏿");
assert_segment(&u_s[09], 22, 02.into(), 09, 26, "👨🏾‍🤝‍👨🏿");
assert_segment(&u_s[10], 48, 01.into(), 10, 01, ".");
}

Expand All @@ -92,20 +92,10 @@ mod tests {
assert_eq2!(u_s.at_display_col_index(08.into()).unwrap().string, " ");
assert_eq2!(u_s.at_display_col_index(09.into()).unwrap().string, "🙏🏽");
assert_eq2!(u_s.at_display_col_index(10.into()).unwrap().string, "🙏🏽");
assert_eq2!(u_s.at_display_col_index(11.into()).unwrap().string, "🙏🏽");
assert_eq2!(u_s.at_display_col_index(12.into()).unwrap().string, "🙏🏽");
assert_eq2!(u_s.at_display_col_index(13.into()).unwrap().string, " ");
assert_eq2!(u_s.at_display_col_index(14.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(15.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(16.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(17.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(18.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(19.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(20.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(21.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(22.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(23.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(24.into()).unwrap().string, ".");
assert_eq2!(u_s.at_display_col_index(11.into()).unwrap().string, " ");
assert_eq2!(u_s.at_display_col_index(12.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(13.into()).unwrap().string, "👨🏾‍🤝‍👨🏿");
assert_eq2!(u_s.at_display_col_index(14.into()).unwrap().string, ".");

// Spot check convert logical index to display column.
assert_eq2!(u_s.logical_index_at_display_col_index(0.into()).unwrap(), 0); // "H"
Expand Down Expand Up @@ -141,21 +131,11 @@ mod tests {
assert_eq2! {u_s.truncate_end_to_fit_width(08.into()), "Hi 😃 📦"};
assert_eq2! {u_s.truncate_end_to_fit_width(09.into()), "Hi 😃 📦 "};
assert_eq2! {u_s.truncate_end_to_fit_width(10.into()), "Hi 😃 📦 "};
assert_eq2! {u_s.truncate_end_to_fit_width(11.into()), "Hi 😃 📦 "};
assert_eq2! {u_s.truncate_end_to_fit_width(12.into()), "Hi 😃 📦 "};
assert_eq2! {u_s.truncate_end_to_fit_width(13.into()), "Hi 😃 📦 🙏🏽"};
assert_eq2! {u_s.truncate_end_to_fit_width(14.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(15.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(16.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(17.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(18.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(19.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(20.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(21.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(22.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(23.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(24.into()), "Hi 😃 📦 🙏🏽 👨🏾‍🤝‍👨🏿"};
assert_eq2! {u_s.truncate_end_to_fit_width(25.into()), "Hi 😃 📦 🙏🏽 👨🏾‍🤝‍👨🏿."};
assert_eq2! {u_s.truncate_end_to_fit_width(11.into()), "Hi 😃 📦 🙏🏽"};
assert_eq2! {u_s.truncate_end_to_fit_width(12.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(13.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_to_fit_width(14.into()), "Hi 😃 📦 🙏🏽 👨🏾‍🤝‍👨🏿"};
assert_eq2! {u_s.truncate_end_to_fit_width(15.into()), "Hi 😃 📦 🙏🏽 👨🏾‍🤝‍👨🏿."};
}

#[allow(clippy::zero_prefixed_literal)]
Expand All @@ -167,15 +147,19 @@ mod tests {
assert_eq2! {u_s.truncate_end_by_n_col(01.into()), "Hi 😃 📦 🙏🏽 👨🏾‍🤝‍👨🏿"};
assert_eq2! {u_s.truncate_end_by_n_col(02.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(03.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(04.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(05.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(06.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(07.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(08.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(09.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(10.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(11.into()), "Hi 😃 📦 🙏🏽 "};
assert_eq2! {u_s.truncate_end_by_n_col(12.into()), "Hi 😃 📦 🙏🏽"};
assert_eq2! {u_s.truncate_end_by_n_col(04.into()), "Hi 😃 📦 🙏🏽"};
assert_eq2! {u_s.truncate_end_by_n_col(05.into()), "Hi 😃 📦 "};
assert_eq2! {u_s.truncate_end_by_n_col(06.into()), "Hi 😃 📦 "};
assert_eq2! {u_s.truncate_end_by_n_col(07.into()), "Hi 😃 📦"};
assert_eq2! {u_s.truncate_end_by_n_col(08.into()), "Hi 😃 "};
assert_eq2! {u_s.truncate_end_by_n_col(09.into()), "Hi 😃 "};
assert_eq2! {u_s.truncate_end_by_n_col(10.into()), "Hi 😃"};
assert_eq2! {u_s.truncate_end_by_n_col(11.into()), "Hi "};
assert_eq2! {u_s.truncate_end_by_n_col(12.into()), "Hi "};
assert_eq2! {u_s.truncate_end_by_n_col(13.into()), "Hi"};
assert_eq2! {u_s.truncate_end_by_n_col(14.into()), "H"};
assert_eq2! {u_s.truncate_end_by_n_col(15.into()), ""};
assert_eq2! {u_s.truncate_end_by_n_col(16.into()), ""};
}

#[allow(clippy::zero_prefixed_literal)]
Expand All @@ -197,7 +181,7 @@ mod tests {
fn test_unicode_string2_insert_at_display_col() {
let test_string: String = TEST_STRING.to_string();
let u_s = UnicodeString::from(&test_string);
assert_eq!(u_s.display_width, ch!(25));
assert_eq2!(u_s.display_width, ch!(15));

// Insert "😃" at display col 1, just after `H`.
let Some((new_unicode_string, display_width_of_inserted_chunk)) =
Expand All @@ -216,14 +200,14 @@ mod tests {
fn test_unicode_string2_delete_at_display_col() {
let test_string: String = TEST_STRING.to_string();
let u_s = UnicodeString::from(&test_string);
assert_eq!(u_s.display_width, ch!(25));
assert_eq2!(u_s.display_width, ch!(15));

// Delete "i" at display col 1, just after `H`.
let Some(new_unicode_string) = u_s.delete_char_at_display_col(1.into()) else {
panic!("Failed to delete char");
};

assert_eq2! {new_unicode_string.display_width, ch!(24)};
assert_eq2! {new_unicode_string.display_width, ch!(14)};
assert_eq2! {new_unicode_string.truncate_start_by_n_col(00.into()), "H 😃 📦 🙏🏽 👨🏾‍🤝‍👨🏿."};
assert_eq2! {new_unicode_string.truncate_start_by_n_col(01.into()), " 😃 📦 🙏🏽 👨🏾‍🤝‍👨🏿."};
}
Expand All @@ -233,15 +217,15 @@ mod tests {
fn test_unicode_string2_split_at_display_col() {
let test_string: String = TEST_STRING.to_string();
let u_s = UnicodeString::from(&test_string);
assert_eq!(u_s.display_width, ch!(25));
assert_eq2!(u_s.display_width, ch!(15));

// Split at display col 4.
let Some((lhs_u_s, rhs_u_s)) = u_s.split_at_display_col(4.into()) else {
panic!("Failed to split unicode string");
};

assert_eq2! {lhs_u_s.display_width, ch!(3)};
assert_eq2! {rhs_u_s.display_width, ch!(22)};
assert_eq2! {rhs_u_s.display_width, ch!(12)};

assert_eq2! {lhs_u_s.truncate_start_by_n_col(00.into()), "Hi "};
assert_eq2! {rhs_u_s.truncate_start_by_n_col(00.into()), "😃 📦 🙏🏽 👨🏾‍🤝‍👨🏿."};
Expand Down
20 changes: 12 additions & 8 deletions tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ path = "src/lib.rs"

[dependencies]
# r3bl-open-core.
r3bl_core = { path = "../core", version = "0.9.16" } # version is requried to publish to crates.io
r3bl_macro = { path = "../macro", version = "0.9.10" } # version is requried to publish to crates.io
r3bl_ansi_color = { path = "../ansi_color", version = "0.6.10" } # version is requried to publish to crates.io
r3bl_core = { path = "../core", version = "0.9.16" } # version is requried to publish to crates.io
r3bl_macro = { path = "../macro", version = "0.9.10" } # version is requried to publish to crates.io
r3bl_ansi_color = { path = "../ansi_color", version = "0.7.0" } # version is requried to publish to crates.io

# Time
chrono = "0.4.38"
Expand All @@ -38,11 +38,11 @@ rand = "0.8.5"

# Crossterm & EventStream support.
crossterm = { version = "0.28.1", features = ["event-stream"] }
futures-util = "0.3.30"
futures-util = "0.3.31"

# https://github.com/serde-rs/serde.
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
serde_json = "1.0.131"

# strum.
strum = "0.26.3"
Expand Down Expand Up @@ -73,9 +73,13 @@ tracing-appender = "0.2.3"
tracing-core = "0.1.32"

# Error handling.
thiserror = "1.0.63"
thiserror = "1.0.64"
miette = { version = "7.2.0", features = ["fancy"] }
pretty_assertions = "1.4.0"
pretty_assertions = "1.4.1"

# Unicode, grapheme clusters.
unicode-width = "0.2.0"
unicode-segmentation = "1.12.0"

[dev-dependencies]
# - Async readline for running examples, with the source code checked out for
Expand All @@ -86,7 +90,7 @@ r3bl_terminal_async = { path = "../terminal_async" }
r3bl_test_fixtures = { path = "../test_fixtures" }

# For assert_eq2! macro.
pretty_assertions = "1.4.0"
pretty_assertions = "1.4.1"
textwrap = "0.16.1"
serial_test = "3.1.1"

Expand Down
Loading

0 comments on commit 50d5e89

Please sign in to comment.