@@ -9,13 +9,66 @@ describe("Tree-sitter PHP grammar", () => {
99 await atom . packages . activatePackage ( "language-php" ) ;
1010 await atom . packages . activatePackage ( "language-html" ) ;
1111 editor = await atom . workspace . open ( "foo.php" ) ;
12- editor . setContent = setContent ;
1312 } ) ;
1413
1514 beforeEach ( function ( ) {
16- this . addMatchers ( { toHaveScopesAtPosition} ) ;
15+ this . addMatchers ( { toHaveScopesAtPosition } ) ;
1716 } ) ;
1817
19-
18+ describe ( "loading the grammar" , ( ) => {
19+ it ( 'loads the wrapper HTML grammar' , ( ) => {
20+ embeddingGrammar = atom . grammars . grammarForScopeName ( "text.html.php" ) ;
21+ expect ( embeddingGrammar ) . toBeTruthy ( ) ;
22+ expect ( embeddingGrammar . scopeName ) . toBe ( "text.html.php" ) ;
23+ expect ( embeddingGrammar . constructor . name ) . toBe ( "TreeSitterGrammar" ) ;
24+ // FIXME how to test that all selectors were loaded correctly? Invalid
25+ // selectors may generate errors and it would be great to catch those here.
2026
21- } )
27+ // injections
28+ expect ( embeddingGrammar . injectionPointsByType . template ) . toBeTruthy ( ) ;
29+ expect ( embeddingGrammar . injectionPointsByType . php ) . toBeTruthy ( ) ;
30+ } )
31+ } ) ;
32+
33+ describe ( "shebang" , ( ) => {
34+ it ( "recognises shebang on the first line of document" , ( ) => {
35+ editor . setText ( dedent `
36+ #!/usr/bin/env php
37+ <?php echo "test"; ?>
38+ ` ) ;
39+
40+ // expect(editor).toHaveScopesAtPosition([0, 0], "#!", ["text.html.php", "comment.line.shebang.php", "punctuation.definition.comment.php"], true);
41+ expect ( editor ) . toHaveScopesAtPosition ( [ 0 , 1 ] , "#!" , [ "text.html.php" , "comment.line.shebang.php" ,
42+ // FIXME following scopes differ from TM
43+ 'source.html'
44+ ] , true ) ;
45+ expect ( editor ) . toHaveScopesAtPosition ( [ 0 , 2 ] , "/usr/bin/env php" , [ "text.html.php" , "comment.line.shebang.php" ,
46+ // FIXME following scopes differ from TM
47+ 'source.html'
48+ ] , true ) ;
49+ expect ( editor ) . toHaveScopesAtPosition ( [ 1 , 0 ] , "<?php" , [ "text.html.php" ,
50+ // "meta.embedded.line.php", "punctuation.section.embedded.begin.php"
51+ ] , true ) ;
52+ expect ( editor ) . toHaveScopesAtPosition ( [ 1 , 1 ] , "<?php" , [ "text.html.php" , "meta.embedded.line.php" , "punctuation.section.embedded.begin.php" ,
53+ // FIXME following scopes differ from TM
54+ 'source.php'
55+ ] , true ) ;
56+ } ) ;
57+
58+ it ( "does not recognize shebang on any of the other lines" , ( ) => {
59+ editor . setText ( dedent `
60+
61+ #!/usr/bin/env php
62+ <?php echo "test"; ?>
63+ ` ) ;
64+
65+ expect ( editor ) . toHaveScopesAtPosition ( [ 1 , 0 ] , "#!" , [ "text.html.php" ] , true ) ;
66+ expect ( editor ) . toHaveScopesAtPosition ( [ 1 , 1 ] , "#!" , [ "text.html.php" ,
67+ // FIXME following scopes differ from TM
68+ 'meta.embedded.line.php' ,
69+ 'source.php' ,
70+ 'punctuation.section.embedded.begin.php'
71+ ] , true ) ;
72+ } ) ;
73+ } ) ;
74+ } ) ;
0 commit comments