@@ -1571,4 +1571,119 @@ module Outer
15711571 end
15721572 end
15731573 end
1574+
1575+ def test_parse__class_alias_without_type_name
1576+ result = parse ( <<~RUBY )
1577+ MyString = String #: class-alias
1578+ RUBY
1579+
1580+ assert_empty result . diagnostics
1581+
1582+ result . declarations [ 0 ] . tap do |decl |
1583+ assert_instance_of RBS ::AST ::Ruby ::Declarations ::ClassModuleAliasDecl , decl
1584+ assert_equal RBS ::TypeName . parse ( "MyString" ) , decl . new_name
1585+ assert_equal RBS ::TypeName . parse ( "String" ) , decl . infered_old_name
1586+ assert_instance_of RBS ::AST ::Ruby ::Annotations ::ClassAliasAnnotation , decl . annotation
1587+ assert_nil decl . annotation . type_name
1588+ assert_equal RBS ::TypeName . parse ( "String" ) , decl . old_name
1589+ assert_nil decl . leading_comment
1590+ end
1591+ end
1592+
1593+ def test_parse__class_alias_with_type_name
1594+ result = parse ( <<~RUBY )
1595+ # Alias for the standard Object class
1596+ MyObject = some_object #: class-alias Object
1597+ RUBY
1598+
1599+ assert_empty result . diagnostics
1600+
1601+ result . declarations [ 0 ] . tap do |decl |
1602+ assert_instance_of RBS ::AST ::Ruby ::Declarations ::ClassModuleAliasDecl , decl
1603+ assert_equal RBS ::TypeName . parse ( "MyObject" ) , decl . new_name
1604+ assert_nil decl . infered_old_name
1605+ assert_instance_of RBS ::AST ::Ruby ::Annotations ::ClassAliasAnnotation , decl . annotation
1606+ assert_equal RBS ::TypeName . parse ( "Object" ) , decl . annotation . type_name
1607+ assert_equal RBS ::TypeName . parse ( "Object" ) , decl . old_name
1608+ assert_equal "Alias for the standard Object class" , decl . leading_comment . as_comment . string
1609+ end
1610+ end
1611+
1612+ def test_parse__module_alias_without_type_name
1613+ result = parse ( <<~RUBY )
1614+ MyKernel = Kernel #: module-alias
1615+ RUBY
1616+
1617+ assert_empty result . diagnostics
1618+
1619+ result . declarations [ 0 ] . tap do |decl |
1620+ assert_instance_of RBS ::AST ::Ruby ::Declarations ::ClassModuleAliasDecl , decl
1621+ assert_equal RBS ::TypeName . parse ( "MyKernel" ) , decl . new_name
1622+ assert_equal RBS ::TypeName . parse ( "Kernel" ) , decl . infered_old_name
1623+ assert_instance_of RBS ::AST ::Ruby ::Annotations ::ModuleAliasAnnotation , decl . annotation
1624+ assert_nil decl . annotation . type_name
1625+ assert_equal RBS ::TypeName . parse ( "Kernel" ) , decl . old_name
1626+ assert_nil decl . leading_comment
1627+ end
1628+ end
1629+
1630+ def test_parse__module_alias_with_type_name
1631+ result = parse ( <<~RUBY )
1632+ # Alias for Enumerable module
1633+ MyEnum = some_enumerable #: module-alias Enumerable
1634+ RUBY
1635+
1636+ assert_empty result . diagnostics
1637+
1638+ result . declarations [ 0 ] . tap do |decl |
1639+ assert_instance_of RBS ::AST ::Ruby ::Declarations ::ClassModuleAliasDecl , decl
1640+ assert_equal RBS ::TypeName . parse ( "MyEnum" ) , decl . new_name
1641+ assert_nil decl . infered_old_name
1642+ assert_instance_of RBS ::AST ::Ruby ::Annotations ::ModuleAliasAnnotation , decl . annotation
1643+ assert_equal RBS ::TypeName . parse ( "Enumerable" ) , decl . annotation . type_name
1644+ assert_equal RBS ::TypeName . parse ( "Enumerable" ) , decl . old_name
1645+ assert_equal "Alias for Enumerable module" , decl . leading_comment . as_comment . string
1646+ end
1647+ end
1648+
1649+ def test_parse__class_alias_with_skip_annotation
1650+ result = parse ( <<~RUBY )
1651+ # @rbs skip
1652+ MyString = String #: class-alias
1653+ RUBY
1654+
1655+ assert_empty result . diagnostics
1656+
1657+ assert_equal 0 , result . declarations . size
1658+ end
1659+
1660+ def test_error__class_alias_non_constant_without_type_name
1661+ result = parse ( <<~RUBY )
1662+ MyString = some_function() #: class-alias
1663+ RUBY
1664+
1665+ assert_equal 1 , result . diagnostics . size
1666+ assert_any! ( result . diagnostics ) do |diagnostic |
1667+ assert_instance_of RBS ::InlineParser ::Diagnostic ::ClassModuleAliasDeclarationMissingTypeName , diagnostic
1668+ assert_equal ": class-alias" , diagnostic . location . source
1669+ assert_equal "Class name is missing in class alias declaration" , diagnostic . message
1670+ end
1671+
1672+ assert_empty result . declarations
1673+ end
1674+
1675+ def test_error__module_alias_non_constant_without_type_name
1676+ result = parse ( <<~RUBY )
1677+ MyModule = some_function() #: module-alias
1678+ RUBY
1679+
1680+ assert_equal 1 , result . diagnostics . size
1681+ assert_any! ( result . diagnostics ) do |diagnostic |
1682+ assert_instance_of RBS ::InlineParser ::Diagnostic ::ClassModuleAliasDeclarationMissingTypeName , diagnostic
1683+ assert_equal ": module-alias" , diagnostic . location . source
1684+ assert_equal "Module name is missing in module alias declaration" , diagnostic . message
1685+ end
1686+
1687+ assert_empty result . declarations
1688+ end
15741689end
0 commit comments