Skip to content

Commit a8208f6

Browse files
authored
test: Move DecodeError tests closer to the implementation (#1227)
1 parent 0b9af3b commit a8208f6

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

prost/src/error.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,33 @@ impl fmt::Display for UnknownEnumValue {
148148

149149
#[cfg(feature = "std")]
150150
impl std::error::Error for UnknownEnumValue {}
151+
152+
#[cfg(test)]
153+
mod test {
154+
use super::*;
155+
156+
#[test]
157+
fn test_push() {
158+
let mut decode_error = DecodeError::new("something failed");
159+
decode_error.push("Foo bad", "bar.foo");
160+
decode_error.push("Baz bad", "bar.baz");
161+
162+
assert_eq!(
163+
decode_error.to_string(),
164+
"failed to decode Protobuf message: Foo bad.bar.foo: Baz bad.bar.baz: something failed"
165+
);
166+
}
167+
168+
#[cfg(feature = "std")]
169+
#[test]
170+
fn test_into_std_io_error() {
171+
let decode_error = DecodeError::new("something failed");
172+
let std_io_error = std::io::Error::from(decode_error);
173+
174+
assert_eq!(std_io_error.kind(), std::io::ErrorKind::InvalidData);
175+
assert_eq!(
176+
std_io_error.to_string(),
177+
"failed to decode Protobuf message: something failed"
178+
);
179+
}
180+
}

tests/src/decode_error.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,3 @@ fn test_decode_error_any() {
148148
"failed to decode Protobuf message: unexpected type URL.type_url: expected type URL: \"type.googleapis.com/google.protobuf.Timestamp\" (got: \"non-existing-url\")"
149149
);
150150
}
151-
152-
#[test]
153-
fn test_push() {
154-
let mut decode_error = prost::DecodeError::new("something failed");
155-
decode_error.push("Foo bad", "bar.foo");
156-
decode_error.push("Baz bad", "bar.baz");
157-
158-
assert_eq!(
159-
decode_error.to_string(),
160-
"failed to decode Protobuf message: Foo bad.bar.foo: Baz bad.bar.baz: something failed"
161-
);
162-
}
163-
164-
#[cfg(feature = "std")]
165-
#[test]
166-
fn test_into_std_io_error() {
167-
let decode_error = prost::DecodeError::new("something failed");
168-
let std_io_error = std::io::Error::from(decode_error);
169-
170-
assert_eq!(std_io_error.kind(), std::io::ErrorKind::InvalidData);
171-
assert_eq!(
172-
std_io_error.to_string(),
173-
"failed to decode Protobuf message: something failed"
174-
);
175-
}

0 commit comments

Comments
 (0)