From 90d0c0554d53f064741f8d9213c70c618e38cb41 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Tue, 17 Dec 2024 16:44:27 -0800 Subject: [PATCH] Delete unreachable code files (#362) --- executors/rust/1.3/src/relativedatetimefmt.rs | 104 ------------------ executors/rust/src/numberfmt.rs | 88 --------------- 2 files changed, 192 deletions(-) delete mode 100644 executors/rust/1.3/src/relativedatetimefmt.rs delete mode 100644 executors/rust/src/numberfmt.rs diff --git a/executors/rust/1.3/src/relativedatetimefmt.rs b/executors/rust/1.3/src/relativedatetimefmt.rs deleted file mode 100644 index 3f1fe0cf..00000000 --- a/executors/rust/1.3/src/relativedatetimefmt.rs +++ /dev/null @@ -1,104 +0,0 @@ - // https://docs.rs/icu/1.3.2/icu/datetime/struct.DateTimeFormatter.html - -use icu::calendar::DateTime; -use icu::calendar::{buddhist::Buddhist, - chinese::Chinese, - coptic::Coptic, - dangi::Dangi, - ethopian::Ethopian, - gergorian::Gregorian, - hewbrew::Hebrew, - indian::Indian, - iso::ISO, - japanese::Japanese, - julian::Julian, - persian::Persian, - roc::Roc, - Date}; - -use icu::datetime::{options::length, DateTimeFormatter}; -// use icu::datetime::input::DateTimeInput; -use icu_provider::DataLocale; - -use icu::locid::Locale; - -use serde_json::{json, Value}; -use serde::{Deserialize,Serialize}; - -#[derive(Deserialize, Serialize, Debug)] -#[serde(rename_all = "camelCase")] -struct DateTimeFormatOptions { - date_style: Option, - time_style: Option, - time_zone: Option, - era: Option, - calendar: Option, - numbering_system: Option -} - -pub fn run_datetimeformat_test(json_obj: &Value) -> Result { - let label = &json_obj["label"].as_str().unwrap(); - - let langid: Locale = json_obj - .get("locale") - .map(|locale_name| locale_name.as_str().unwrap().parse().unwrap()) - .unwrap_or_default(); - - let data_locale = DataLocale::from(langid); - - // If there are unsupported values, return - // "unsupported" rather than an error. - let options = &json_obj["options"]; // This will be an array. - - let mut _unsupported_options: Vec<&str> = Vec::new(); - - // handle options - maybe done? - - // TODO: handle calendar - // TODO: dateStyle - // TODO: timeStyle - // TODO: timeZone - // TODO: era - // TODO: skeleton - - // Set up DT options - let dt_options = length::Bag::from_date_time_style( - length::Date::Medium, - length::Time::Short - ); - - let option_struct: DateTimeFormatOptions = - serde_json::from_str(&options.to_string()).unwrap(); - - // TODO: !!! time input in ISO format. - // let input_string = &json_obj["input_string"].as_str().unwrap(); - - // let iso_input = DateTime::try_new_iso_datetime(input_string); - - let dtf = DateTimeFormatter::try_new( - &data_locale, - dt_options.into(), - ) - .expect("Failed to create DateTimeFormatter instance."); - - // !!! TEMPORARY ! - let date_iso = DateTime::try_new_iso_datetime(2020, 9, 1, 12, 34, 28) - .expect("Failed to construct DateTime."); - let any_datetime = date_iso.to_any(); - - // !!! Calendar. - let calendar_type = gregorian; - let calendar_date = date_iso.to_calendar(calendar_type); - - // Result to stdout. - // TODO: get the date/time info from a skeleton. - let formatted_dt = dtf.format(&any_datetime).expect("should work"); - let result_string = formatted_dt.to_string(); - - Ok(json!({ - "label": label, - "result": result_string, - "actual_options": format!("{option_struct:?}, {options:?}"), - })) - -} diff --git a/executors/rust/src/numberfmt.rs b/executors/rust/src/numberfmt.rs deleted file mode 100644 index bc33531d..00000000 --- a/executors/rust/src/numberfmt.rs +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Executor provides tests for NumberFormat and DecimalFormat. - */ - -use serde_json::{json, Value}; -use writeable::Writeable; - -use icu::decimal::options; -use icu::decimal::FixedDecimalFormatter; - -use fixed_decimal::FixedDecimal; - -use icu::locid::{locale, Locale}; -use icu_provider::DataLocale; - -use std::panic; -use std::str::FromStr; - -// Support options - update when ICU4X adds support -static SUPPORTED_OPTIONS: [&str; 5] = [ - "minimumIntegerDigits", - "maximumIntegerDigits", - "minimumFractionDigits", - "maximumFractionDigits", - "RoundingMode", -]; - -// Runs decimal and number formatting given patterns or skeletons. -pub fn run_numberformat_test(json_obj: &Value) -> Result { - let provider = icu_testdata::unstable(); - - // TODO: Handle errors of missing JSON fields - let label = &json_obj["label"].as_str().unwrap(); - - // Default locale if not specified. - let langid = if json_obj.get("locale") != None { - let locale_name = &json_obj["locale"].as_str().unwrap(); - Locale::from_str(locale_name).unwrap() - } else { - locale!("und") - }; - let data_locale = DataLocale::from(langid); - - let input = &json_obj["input"].as_str().unwrap(); - - // TODO: Get the options from JSON. If there are unsupported values, return - // "unsupported" rather than an error. - let options = &json_obj["options"]; // This will be an array. - - let mut unsupported_options: Vec<&str> = Vec::new(); - // If any option is not yet supported, - for (option, _setting) in options.as_object().unwrap() { - if !SUPPORTED_OPTIONS.contains(&option.as_str()) { - unsupported_options.push(&option); - } - } - if unsupported_options.len() > 0 { - let json_result = json!({ - "label": label, - "unsupported": label, - "unsupported_options": unsupported_options - }); - return Ok(json_result); - } - - let mut options: options::FixedDecimalFormatterOptions = Default::default(); - // TODO: Use options to call operations including pad and trunc with rounding. - - // Iterator over options, applying the - - // !! A test. More options to consider! - options.grouping_strategy = options::GroupingStrategy::Min2; - - // Can this fail with invalid options? - let fdf = FixedDecimalFormatter::try_new_unstable(&provider, &data_locale, options) - .expect("Data should load successfully"); - - // Returns error if parsing the number string fails. - let input_num = input.parse::().map_err(|e| e.to_string())?; - // TODO: Can this fail? - let result_string = fdf.format(&input_num); - - // Result to stdout. - let json_result = json!({ - "label": label, - "result": result_string.write_to_string()}); - Ok(json_result) -}