fix error display

This commit is contained in:
epwalsh
2019-12-12 07:02:46 -08:00
committed by MOI Anthony
parent 3bdb849bb3
commit 13df36ca55

View File

@ -15,7 +15,7 @@ impl std::error::Error for Error {}
impl fmt::Display for Error { impl fmt::Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
MissingUnkToken => write!( Error::MissingUnkToken => write!(
fmt, fmt,
"WordPiece error: Missing [UNK] token from the vocabulary" "WordPiece error: Missing [UNK] token from the vocabulary"
), ),
@ -158,3 +158,13 @@ impl Model for WordPiece {
self.vocab_r.get(&id).map(|token| token.clone()) self.vocab_r.get(&id).map(|token| token.clone())
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
assert!(format!("{}", Error::MissingUnkToken).contains("Missing [UNK] token"));
}
}