use jay_lib::fns::fn_str; #[test] fn del_mid_test(){ let s=r#"
自然语言处理 | (30) 文本相似度计算与文本匹配问题_sdu_hao的博客-CSDN博客_文本相似度匹配"#; if let Ok(after_del)=fn_str::del_mid_str(" ICON=\"","\">",s){ assert_eq!(r#"
"#.to_string(),after_del); } if let Ok(after_del)=fn_str::del_mid_str(" ADD_DATE=\"","\">",s){ assert_eq!(r#"
"#.to_string(),after_del); } let s=r#"
文本的匹配 - 简书"#; if let Ok(after_del)=fn_str::del_mid_str(" ADD_DATE=\"","\">",s) { assert_eq!(r#"
"#.to_string(),after_del); } } #[test] fn get_mid_test(){ let s=r#"
CS 97SI: Introduction to Programming Contests"#; if let Ok(get)=fn_str::get_mid_str("HREF=\"","\"",s){ assert_eq!(r#"http://web.stanford.edu/class/cs97si/"#.to_string(),get); } if let Ok(get)=fn_str::get_mid_str("\">","",s){ assert_eq!(r#"CS 97SI: Introduction to Programming Contests"#.to_string(),get); } } #[test] fn english(){ assert_eq!(false,fn_str::check_word("")); assert_eq!(false,fn_str::check_word("123 eng")); assert_eq!(false,fn_str::check_word("what is it")); assert_eq!(true,fn_str::check_word("hello")); assert_eq!(true,fn_str::check_word("It's")); } #[test] fn zh(){ assert_eq!(false,fn_str::check_zh("".to_string())); assert_eq!(true,fn_str::check_zh("中".to_string())); assert_eq!(true,fn_str::check_zh("go 中".to_string())); assert_eq!(true,fn_str::check_zh("裏".to_string())); } #[test] fn digit(){ assert_eq!(false,fn_str::is_number("".to_string())); assert_eq!(true,fn_str::is_number("1".to_string())); assert_eq!(false,fn_str::is_number("1 1".to_string())); assert_eq!(true,fn_str::is_number("789".to_string())); } #[test] fn capitalize_first_test(){ let s=fn_str::capitalize_first("hello world"); assert_eq!("Hello world",s); } #[test] fn first_word_test(){ let s=fn_str::first_word("hello, world"); assert_eq!(Some("hello".to_string()),s); assert_eq!(None,fn_str::first_word("")); assert_eq!(Some("hello".to_string()),fn_str::first_word("hello world")); assert_eq!(Some("hello".to_string()),fn_str::first_word("hello789 world")); assert_eq!(Some("It's".to_string()),fn_str::first_word("It's ok!")); }