use super::super::*;
use crate::types::Value;
fn midb(text: &str, start: f64, num_bytes: f64) -> Value {
midb_fn(&[
Value::Text(text.to_string()),
Value::Number(start),
Value::Number(num_bytes),
])
}
#[test]
fn start_counts_characters_while_length_counts_bytes() {
assert_eq!(midb("aあb", 2.0, 2.0), Value::Text("あ".to_string()));
}
#[test]
fn start_past_last_character_of_dbcs_text_is_empty() {
assert_eq!(midb("熊本", 3.0, 2.0), Value::Text(String::new()));
assert_eq!(midb("熊本", 3.0, 4.0), Value::Text(String::new()));
}
#[test]
fn byte_offset_fed_start_past_character_count_is_empty() {
assert_eq!(midb("农历新年", 5.0, 2.0), Value::Text(String::new()));
}
#[test]
fn length_stays_in_dbcs_bytes() {
assert_eq!(midb("熊本", 1.0, 2.0), Value::Text("熊".to_string()));
}
#[test]
fn ascii_is_unaffected() {
assert_eq!(midb("Hello", 2.0, 3.0), Value::Text("ell".to_string()));
assert_eq!(
midb("hello world", 7.0, 100.0),
Value::Text("world".to_string())
);
}
#[test]
fn a_character_is_taken_whole_until_the_budget_is_met() {
assert_eq!(midb("あab", 1.0, 1.0), Value::Text("あ".to_string()));
assert_eq!(midb("あい", 1.0, 2.0), Value::Text("あ".to_string()));
assert_eq!(midb("あい", 1.0, 3.0), Value::Text("あい".to_string()));
assert_eq!(midb("aあ", 1.0, 2.0), Value::Text("aあ".to_string()));
}
#[test]
fn zero_byte_budget_is_empty() {
assert_eq!(midb("あい", 1.0, 0.0), Value::Text(String::new()));
assert_eq!(midb("hello", 1.0, 0.0), Value::Text(String::new()));
}