Skip to content

Commit 3eccccb

Browse files
committed
add test and docs for Type::metcher_type()
1 parent 9c6da0d commit 3eccccb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let kind = infer::get(&buf).expect("file type is known");
1212
1313
assert_eq!(kind.mime_type(), "image/jpeg");
1414
assert_eq!(kind.extension(), "jpg");
15+
assert_eq!(kind.matcher_type(), infer::MatcherType::Image);
1516
```
1617
1718
### Check file type by path
@@ -129,6 +130,16 @@ impl Type {
129130
}
130131

131132
/// Returns the type of matcher
133+
///
134+
/// # Examples
135+
///
136+
/// ```rust
137+
/// let info = infer::Infer::new();
138+
/// let buf = [0xFF, 0xD8, 0xFF, 0xAA];
139+
/// let kind = info.get(&buf).expect("file type is known");
140+
///
141+
/// assert_eq!(kind.matcher_type(), infer::MatcherType::Image);
142+
/// ```
132143
pub const fn matcher_type(&self) -> MatcherType {
133144
self.matcher_type
134145
}
@@ -613,6 +624,13 @@ mod tests {
613624
assert_eq!(kind.mime_type(), "image/jpeg");
614625
}
615626

627+
#[test]
628+
fn test_matcher_type() {
629+
let buf = [0xFF, 0xD8, 0xFF, 0xAA];
630+
let kind = crate::get(&buf).expect("file type is known");
631+
assert_eq!(kind.matcher_type(), crate::MatcherType::Image);
632+
}
633+
616634
#[cfg(feature = "alloc")]
617635
#[test]
618636
fn test_custom_matcher_ordering() {

0 commit comments

Comments
 (0)