improvement78 Add Error::ReadUtf8 with testcase.
There are 6x LATIN1 bytes in a comment.
This commit is contained in:
parent
1ee6215934
commit
ac2d169333
@ -15,6 +15,9 @@ pub enum Error {
|
||||
path: PathBuf,
|
||||
},
|
||||
|
||||
#[error("File could not be read as UTF8: {0:?}")]
|
||||
ReadUtf8(Option<PathBuf>),
|
||||
|
||||
#[error("Include error")]
|
||||
Include {
|
||||
#[from]
|
||||
|
@ -149,18 +149,21 @@ fn preprocess_inner<T: AsRef<Path>, U: AsRef<Path>, V: BuildHasher>(
|
||||
})?;
|
||||
let mut reader = BufReader::new(f);
|
||||
let mut s = String::new();
|
||||
reader.read_to_string(&mut s)?;
|
||||
|
||||
preprocess_str(
|
||||
&s,
|
||||
path,
|
||||
pre_defines,
|
||||
include_paths,
|
||||
ignore_include,
|
||||
strip_comments,
|
||||
0, // resolve_depth
|
||||
include_depth,
|
||||
)
|
||||
if let Err(_) = reader.read_to_string(&mut s) {
|
||||
Err(Error::ReadUtf8(Some(PathBuf::from(path.as_ref()))))
|
||||
} else {
|
||||
preprocess_str(
|
||||
&s,
|
||||
path,
|
||||
pre_defines,
|
||||
include_paths,
|
||||
ignore_include,
|
||||
strip_comments,
|
||||
0, // resolve_depth
|
||||
include_depth,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct SkipNodes<'a> {
|
||||
@ -1113,6 +1116,25 @@ mod tests {
|
||||
};
|
||||
} // }}}
|
||||
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn err_ReadUtf8() { // {{{
|
||||
match preprocess_usualargs("err_ReadUtf8.sv").unwrap_err() {
|
||||
Error::ReadUtf8(path) => {
|
||||
assert_eq!(
|
||||
path,
|
||||
Some(PathBuf::from(format!(
|
||||
"{}/testcases/err_ReadUtf8.sv",
|
||||
env::var("CARGO_MANIFEST_DIR").unwrap(),
|
||||
)))
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
panic!("Error::ReadUtf8 not raised.");
|
||||
}
|
||||
};
|
||||
} // }}}
|
||||
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn IEEE18002017_keywords_if2_13642005() { // {{{
|
||||
|
4
sv-parser-pp/testcases/err_ReadUtf8.sv
Normal file
4
sv-parser-pp/testcases/err_ReadUtf8.sv
Normal file
@ -0,0 +1,4 @@
|
||||
// In the next comment, there are non-UTF8 bytes.
|
||||
module M;
|
||||
// Non-UTF8:XñòóôõöX
|
||||
endmodule
|
Loading…
x
Reference in New Issue
Block a user