@@ -483,6 +483,112 @@ mod tests {
483483 assert_eq ! ( 12 , int_loc. end( ) ) ;
484484 }
485485
486+ #[ test]
487+ fn test_sub_locations ( ) {
488+ let rbs_code = r#"class Foo < Bar end"# ;
489+ let signature = parse ( rbs_code. as_bytes ( ) ) . unwrap ( ) ;
490+
491+ let declaration = signature. declarations ( ) . iter ( ) . next ( ) . unwrap ( ) ;
492+ let Node :: Class ( class) = declaration else {
493+ panic ! ( "Expected Class" ) ;
494+ } ;
495+
496+ // Test required sub-locations
497+ let keyword_loc = class. keyword_location ( ) ;
498+ assert_eq ! ( 0 , keyword_loc. start( ) ) ;
499+ assert_eq ! ( 5 , keyword_loc. end( ) ) ;
500+
501+ let name_loc = class. name_location ( ) ;
502+ assert_eq ! ( 6 , name_loc. start( ) ) ;
503+ assert_eq ! ( 9 , name_loc. end( ) ) ;
504+
505+ let end_loc = class. end_location ( ) ;
506+ assert_eq ! ( 16 , end_loc. start( ) ) ;
507+ assert_eq ! ( 19 , end_loc. end( ) ) ;
508+
509+ // Test optional sub-location that's present
510+ let lt_loc = class. lt_location ( ) ;
511+ assert ! ( lt_loc. is_some( ) ) ;
512+ let lt = lt_loc. unwrap ( ) ;
513+ assert_eq ! ( 10 , lt. start( ) ) ;
514+ assert_eq ! ( 11 , lt. end( ) ) ;
515+
516+ // Test optional sub-location that's not present (no type params in this class)
517+ let type_params_loc = class. type_params_location ( ) ;
518+ assert ! ( type_params_loc. is_none( ) ) ;
519+ }
520+
521+ #[ test]
522+ fn test_type_alias_sub_locations ( ) {
523+ let rbs_code = r#"type foo = String"# ;
524+ let signature = parse ( rbs_code. as_bytes ( ) ) . unwrap ( ) ;
525+
526+ let declaration = signature. declarations ( ) . iter ( ) . next ( ) . unwrap ( ) ;
527+ let Node :: TypeAlias ( type_alias) = declaration else {
528+ panic ! ( "Expected TypeAlias" ) ;
529+ } ;
530+
531+ // Test required sub-locations
532+ let keyword_loc = type_alias. keyword_location ( ) ;
533+ assert_eq ! ( 0 , keyword_loc. start( ) ) ;
534+ assert_eq ! ( 4 , keyword_loc. end( ) ) ;
535+
536+ let name_loc = type_alias. name_location ( ) ;
537+ assert_eq ! ( 5 , name_loc. start( ) ) ;
538+ assert_eq ! ( 8 , name_loc. end( ) ) ;
539+
540+ let eq_loc = type_alias. eq_location ( ) ;
541+ assert_eq ! ( 9 , eq_loc. start( ) ) ;
542+ assert_eq ! ( 10 , eq_loc. end( ) ) ;
543+
544+ // Test optional sub-location that's not present (no type params)
545+ let type_params_loc = type_alias. type_params_location ( ) ;
546+ assert ! ( type_params_loc. is_none( ) ) ;
547+ }
548+
549+ #[ test]
550+ fn test_module_sub_locations ( ) {
551+ let rbs_code = r#"module Foo[T] : Bar end"# ;
552+ let signature = parse ( rbs_code. as_bytes ( ) ) . unwrap ( ) ;
553+
554+ let declaration = signature. declarations ( ) . iter ( ) . next ( ) . unwrap ( ) ;
555+ let Node :: Module ( module) = declaration else {
556+ panic ! ( "Expected Module" ) ;
557+ } ;
558+
559+ // Test required sub-locations
560+ let keyword_loc = module. keyword_location ( ) ;
561+ assert_eq ! ( 0 , keyword_loc. start( ) ) ;
562+ assert_eq ! ( 6 , keyword_loc. end( ) ) ;
563+
564+ let name_loc = module. name_location ( ) ;
565+ assert_eq ! ( 7 , name_loc. start( ) ) ;
566+ assert_eq ! ( 10 , name_loc. end( ) ) ;
567+
568+ let end_loc = module. end_location ( ) ;
569+ assert_eq ! ( 20 , end_loc. start( ) ) ;
570+ assert_eq ! ( 23 , end_loc. end( ) ) ;
571+
572+ // Test optional sub-locations that are present
573+ let type_params_loc = module. type_params_location ( ) ;
574+ assert ! ( type_params_loc. is_some( ) ) ;
575+ let tp = type_params_loc. unwrap ( ) ;
576+ assert_eq ! ( 10 , tp. start( ) ) ;
577+ assert_eq ! ( 13 , tp. end( ) ) ;
578+
579+ let colon_loc = module. colon_location ( ) ;
580+ assert ! ( colon_loc. is_some( ) ) ;
581+ let colon = colon_loc. unwrap ( ) ;
582+ assert_eq ! ( 14 , colon. start( ) ) ;
583+ assert_eq ! ( 15 , colon. end( ) ) ;
584+
585+ let self_types_loc = module. self_types_location ( ) ;
586+ assert ! ( self_types_loc. is_some( ) ) ;
587+ let st = self_types_loc. unwrap ( ) ;
588+ assert_eq ! ( 16 , st. start( ) ) ;
589+ assert_eq ! ( 19 , st. end( ) ) ;
590+ }
591+
486592 #[ test]
487593 fn test_enum_types ( ) {
488594 let rbs_code = r#"
0 commit comments