Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Commit acff387

Browse files
committed
move impl from test/file_utilities to test_utilities
1 parent af254a2 commit acff387

7 files changed

Lines changed: 35 additions & 40 deletions

File tree

cli/tests/file_utilities/mod.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.

cli/tests/localize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::process::{Command, Output};
22

33
use tempfile::TempDir;
44

5-
mod file_utilities;
5+
use test_utilities;
66

77
#[test]
88
fn succeeds_with_mapping() {
@@ -111,7 +111,7 @@ fn assert_status_and_stdout(output: Output) {
111111
}
112112

113113
fn assert_output_files(temp_dir: TempDir, expected_output_dir_path: &str) {
114-
file_utilities::assert_eq_of_file_contents_to_either_or(
114+
test_utilities::file::assert_eq_of_file_contents_to_either_or(
115115
&format!("{}/to_localize_1.csv", temp_dir.path().to_str().unwrap()),
116116
&format!("{}/es_fr.csv", expected_output_dir_path),
117117
&format!("{}/fr_es.csv", expected_output_dir_path),

cli/tests/localized.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use tempfile::TempDir;
55

66
use test_utilities;
77

8-
mod file_utilities;
9-
108
#[test]
119
fn succeeds_with_mapping() {
1210
execute_with_copied_sample_res(
@@ -70,7 +68,7 @@ fn warns_if_nothing_new_localized() {
7068
"run",
7169
"localized",
7270
"--res-dir",
73-
&output_res_path.clone(),
71+
&output_res_path,
7472
"--input-file",
7573
"./tests_data/localized/warn/input/localized.csv",
7674
])
@@ -194,12 +192,12 @@ fn assert_status_and_stdout(output: Output) {
194192
}
195193

196194
fn assert_output_files(output_res_path: String) {
197-
file_utilities::assert_eq_of_file_contents(
195+
test_utilities::file::assert_eq_of_file_contents(
198196
"./tests_data/localized/success/output/french_strings.xml",
199197
&format!("{}/values-fr/strings.xml", output_res_path),
200198
);
201199

202-
file_utilities::assert_eq_of_file_contents(
200+
test_utilities::file::assert_eq_of_file_contents(
203201
"./tests_data/localized/success/output/spanish_strings.xml",
204202
&format!("{}/values-es/strings.xml", output_res_path),
205203
);

core/src/localized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ mod tests {
240240

241241
xml_writer::write(&mut zh_strings.file, chinese_android_strings.clone()).unwrap();
242242

243-
fs::create_dir_all(localized_dir_path.clone()).unwrap();
243+
fs::create_dir_all(localized_dir_path).unwrap();
244244
let mut localized_file = File::create(localized_file_path.clone()).unwrap();
245245
localized_file
246246
.write_all(

core/src/validate/formatter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ mod tests {
199199
}],
200200
}),
201201
missing_strings_error: Some(missing_strings::MissingStrings {
202-
extra_in_default_locale: vec![default_s1.clone(), default_s2.clone()],
203-
extra_in_foreign_locale: vec![spanish_s1.clone(), spanish_s2.clone()],
202+
extra_in_default_locale: vec![default_s1, default_s2],
203+
extra_in_foreign_locale: vec![spanish_s1, spanish_s2],
204204
}),
205205
},
206206
];

core/src/validate/validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ mod tests {
239239

240240
Some(missing_strings::MissingStrings {
241241
extra_in_foreign_locale: vec![],
242-
extra_in_default_locale: vec![default_s1.clone()],
242+
extra_in_default_locale: vec![default_s1],
243243
})
244244
} else {
245245
missing_strings_error_for_fr = None;

test_utilities/src/file.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::eq;
12
use std::fs::File;
23
use std::io::Read;
34
use std::io::Write;
@@ -14,3 +15,28 @@ pub fn write_content<P: AsRef<Path>, S: Into<String>>(file_path: P, content: S)
1415
let mut file = File::create(file_path).unwrap();
1516
file.write_all(content.into().as_bytes()).unwrap();
1617
}
18+
19+
pub fn assert_eq_of_file_contents(actual_file_path: &str, expected_file_path: &str) {
20+
let actual_file_lines = read_file_contents_as_lines(actual_file_path);
21+
let expected_file_lines = read_file_contents_as_lines(expected_file_path);
22+
assert_eq!(actual_file_lines, expected_file_lines)
23+
}
24+
25+
pub fn assert_eq_of_file_contents_to_either_or(
26+
actual_file_path: &str,
27+
expected_file_path1: &str,
28+
expected_file_path2: &str,
29+
) {
30+
eq::assert_eq_to_either_or(
31+
read_file_contents_as_lines(actual_file_path),
32+
read_file_contents_as_lines(expected_file_path1),
33+
read_file_contents_as_lines(expected_file_path2),
34+
);
35+
}
36+
37+
fn read_file_contents_as_lines(file_path: &str) -> Vec<String> {
38+
// By default, the writers we employ, use \n as line terminator which
39+
// wouldn't match when run on Windows! To work around this, we are using
40+
// lines instead (`String#lines` takes care of handling both \n & \r\n)
41+
read_content(file_path).lines().map(String::from).collect()
42+
}

0 commit comments

Comments
 (0)