1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::fmt;
#[derive(Clone, Copy)]
pub struct SourceLocation {
pub file: &'static str,
pub line: u32,
pub column: u32,
}
impl SourceLocation {
pub fn new(file: &'static str, line: u32, column: u32) -> SourceLocation {
SourceLocation { file, line, column }
}
}
impl fmt::Display for SourceLocation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}:{}", self.file, self.line, self.column)
}
}
impl fmt::Debug for SourceLocation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
#[cfg(test)]
mod tests {
use super::SourceLocation;
use crate::matchers::be_equal_to;
#[test]
fn location_should_display_correct_text() {
let location = SourceLocation::new("path/to/file.rs", 9, 8);
expect!(location.to_string()).to(be_equal_to("path/to/file.rs:9:8"));
}
}