Fix core tests

pull/136/head
Chip Senkbeil 2 years ago
parent 86ed409765
commit 6a78d9bc05
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -1533,7 +1533,7 @@ mod tests {
}
#[tokio::test]
async fn should_return_binary_match_data_if_match_is_not_utf8() {
async fn should_return_binary_match_data_if_match_is_not_utf8_but_path_is_explicit() {
let root = assert_fs::TempDir::new().unwrap();
let bin_file = root.child(make_path("file.bin"));
@ -1548,7 +1548,7 @@ mod tests {
// NOTE: We provide regex that matches an invalid UTF-8 character by disabling the u flag
// and checking for 0x9F (159)
let query = SearchQuery {
paths: vec![root.path().to_path_buf()],
paths: vec![bin_file.path().to_path_buf()],
target: SearchQueryTarget::Contents,
condition: SearchQueryCondition::regex(r"(?-u:\x9F)"),
options: Default::default(),
@ -1561,17 +1561,19 @@ mod tests {
.filter_map(|m| m.into_contents_match())
.collect::<Vec<_>>();
// NOTE: Null bytes are treated as newlines, so that shifts us to being on "line 2"
// and associated other shifts
assert_eq!(
matches,
vec![SearchQueryContentsMatch {
path: root.child(make_path("file.bin")).to_path_buf(),
lines: SearchQueryMatchData::bytes([0, 159, 146, 150, 10]),
line_number: 1,
absolute_offset: 0,
lines: SearchQueryMatchData::bytes([159, 146, 150, 10]),
line_number: 2,
absolute_offset: 1,
submatches: vec![SearchQuerySubmatch {
r#match: SearchQueryMatchData::bytes([159]),
start: 1,
end: 2,
start: 0,
end: 1,
}]
},]
);
@ -1585,6 +1587,40 @@ mod tests {
assert_eq!(rx.recv().await, None);
}
#[tokio::test]
async fn should_not_return_binary_match_data_if_match_is_not_utf8_and_not_explicit_path() {
let root = assert_fs::TempDir::new().unwrap();
let bin_file = root.child(make_path("file.bin"));
// Write some invalid bytes, a newline, and then "hello"
bin_file
.write_binary(&[0, 159, 146, 150, 10, 72, 69, 76, 76, 79])
.unwrap();
let state = SearchState::new();
let (reply, mut rx) = mpsc::channel(100);
// NOTE: We provide regex that matches an invalid UTF-8 character by disabling the u flag
// and checking for 0x9F (159)
let query = SearchQuery {
paths: vec![root.path().to_path_buf()],
target: SearchQueryTarget::Contents,
condition: SearchQueryCondition::regex(r"(?-u:\x9F)"),
options: Default::default(),
};
let search_id = state.start(query, Box::new(reply)).await.unwrap();
// Get done indicator next as there were no matches
let data = rx.recv().await;
assert_eq!(
data,
Some(DistantResponseData::SearchDone { id: search_id })
);
assert_eq!(rx.recv().await, None);
}
#[tokio::test]
async fn should_filter_searched_paths_to_only_those_are_an_allowed_file_type() {
let root = assert_fs::TempDir::new().unwrap();

Loading…
Cancel
Save