aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_path.rs')
-rw-r--r--tests/test_path.rs56
1 files changed, 54 insertions, 2 deletions
diff --git a/tests/test_path.rs b/tests/test_path.rs
index 2ce12066..e05b52ee 100644
--- a/tests/test_path.rs
+++ b/tests/test_path.rs
@@ -2,9 +2,9 @@
mod macros;
use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
-use quote::quote;
+use quote::{quote, ToTokens};
use std::iter::FromIterator;
-use syn::{Expr, Type};
+use syn::{parse_quote, Expr, Type, TypePath};
#[test]
fn parse_interpolated_leading_component() {
@@ -50,3 +50,55 @@ fn parse_interpolated_leading_component() {
}
"###);
}
+
+#[test]
+fn print_incomplete_qpath() {
+ // qpath with `as` token
+ let mut ty: TypePath = parse_quote!(<Self as A>::Q);
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(`< Self as A > :: Q`)
+ "###);
+ assert!(ty.path.segments.pop().is_some());
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(`< Self as A > ::`)
+ "###);
+ assert!(ty.path.segments.pop().is_some());
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(`< Self >`)
+ "###);
+ assert!(ty.path.segments.pop().is_none());
+
+ // qpath without `as` token
+ let mut ty: TypePath = parse_quote!(<Self>::A::B);
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(`< Self > :: A :: B`)
+ "###);
+ assert!(ty.path.segments.pop().is_some());
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(`< Self > :: A ::`)
+ "###);
+ assert!(ty.path.segments.pop().is_some());
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(`< Self > ::`)
+ "###);
+ assert!(ty.path.segments.pop().is_none());
+
+ // normal path
+ let mut ty: TypePath = parse_quote!(Self::A::B);
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(`Self :: A :: B`)
+ "###);
+ assert!(ty.path.segments.pop().is_some());
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(`Self :: A ::`)
+ "###);
+ assert!(ty.path.segments.pop().is_some());
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(`Self ::`)
+ "###);
+ assert!(ty.path.segments.pop().is_some());
+ snapshot!(ty.to_token_stream(), @r###"
+ TokenStream(``)
+ "###);
+ assert!(ty.path.segments.pop().is_none());
+}