Skip to content

Commit e70bc54

Browse files
author
Zibi Braniecki
committed
Reorganize the code and add tests
1 parent 9c567cb commit e70bc54

22 files changed

+999
-329
lines changed

examples/expected_type.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate annotate_snippets;
22

33
use annotate_snippets::display_list::DisplayList;
4+
use annotate_snippets::formatter::DisplayListFormatter;
45
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
56

67
fn main() {
@@ -23,16 +24,18 @@ fn main() {
2324
SourceAnnotation {
2425
label: "".to_string(),
2526
annotation_type: AnnotationType::Error,
26-
range: (209, 211),
27+
range: (208, 210),
2728
},
2829
SourceAnnotation {
2930
label: "while parsing this struct".to_string(),
3031
annotation_type: AnnotationType::Info,
31-
range: (35, 51),
32+
range: (34, 50),
3233
},
3334
],
3435
}],
3536
};
3637

37-
println!("{}", DisplayList::from(snippet));
38+
let dl = DisplayList::from(snippet);
39+
let dlf = DisplayListFormatter::new(true);
40+
println!("{}", dlf.format(dl));
3841
}

examples/footer.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate annotate_snippets;
22

33
use annotate_snippets::display_list::DisplayList;
4+
use annotate_snippets::formatter::DisplayListFormatter;
45
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
56

67
fn main() {
@@ -26,11 +27,13 @@ fn main() {
2627
annotations: vec![SourceAnnotation {
2728
label: "expected struct `annotate_snippets::snippet::Slice`, found reference"
2829
.to_string(),
29-
range: (22, 25),
30+
range: (21, 24),
3031
annotation_type: AnnotationType::Error,
3132
}],
3233
}],
3334
};
3435

35-
println!("{}", DisplayList::from(snippet));
36+
let dl = DisplayList::from(snippet);
37+
let dlf = DisplayListFormatter::new(true);
38+
println!("{}", dlf.format(dl));
3639
}

examples/format.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate annotate_snippets;
22

33
use annotate_snippets::display_list::DisplayList;
4+
use annotate_snippets::formatter::DisplayListFormatter;
45
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
56

67
fn main() {
@@ -35,12 +36,12 @@ fn main() {
3536
SourceAnnotation {
3637
label: "expected `Option<String>` because of return type".to_string(),
3738
annotation_type: AnnotationType::Warning,
38-
range: (6, 20),
39+
range: (5, 19),
3940
},
4041
SourceAnnotation {
4142
label: "expected enum `std::option::Option`".to_string(),
4243
annotation_type: AnnotationType::Error,
43-
range: (23, 746),
44+
range: (23, 745),
4445
},
4546
],
4647
}],
@@ -52,5 +53,7 @@ fn main() {
5253
footer: vec![],
5354
};
5455

55-
println!("{}", DisplayList::from(snippet));
56+
let dl = DisplayList::from(snippet);
57+
let dlf = DisplayListFormatter::new(true);
58+
println!("{}", dlf.format(dl));
5659
}

examples/multislice.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate annotate_snippets;
22

33
use annotate_snippets::display_list::DisplayList;
4+
use annotate_snippets::formatter::DisplayListFormatter;
45
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet};
56

67
fn main() {
@@ -29,5 +30,7 @@ fn main() {
2930
],
3031
};
3132

32-
println!("{}", DisplayList::from(snippet));
33+
let dl = DisplayList::from(snippet);
34+
let dlf = DisplayListFormatter::new(true);
35+
println!("{}", dlf.format(dl));
3336
}

0 commit comments

Comments
 (0)