@@ -730,9 +730,114 @@ mod tests {
730730 kind: VariableType :: Named ,
731731 rule: Rule :: string( "x" ) ,
732732 } ,
733+ // This rule is not reachable from the start symbol
734+ // so it won't be present in the node_types
735+ Variable {
736+ name: "v3" . to_string( ) ,
737+ kind: VariableType :: Named ,
738+ rule: Rule :: string( "y" ) ,
739+ } ,
740+ ] ,
741+ } ) ;
742+
743+ assert_eq ! ( node_types. len( ) , 3 ) ;
744+
745+ assert_eq ! (
746+ node_types[ 0 ] ,
747+ NodeInfoJSON {
748+ kind: "v1" . to_string( ) ,
749+ named: true ,
750+ subtypes: None ,
751+ children: None ,
752+ fields: Some (
753+ vec![
754+ (
755+ "f1" . to_string( ) ,
756+ FieldInfoJSON {
757+ multiple: false ,
758+ required: true ,
759+ types: vec![ NodeTypeJSON {
760+ kind: "v2" . to_string( ) ,
761+ named: true ,
762+ } ]
763+ }
764+ ) ,
765+ (
766+ "f2" . to_string( ) ,
767+ FieldInfoJSON {
768+ multiple: false ,
769+ required: true ,
770+ types: vec![ NodeTypeJSON {
771+ kind: ";" . to_string( ) ,
772+ named: false ,
773+ } ]
774+ }
775+ ) ,
776+ ]
777+ . into_iter( )
778+ . collect( )
779+ )
780+ }
781+ ) ;
782+ assert_eq ! (
783+ node_types[ 1 ] ,
784+ NodeInfoJSON {
785+ kind: ";" . to_string( ) ,
786+ named: false ,
787+ subtypes: None ,
788+ children: None ,
789+ fields: None
790+ }
791+ ) ;
792+ assert_eq ! (
793+ node_types[ 2 ] ,
794+ NodeInfoJSON {
795+ kind: "v2" . to_string( ) ,
796+ named: true ,
797+ subtypes: None ,
798+ children: None ,
799+ fields: None
800+ }
801+ ) ;
802+ }
803+
804+ #[ test]
805+ fn test_node_types_simple_extras ( ) {
806+ let node_types = get_node_types ( InputGrammar {
807+ name : String :: new ( ) ,
808+ extra_symbols : vec ! [ Rule :: named( "v3" ) ] ,
809+ external_tokens : Vec :: new ( ) ,
810+ expected_conflicts : Vec :: new ( ) ,
811+ variables_to_inline : Vec :: new ( ) ,
812+ word_token : None ,
813+ supertype_symbols : vec ! [ ] ,
814+ variables : vec ! [
815+ Variable {
816+ name: "v1" . to_string( ) ,
817+ kind: VariableType :: Named ,
818+ rule: Rule :: seq( vec![
819+ Rule :: field( "f1" . to_string( ) , Rule :: named( "v2" ) ) ,
820+ Rule :: field( "f2" . to_string( ) , Rule :: string( ";" ) ) ,
821+ ] ) ,
822+ } ,
823+ Variable {
824+ name: "v2" . to_string( ) ,
825+ kind: VariableType :: Named ,
826+ rule: Rule :: string( "x" ) ,
827+ } ,
828+ // This rule is not reachable from the start symbol, but
829+ // it is reachable from the 'extra_symbols' so it
830+ // should be present in the node_types
831+ Variable {
832+ name: "v3" . to_string( ) ,
833+ kind: VariableType :: Named ,
834+ rule: Rule :: string( "y" ) ,
835+ } ,
733836 ] ,
734837 } ) ;
735838
839+ assert_eq ! ( node_types. len( ) , 4 ) ;
840+
736841 assert_eq ! (
737842 node_types[ 0 ] ,
738843 NodeInfoJSON {
@@ -790,6 +895,16 @@ mod tests {
790895 fields: None
791896 }
792897 ) ;
898+ assert_eq ! (
899+ node_types[ 3 ] ,
900+ NodeInfoJSON {
901+ kind: "v3" . to_string( ) ,
902+ named: true ,
903+ subtypes: None ,
904+ children: None ,
905+ fields: None
906+ }
907+ ) ;
793908 }
794909
795910 #[ test]
0 commit comments