Skip to content

Commit 52bf734

Browse files
committed
test: Add tests for multiple annotations per line
1 parent 23de02d commit 52bf734

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

tests/formatter.rs

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,3 +732,168 @@ error
732732
let renderer = Renderer::plain().anonymized_line_numbers(false);
733733
assert_data_eq!(renderer.render(input).to_string(), expected);
734734
}
735+
736+
#[test]
737+
fn two_single_line_same_line() {
738+
let source = r#"bar = { version = "0.1.0", optional = true }"#;
739+
let input = Level::Error.title("unused optional dependency").snippet(
740+
Snippet::source(source)
741+
.origin("Cargo.toml")
742+
.line_start(4)
743+
.annotation(
744+
Level::Error
745+
.span(0..3)
746+
.label("I need this to be really long so I can test overlaps"),
747+
)
748+
.annotation(
749+
Level::Info
750+
.span(27..42)
751+
.label("This should also be long but not too long"),
752+
),
753+
);
754+
let expected = str![[r#"
755+
error: unused optional dependency
756+
--> Cargo.toml:4:1
757+
|
758+
4 | bar = { version = "0.1.0", optional = true }
759+
| ^^^ I need this to be really long so I can test overlaps
760+
| --------------- info: This should also be long but not too long
761+
|
762+
"#]];
763+
let renderer = Renderer::plain().anonymized_line_numbers(false);
764+
assert_data_eq!(renderer.render(input).to_string(), expected);
765+
}
766+
767+
#[test]
768+
fn multi_and_single() {
769+
let source = r#"bar = { version = "0.1.0", optional = true }
770+
this is another line
771+
so is this
772+
bar = { version = "0.1.0", optional = true }
773+
"#;
774+
let input = Level::Error.title("unused optional dependency").snippet(
775+
Snippet::source(source)
776+
.line_start(4)
777+
.annotation(
778+
Level::Error
779+
.span(41..119)
780+
.label("I need this to be really long so I can test overlaps"),
781+
)
782+
.annotation(
783+
Level::Info
784+
.span(27..42)
785+
.label("This should also be long but not too long"),
786+
),
787+
);
788+
let expected = str![[r#"
789+
error: unused optional dependency
790+
|
791+
4 | bar = { version = "0.1.0", optional = true }
792+
| __________________________________________^
793+
| --------------- info: This should also be long but not too long
794+
5 | | this is another line
795+
6 | | so is this
796+
7 | | bar = { version = "0.1.0", optional = true }
797+
| |__________________________________________^ I need this to be really long so I can test overlaps
798+
|
799+
"#]];
800+
let renderer = Renderer::plain();
801+
assert_data_eq!(renderer.render(input).to_string(), expected);
802+
}
803+
804+
#[test]
805+
fn two_multi_and_single() {
806+
let source = r#"bar = { version = "0.1.0", optional = true }
807+
this is another line
808+
so is this
809+
bar = { version = "0.1.0", optional = true }
810+
"#;
811+
let input = Level::Error.title("unused optional dependency").snippet(
812+
Snippet::source(source)
813+
.line_start(4)
814+
.annotation(
815+
Level::Error
816+
.span(41..119)
817+
.label("I need this to be really long so I can test overlaps"),
818+
)
819+
.annotation(
820+
Level::Error
821+
.span(8..102)
822+
.label("I need this to be really long so I can test overlaps"),
823+
)
824+
.annotation(
825+
Level::Info
826+
.span(27..42)
827+
.label("This should also be long but not too long"),
828+
),
829+
);
830+
let expected = str![[r#"
831+
error: unused optional dependency
832+
|
833+
4 | bar = { version = "0.1.0", optional = true }
834+
| __________________________________________^
835+
| _________^
836+
| --------------- info: This should also be long but not too long
837+
5 | || this is another line
838+
6 | || so is this
839+
7 | || bar = { version = "0.1.0", optional = true }
840+
| ||__________________________________________^ I need this to be really long so I can test overlaps
841+
| ||_________________________^ I need this to be really long so I can test overlaps
842+
|
843+
"#]];
844+
let renderer = Renderer::plain();
845+
assert_data_eq!(renderer.render(input).to_string(), expected);
846+
}
847+
848+
#[test]
849+
fn three_multi_and_single() {
850+
let source = r#"bar = { version = "0.1.0", optional = true }
851+
this is another line
852+
so is this
853+
bar = { version = "0.1.0", optional = true }
854+
this is another line
855+
"#;
856+
let input = Level::Error.title("unused optional dependency").snippet(
857+
Snippet::source(source)
858+
.line_start(4)
859+
.annotation(
860+
Level::Error
861+
.span(41..119)
862+
.label("I need this to be really long so I can test overlaps"),
863+
)
864+
.annotation(
865+
Level::Error
866+
.span(8..102)
867+
.label("I need this to be really long so I can test overlaps"),
868+
)
869+
.annotation(
870+
Level::Error
871+
.span(48..126)
872+
.label("I need this to be really long so I can test overlaps"),
873+
)
874+
.annotation(
875+
Level::Info
876+
.span(27..42)
877+
.label("This should also be long but not too long"),
878+
),
879+
);
880+
let expected = str![[r#"
881+
error: unused optional dependency
882+
|
883+
4 | bar = { version = "0.1.0", optional = true }
884+
| __________________________________________^
885+
| _________^
886+
| --------------- info: This should also be long but not too long
887+
5 | || this is another line
888+
| ||____^
889+
6 | ||| so is this
890+
7 | ||| bar = { version = "0.1.0", optional = true }
891+
| |||__________________________________________^ I need this to be really long so I can test overlaps
892+
| |||_________________________^ I need this to be really long so I can test overlaps
893+
8 | | this is another line
894+
| |____^ I need this to be really long so I can test overlaps
895+
|
896+
"#]];
897+
let renderer = Renderer::plain();
898+
assert_data_eq!(renderer.render(input).to_string(), expected);
899+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy