diff --git a/Cargo.lock b/Cargo.lock index c1d82265940..913c5e2deeb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1822,6 +1822,7 @@ dependencies = [ "icu_provider", "icu_segmenter_data", "itertools 0.14.0", + "ndarray", "potential_utf", "serde", "serde_json", diff --git a/components/segmenter/Cargo.toml b/components/segmenter/Cargo.toml index 84f97ca05aa..b7819163234 100644 --- a/components/segmenter/Cargo.toml +++ b/components/segmenter/Cargo.toml @@ -40,6 +40,7 @@ icu_locale = { workspace = true, optional = true } icu = { path = "../../components/icu", default-features = false } icu_properties = { path = "../properties", features = ["compiled_data"] } itertools = { workspace = true } +ndarray = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } @@ -64,3 +65,7 @@ harness = false [[test]] name = "complex_word" required-features = ["auto"] + +[[test]] +name = "cnn" +required-features = [] diff --git a/components/segmenter/tests/cnn/helper.rs b/components/segmenter/tests/cnn/helper.rs new file mode 100644 index 00000000000..6287010fa7d --- /dev/null +++ b/components/segmenter/tests/cnn/helper.rs @@ -0,0 +1,10 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +use ndarray::array; + +pub fn get_shape() -> Vec { + let a1 = array![1, 2, 3, 4]; + a1.shape().to_vec() +} diff --git a/components/segmenter/tests/cnn/main.rs b/components/segmenter/tests/cnn/main.rs new file mode 100644 index 00000000000..62fb742a905 --- /dev/null +++ b/components/segmenter/tests/cnn/main.rs @@ -0,0 +1,26 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +use serde::Deserialize; + +mod helper; + +static JSON_STR: &str = include_str!("sample.json"); + +#[test] +fn hello_world() { + println!("hello world"); + assert_eq!(helper::get_shape(), vec![4]); +} + +#[derive(Deserialize)] +struct JsonStruct { + key: String, +} + +#[test] +fn test_json() { + let json_obj: JsonStruct = serde_json::from_str(JSON_STR).unwrap(); + assert_eq!(json_obj.key, "value"); +} diff --git a/components/segmenter/tests/cnn/sample.json b/components/segmenter/tests/cnn/sample.json new file mode 100644 index 00000000000..a977d991bb0 --- /dev/null +++ b/components/segmenter/tests/cnn/sample.json @@ -0,0 +1,3 @@ +{ + "key": "value" +} \ No newline at end of file