Skip to content

Commit

Permalink
change definition of highlight_keywords_in_body
Browse files Browse the repository at this point in the history
Signed-off-by: Zhenbo Li <[email protected]>
  • Loading branch information
Endle committed Apr 16, 2024
1 parent aa3bb95 commit 5568c23
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions fire_seq_search_server/tests/unit_test_post_query.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
use fire_seq_search_server::post_query::highlighter::{highlight_keywords_in_body, highlight_sentence_with_keywords, locate_single_keyword, split_body_to_blocks, wrap_text_at_given_spots};
use fire_seq_search_server::generate_server_info_for_test;

fn get_english_text() -> String {
std::fs::read_to_string("tests/resource/pages/International Language, Past, Present & Future by Walter John Clark.md")
.expect("Should have been able to read the file")
}
fn highlight_keywords_in_body_old_2024_apr(body:&str, terms: &Vec<String>, limit:usize) ->String {
let mut server_info = generate_server_info_for_test();
server_info.show_summary_single_line_chars_limit = limit;
highlight_keywords_in_body(body, terms, &server_info)
}

#[test]
fn test_empty_key() {
let text = "Hello World";
let v = Vec::new();

let r = highlight_keywords_in_body(text, &v, 120);
let r = highlight_keywords_in_body_old_2024_apr(text, &v, 120);
assert_eq!(4,4);

assert_eq!(&r, "");
Expand All @@ -22,15 +28,15 @@ fn test_empty_key() {
fn test_highlight_wrap() {
let contents = "使用 git shallow clone 下载并编译 Thunderbird".to_string();
let v = vec![String::from("thunderbird")];
let r = highlight_keywords_in_body(&contents, &v, 120);
let r = highlight_keywords_in_body_old_2024_apr(&contents, &v, 120);
assert_eq!(&r, "使用 git shallow clone 下载并编译 <span class=\"fireSeqSearchHighlight\">Thunderbird</span>");
}

#[test]
fn test_highlight_latex() {
let contents = "$\\vec{q_i}^T \\vec{a_j}, i<j$".to_string();
let v = vec![String::from("vec")];
let r = highlight_keywords_in_body(&contents, &v, 120);
let r = highlight_keywords_in_body_old_2024_apr(&contents, &v, 120);
println!("{:?}", &r);
}
#[test]
Expand Down Expand Up @@ -87,4 +93,4 @@ fn test_wrap_text_at_given_spots() {
assert_eq!(right-left, 6);
}
let _r = wrap_text_at_given_spots(&contents, &mats, 320);
}
}

0 comments on commit 5568c23

Please sign in to comment.