@@ -1662,4 +1662,97 @@ ${caret}
16621662 // SKIP this is covered by tree-sitter-php, not this grammar
16631663 // it("tokenizes trailing comma in use statements", () => {});
16641664 } ) ;
1665+
1666+ describe ( "classes" , ( ) => {
1667+ it ( "tokenizes class declarations" , ( ) => {
1668+ editor . setContent ( "class Test { /* stuff */ }" ) ;
1669+
1670+ expect ( editor ) . toHaveScopesAtPosition (
1671+ [ 1 , 0 ] ,
1672+ [ "source.php" , "meta.class.php" , "storage.type.class.php" ]
1673+ ) ;
1674+ expect ( editor ) . toHaveScopesAtPosition (
1675+ [ 1 , 5 ] ,
1676+ [ "source.php" , "meta.class.php" ]
1677+ ) ;
1678+ expect ( editor ) . toHaveScopesAtPosition (
1679+ [ 1 , 6 ] ,
1680+ [ "source.php" , "meta.class.php" , "entity.name.type.class.php" ]
1681+ ) ;
1682+ expect ( editor ) . toHaveScopesAtPosition (
1683+ [ 1 , 10 ] ,
1684+ [ "source.php" , "meta.class.php" ]
1685+ ) ;
1686+ expect ( editor ) . toHaveScopesAtPosition (
1687+ [ 1 , 11 ] ,
1688+ [
1689+ "source.php" ,
1690+ "meta.class.php" ,
1691+ // FIXME TM doesn't include this, TS does
1692+ "meta.class.body.php" ,
1693+ "punctuation.definition.class.begin.bracket.curly.php"
1694+ ]
1695+ ) ;
1696+ expect ( editor ) . toHaveScopesAtPosition (
1697+ [ 1 , 12 ] ,
1698+ [ "source.php" , "meta.class.php" , "meta.class.body.php" ]
1699+ ) ;
1700+ // /*
1701+ expect ( editor ) . toHaveScopesAtPosition (
1702+ [ 1 , 13 ] ,
1703+ [
1704+ "source.php" ,
1705+ "meta.class.php" ,
1706+ "meta.class.body.php" ,
1707+ "comment.block.php"
1708+ // FIXME how to select & scope this?
1709+ // "punctuation.definition.comment.php"
1710+ ]
1711+ ) ;
1712+ expect ( editor ) . toHaveScopesAtPosition (
1713+ [ 1 , 25 ] ,
1714+ [
1715+ "source.php" ,
1716+ "meta.class.php" ,
1717+ // FIXME TM doesn't include this, TS does
1718+ "meta.class.body.php" ,
1719+ "punctuation.definition.class.end.bracket.curly.php"
1720+ ]
1721+ ) ;
1722+ } ) ;
1723+
1724+ it ( "tokenizes class instantiation" , ( ) => {
1725+ editor . setContent ( "$a = new ClassName();" ) ;
1726+
1727+ // new
1728+ expect ( editor ) . toHaveScopesAtPosition (
1729+ [ 1 , 5 ] ,
1730+ [ "source.php" , "keyword.other.new.php" ]
1731+ ) ;
1732+ // ' '
1733+ expect ( editor ) . toHaveScopesAtPosition ( [ 1 , 8 ] , [ "source.php" ] ) ;
1734+ // ClassName
1735+ expect ( editor ) . toHaveScopesAtPosition (
1736+ [ 1 , 9 ] ,
1737+ [ "source.php" , "support.class.php" ]
1738+ ) ;
1739+ // (
1740+ expect ( editor ) . toHaveScopesAtPosition (
1741+ [ 1 , 18 ] ,
1742+ // FIXME I wonder if punctuation.definition.arguments.begin.bracket.round.php
1743+ // would be more correct: these are surrounding arguments to a new instance
1744+ [ "source.php" , "punctuation.definition.begin.bracket.round.php" ]
1745+ ) ;
1746+ // )
1747+ expect ( editor ) . toHaveScopesAtPosition (
1748+ [ 1 , 19 ] ,
1749+ [ "source.php" , "punctuation.definition.end.bracket.round.php" ]
1750+ ) ;
1751+ // ;
1752+ expect ( editor ) . toHaveScopesAtPosition (
1753+ [ 1 , 20 ] ,
1754+ [ "source.php" , "punctuation.terminator.expression.php" ]
1755+ ) ;
1756+ } ) ;
1757+ } ) ;
16651758} ) ;
0 commit comments