Skip to content

Commit 46dd24b

Browse files
committed
Cleanup and add tests to improve coverage
1 parent 54926e6 commit 46dd24b

File tree

7 files changed

+93
-1
lines changed

7 files changed

+93
-1
lines changed

src/config/errors.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,62 @@ impl Display for ConfigError {
6363
}
6464
}
6565
}
66+
67+
#[cfg(test)]
68+
mod tests {
69+
use claims::{assert_none, assert_some_eq};
70+
71+
use super::*;
72+
73+
#[test]
74+
fn new() {
75+
let err = ConfigError::new("name", "input", ConfigErrorCause::InvalidBoolean);
76+
assert_eq!(err.name, "name");
77+
assert_some_eq!(err.input, "input");
78+
assert_eq!(err.cause, ConfigErrorCause::InvalidBoolean);
79+
}
80+
81+
#[test]
82+
fn new_with_optional_input_with_input() {
83+
let err =
84+
ConfigError::new_with_optional_input("name", Some(String::from("input")), ConfigErrorCause::InvalidBoolean);
85+
assert_eq!(err.name, "name");
86+
assert_some_eq!(err.input, "input");
87+
assert_eq!(err.cause, ConfigErrorCause::InvalidBoolean);
88+
}
89+
90+
#[test]
91+
fn new_with_optional_input_without_input() {
92+
let err = ConfigError::new_with_optional_input("name", None, ConfigErrorCause::InvalidBoolean);
93+
assert_eq!(err.name, "name");
94+
assert_none!(err.input);
95+
assert_eq!(err.cause, ConfigErrorCause::InvalidBoolean);
96+
}
97+
98+
#[test]
99+
fn new_read_error() {
100+
let err = ConfigError::new_read_error("name", ConfigErrorCause::InvalidBoolean);
101+
assert_eq!(err.name, "name");
102+
assert_none!(err.input);
103+
assert_eq!(err.cause, ConfigErrorCause::InvalidBoolean);
104+
}
105+
106+
#[test]
107+
fn display_valid_input_with_input() {
108+
let err = ConfigError::new("name", "input", ConfigErrorCause::InvalidBoolean);
109+
110+
assert_eq!(
111+
format!("{err}"),
112+
"Provided value 'input' is invalid for 'name': The input provided is not a valid boolean value."
113+
);
114+
}
115+
#[test]
116+
fn display_valid_input_without_input() {
117+
let err = ConfigError::new_read_error("name", ConfigErrorCause::InvalidBoolean);
118+
119+
assert_eq!(
120+
format!("{err}"),
121+
"Provided value is invalid for 'name': The input provided is not a valid boolean value."
122+
);
123+
}
124+
}

src/display.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//! performance should only be used in test code.
1010
1111
mod color_mode;
12-
#[cfg(not(tarpaulin_include))]
1312
mod crossterm;
1413
mod display_color;
1514
mod error;

src/display/crossterm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(not(tarpaulin_include))]
12
use std::io::{stdout, BufWriter, Stdout, Write};
23

34
use crossterm::{

src/git/commit_diff_loader.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ mod tests {
167167
use super::*;
168168
use crate::{git::Origin, test_helpers::with_temp_repository};
169169

170+
#[cfg(not(tarpaulin_include))]
170171
fn _format_status(status: &FileStatus) -> String {
171172
let s = match status.status() {
172173
Status::Added => "Added",
@@ -181,6 +182,7 @@ mod tests {
181182
format!("Status {s}")
182183
}
183184

185+
#[cfg(not(tarpaulin_include))]
184186
fn _format_file_mode(mode: FileMode) -> String {
185187
String::from(match mode {
186188
FileMode::Normal => "n",
@@ -190,6 +192,7 @@ mod tests {
190192
})
191193
}
192194

195+
#[cfg(not(tarpaulin_include))]
193196
fn _format_paths(status: &FileStatus) -> String {
194197
let source_mode = _format_file_mode(status.source_mode());
195198
let source_binary = if status.source_is_binary() { ",b" } else { "" };
@@ -211,6 +214,7 @@ mod tests {
211214
}
212215
}
213216

217+
#[cfg(not(tarpaulin_include))]
214218
#[allow(clippy::string_slice)]
215219
fn _format_diff_line(line: &DiffLine) -> String {
216220
let origin = match line.origin() {
@@ -240,6 +244,7 @@ mod tests {
240244
}
241245
}
242246

247+
#[cfg(not(tarpaulin_include))]
243248
fn _assert_commit_diff(diff: &CommitDiff, expected: &[String]) {
244249
let mut actual = vec![];
245250
for status in diff.file_statuses() {
@@ -274,6 +279,7 @@ mod tests {
274279
};
275280
}
276281

282+
#[cfg(not(tarpaulin_include))]
277283
fn write_normal_file(repository: &crate::git::Repository, name: &str, contents: &[&str]) {
278284
let root = repository.repo_path().parent().unwrap().to_path_buf();
279285

@@ -285,6 +291,7 @@ mod tests {
285291
repository.add_path_to_index(PathBuf::from(name).as_path()).unwrap();
286292
}
287293

294+
#[cfg(not(tarpaulin_include))]
288295
fn remove_path(repository: &crate::git::Repository, name: &str) {
289296
let root = repository.repo_path().parent().unwrap().to_path_buf();
290297

@@ -296,13 +303,15 @@ mod tests {
296303
.unwrap();
297304
}
298305

306+
#[cfg(not(tarpaulin_include))]
299307
fn create_commit(repository: &crate::git::Repository) {
300308
let sig = git2::Signature::new("name", "[email protected]", &git2::Time::new(1_609_459_200, 0)).unwrap();
301309
repository
302310
.create_commit_on_index("refs/heads/main", &sig, &sig, "title")
303311
.unwrap();
304312
}
305313

314+
#[cfg(not(tarpaulin_include))]
306315
fn diff_from_head(repository: &crate::git::Repository, options: &CommitDiffLoaderOptions) -> CommitDiff {
307316
let id = repository.commit_id_from_ref("refs/heads/main").unwrap();
308317
let loader = CommitDiffLoader::new(repository.repository(), options);

src/input/event.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ mod tests {
6969

7070
use super::*;
7171

72+
#[test]
73+
fn from_key_event() {
74+
let key_event = KeyEvent::new(KeyCode::Null, KeyModifiers::empty());
75+
let event = Event::from(key_event);
76+
assert_eq!(event, Event::Key(key_event));
77+
}
78+
7279
#[test]
7380
fn from_crossterm_key_event() {
7481
let event = Event::from(ct_event::Event::Key(ct_event::KeyEvent::new(

src/modules/list/tests/toggle_option.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ fn on_fixup_keep_message_with_editor() {
3535
);
3636
}
3737

38+
#[test]
39+
fn on_existing_option_remove_option() {
40+
testers::module(
41+
&["fixup -c aaa c1"],
42+
&[Event::from(StandardEvent::FixupKeepMessageWithEditor)],
43+
|mut test_context| {
44+
let mut module = create_list(&create_config(), test_context.take_todo_file());
45+
_ = test_context.activate(&mut module, State::List);
46+
_ = test_context.handle_all_events(&mut module);
47+
let todo_file = module.todo_file.lock();
48+
let line = todo_file.get_line(0).unwrap();
49+
assert_none!(line.option());
50+
},
51+
);
52+
}
53+
3854
#[test]
3955
fn after_select_line() {
4056
testers::module(

src/todo_file/history/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(not(tarpaulin_include))]
12
use claims::assert_some_eq;
23

34
use super::*;

0 commit comments

Comments
 (0)