in cli/src/generate/node_types.rs [710:794]
fn test_node_types_with_supertypes() {
let node_types = get_node_types(InputGrammar {
name: String::new(),
extra_tokens: Vec::new(),
external_tokens: Vec::new(),
expected_conflicts: Vec::new(),
variables_to_inline: Vec::new(),
word_token: None,
supertype_symbols: vec!["_v2".to_string()],
variables: vec![
Variable {
name: "v1".to_string(),
kind: VariableType::Named,
rule: Rule::field("f1".to_string(), Rule::named("_v2")),
},
Variable {
name: "_v2".to_string(),
kind: VariableType::Hidden,
rule: Rule::choice(vec![
Rule::named("v3"),
Rule::named("v4"),
Rule::string("*"),
]),
},
Variable {
name: "v3".to_string(),
kind: VariableType::Named,
rule: Rule::string("x"),
},
Variable {
name: "v4".to_string(),
kind: VariableType::Named,
rule: Rule::string("y"),
},
],
});
assert_eq!(
node_types[0],
NodeInfoJSON {
kind: "_v2".to_string(),
named: true,
fields: None,
children: None,
subtypes: Some(vec![
NodeTypeJSON {
kind: "*".to_string(),
named: false,
},
NodeTypeJSON {
kind: "v3".to_string(),
named: true,
},
NodeTypeJSON {
kind: "v4".to_string(),
named: true,
},
]),
}
);
assert_eq!(
node_types[1],
NodeInfoJSON {
kind: "v1".to_string(),
named: true,
subtypes: None,
children: None,
fields: Some(
vec![(
"f1".to_string(),
FieldInfoJSON {
multiple: false,
required: true,
types: vec![NodeTypeJSON {
kind: "_v2".to_string(),
named: true,
}]
}
),]
.into_iter()
.collect()
)
}
);
}