Skip to content

Allow multiple puncts in a row in NodeName #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/node/node_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ pub enum NodeNameFragment {
// In case when name contain more than one Punct in series
Empty,
}
impl NodeNameFragment {
fn peek_any(input: ParseStream) -> bool {
input.peek(Ident::peek_any) || input.peek(LitInt)
}
}

impl PartialEq<NodeNameFragment> for NodeNameFragment {
fn eq(&self, other: &NodeNameFragment) -> bool {
Expand Down Expand Up @@ -179,7 +174,7 @@ impl NodeName {
let fork = &input.fork();
let mut segments = Punctuated::<X, T>::new();

while !fork.is_empty() && NodeNameFragment::peek_any(fork) {
while !fork.is_empty() {
let ident = NodeNameFragment::parse(fork)?;
segments.push_value(ident.clone().into());

Expand Down
10 changes: 9 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use eyre::Result;
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use rstml::{
node::{KeyedAttribute, KeyedAttributeValue, Node, NodeAttribute, NodeElement, NodeType},
node::{
KeyedAttribute, KeyedAttributeValue, Node, NodeAttribute, NodeElement, NodeName, NodeType,
},
parse2, Parser, ParserConfig,
};
use syn::{parse_quote, token::Colon, Block, LifetimeParam, Pat, PatType, Token, TypeParam};
Expand Down Expand Up @@ -885,6 +887,12 @@ fn test_empty_input() -> Result<()> {
Ok(())
}

#[test]
fn test_consecutive_puncts_in_name() {
let name: NodeName = parse_quote! { a--::..d };
assert_eq!(name.to_string(), "a--::..d");
}

fn get_element(nodes: &[Node], element_index: usize) -> &NodeElement {
let Some(Node::Element(element)) = nodes.get(element_index) else {
panic!("expected element")
Expand Down