use crate::extensions::token_stream::PathTokenStreamFromStr;
use proc_macro2::TokenStream;
use quote::ToTokens;
pub trait PathExt {
fn eq_str(&self, s: &str) -> bool;
#[allow(dead_code)]
fn eq_tokens(&self, tokens: &TokenStream) -> bool;
#[allow(dead_code)]
fn eq_path(&self, other: &Self) -> bool;
}
impl PathExt for syn::Path {
fn eq_str(&self, s: &str) -> bool {
self.to_token_stream().to_string()
== PathTokenStreamFromStr::new(s).to_token_stream().to_string()
}
fn eq_tokens(&self, tokens: &TokenStream) -> bool {
self.to_token_stream().to_string() == tokens.to_string()
}
fn eq_path(&self, other: &Self) -> bool {
self.to_token_stream().to_string() == other.to_token_stream().to_string()
}
}
#[cfg(test)]
mod tests {
use super::*;
use syn::parse_quote;
#[test]
fn test_eq_str() {
let path: syn::Path = parse_quote! { foo::bar::baz };
assert!(path.eq_str("foo::bar::baz"));
}
#[test]
fn test_eq_tokens() {
let path: syn::Path = parse_quote! { foo::bar::baz };
assert!(path.eq_tokens(&parse_quote! { foo::bar::baz }));
}
#[test]
fn test_eq_path() {
let path: syn::Path = parse_quote! { foo::bar::baz };
assert!(path.eq_path(&parse_quote! { foo::bar::baz }));
}
}