@@ -2753,3 +2753,71 @@ fn main() {
2753
2753
let renderer = Renderer :: plain ( ) ;
2754
2754
renderer. render ( input) ;
2755
2755
}
2756
+
2757
+ #[ test]
2758
+ fn snippet_no_path ( ) {
2759
+ // Taken from: https://docs.python.org/3/library/typing.html#annotating-callable-objects
2760
+
2761
+ let source = "def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ..." ;
2762
+ let input = & [ Group :: with_title ( Level :: ERROR . title ( "" ) ) . element (
2763
+ Snippet :: source ( source) . annotation ( AnnotationKind :: Primary . span ( 4 ..12 ) . label ( "annotation" ) ) ,
2764
+ ) ] ;
2765
+
2766
+ let expected_ascii = str![ [ r#"
2767
+ error:
2768
+ |
2769
+ 1 | def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ...
2770
+ | ^^^^^^^^ annotation
2771
+ "# ] ] ;
2772
+ let renderer = Renderer :: plain ( ) ;
2773
+ assert_data_eq ! ( renderer. render( input) , expected_ascii) ;
2774
+
2775
+ let expected_unicode = str![ [ r#"
2776
+ error:
2777
+ │
2778
+ 1 │ def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ...
2779
+ ╰╴ ━━━━━━━━ annotation
2780
+ "# ] ] ;
2781
+ let renderer = Renderer :: plain ( ) . theme ( OutputTheme :: Unicode ) ;
2782
+ assert_data_eq ! ( renderer. render( input) , expected_unicode) ;
2783
+ }
2784
+
2785
+ #[ test]
2786
+ fn snippet_no_path2 ( ) {
2787
+ // Taken from: https://docs.python.org/3/library/typing.html#annotating-callable-objects
2788
+
2789
+ let source = "def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ..." ;
2790
+ let input = & [ Group :: with_title ( Level :: ERROR . title ( "" ) )
2791
+ . element (
2792
+ Snippet :: source ( source)
2793
+ . annotation ( AnnotationKind :: Primary . span ( 4 ..12 ) . label ( "annotation" ) ) ,
2794
+ )
2795
+ . element (
2796
+ Snippet :: source ( source)
2797
+ . annotation ( AnnotationKind :: Primary . span ( 4 ..12 ) . label ( "annotation" ) ) ,
2798
+ ) ] ;
2799
+
2800
+ let expected_ascii = str![ [ r#"
2801
+ error:
2802
+ |
2803
+ 1 | def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ...
2804
+ | ^^^^^^^^ annotation
2805
+ |
2806
+ 1 | def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ...
2807
+ | ^^^^^^^^ annotation
2808
+ "# ] ] ;
2809
+ let renderer = Renderer :: plain ( ) ;
2810
+ assert_data_eq ! ( renderer. render( input) , expected_ascii) ;
2811
+
2812
+ let expected_unicode = str![ [ r#"
2813
+ error:
2814
+ │
2815
+ 1 │ def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ...
2816
+ │ ━━━━━━━━ annotation
2817
+ │
2818
+ 1 │ def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: ...
2819
+ ╰╴ ━━━━━━━━ annotation
2820
+ "# ] ] ;
2821
+ let renderer = Renderer :: plain ( ) . theme ( OutputTheme :: Unicode ) ;
2822
+ assert_data_eq ! ( renderer. render( input) , expected_unicode) ;
2823
+ }
0 commit comments