forked from trishume/syntect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
Error
and Display
for all error enums by using thiserror
Also do some minor tweaks to the way errors are represented, and add basic integration tests for errors, to give a feel for how the errors behave. Fixes trishume#94
- Loading branch information
Showing
8 changed files
with
97 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::{error::Error, fmt::Display}; | ||
|
||
use syntect::{ | ||
parsing::{ParseScopeError, ParseSyntaxError}, | ||
LoadingError, | ||
}; | ||
|
||
#[test] | ||
fn loading_error_display() { | ||
assert_display(LoadingError::BadPath, "Invalid path"); | ||
|
||
assert_display( | ||
LoadingError::ParseSyntax( | ||
ParseSyntaxError::MissingMandatoryKey("main"), | ||
String::from("file.sublime-syntax"), | ||
), | ||
"file.sublime-syntax: Missing mandatory key in YAML file: main", | ||
); | ||
|
||
assert_display( | ||
LoadingError::ParseSyntax( | ||
ParseSyntaxError::RegexCompileError("[a-Z]".to_owned(), LoadingError::BadPath.into()), | ||
String::from("another-file.sublime-syntax"), | ||
), | ||
"another-file.sublime-syntax: Error while compiling regex '[a-Z]': Invalid path", | ||
); | ||
} | ||
|
||
#[test] | ||
fn parse_scope_error_display() { | ||
assert_display( | ||
ParseScopeError::TooLong, | ||
"Too long scope. Scopes can be at most 8 atoms long.", | ||
) | ||
} | ||
|
||
#[test] | ||
fn loading_error_source() { | ||
let source = std::io::Error::new(std::io::ErrorKind::Other, "this is an error string"); | ||
assert_display( | ||
LoadingError::Io(source).source().unwrap(), | ||
"this is an error string", | ||
); | ||
} | ||
|
||
/// Helper to assert that a given implementation of [Display] generates the | ||
/// expected string. | ||
fn assert_display(display: impl Display, expected_display: &str) { | ||
assert_eq!(format!("{}", display), String::from(expected_display)); | ||
} |