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