11
22const path = require ( 'path' ) ;
33
4- describe ( 'Hyperlink grammar' , function ( ) {
4+ describe ( 'Hyperlink grammar' , function ( ) {
55 let grammar = null ;
66
7- beforeEach ( function ( ) {
7+ beforeEach ( function ( ) {
8+ // TODO: All these specs rely on the ability of a grammar to tokenize a
9+ // line in isolation, which is something that a `WASMTreeSitterGrammar`
10+ // cannot do. This package will need specialized tests for the modern
11+ // Tree-sitter world the same way that most other language packages do.
12+ atom . config . set ( 'core.useTreeSitterParsers' , false ) ;
813 waitsForPromise ( ( ) => atom . packages . activatePackage ( 'language-hyperlink' ) ) ;
914
1015 runs ( ( ) => grammar = atom . grammars . grammarForScopeName ( 'text.hyperlink' ) ) ;
1116 } ) ;
1217
13- it ( 'parses the grammar' , function ( ) {
18+ it ( 'parses the grammar' , function ( ) {
1419 expect ( grammar ) . toBeTruthy ( ) ;
1520 expect ( grammar . scopeName ) . toBe ( 'text.hyperlink' ) ;
1621 } ) ;
1722
18- it ( 'parses http: and https: links' , function ( ) {
23+ it ( 'parses http: and https: links' , function ( ) {
1924 const plainGrammar = atom . grammars . selectGrammar ( ) ;
2025
2126 let { tokens} = plainGrammar . tokenizeLine ( 'http://github.com' ) ;
@@ -29,16 +34,16 @@ describe('Hyperlink grammar', function() {
2934
3035 ( { tokens} = plainGrammar . tokenizeLine ( 'https://github.com/atom/brightray_example' ) ) ;
3136 expect ( tokens [ 0 ] ) . toEqual ( { value : 'https://github.com/atom/brightray_example' , scopes : [ 'text.plain.null-grammar' , 'markup.underline.link.https.hyperlink' ] } ) ;
32- } ) ;
37+ } ) ;
3338
34- it ( 'parses http: and https: links that contains unicode characters' , function ( ) {
39+ it ( 'parses http: and https: links that contains unicode characters' , function ( ) {
3540 const plainGrammar = atom . grammars . selectGrammar ( ) ;
3641
3742 const { tokens} = plainGrammar . tokenizeLine ( 'https://sv.wikipedia.org/wiki/Mañana' ) ;
3843 expect ( tokens [ 0 ] ) . toEqual ( { value : 'https://sv.wikipedia.org/wiki/Mañana' , scopes : [ 'text.plain.null-grammar' , 'markup.underline.link.https.hyperlink' ] } ) ;
39- } ) ;
44+ } ) ;
4045
41- it ( 'parses other links' , function ( ) {
46+ it ( 'parses other links' , function ( ) {
4247 const plainGrammar = atom . grammars . selectGrammar ( ) ;
4348
4449 let { tokens} = plainGrammar . tokenizeLine ( 'mailto:noreply@example.com' ) ;
@@ -49,55 +54,57 @@ describe('Hyperlink grammar', function() {
4954
5055 ( { tokens} = plainGrammar . tokenizeLine ( 'atom://core/open/file?filename=urlEncodedFileName&line=n&column=n' ) ) ;
5156 expect ( tokens [ 0 ] ) . toEqual ( { value : 'atom://core/open/file?filename=urlEncodedFileName&line=n&column=n' , scopes : [ 'text.plain.null-grammar' , 'markup.underline.link.atom.hyperlink' ] } ) ;
52- } ) ;
57+ } ) ;
5358
54- it ( 'does not parse links in a regex string' , function ( ) {
59+ it ( 'does not parse links in a regex string' , function ( ) {
5560 const testGrammar = atom . grammars . loadGrammarSync ( path . join ( __dirname , 'fixtures' , 'test-grammar.cson' ) ) ;
5661
5762 const { tokens} = testGrammar . tokenizeLine ( 'regexp:http://github.com' ) ;
5863 expect ( tokens [ 1 ] ) . toEqual ( { value : 'http://github.com' , scopes : [ 'source.test' , 'string.regexp.test' ] } ) ;
59- } ) ;
60-
61- describe ( 'parsing PHP strings' , ( ) => it ( 'does not parse links in a regex string' , function ( ) {
62- // PHP is unique in that its root scope is `text.html.php`, meaning that even though
63- // `string - string.regexp` won't match in a regex string, `text` still will.
64- // This is the reason the injection selector is `text - string.regexp` instead.
65- // https://github.com/atom/language-php/issues/219
66-
67- waitsForPromise ( ( ) => atom . packages . activatePackage ( 'language-php' ) ) ;
68-
69- runs ( function ( ) {
70- const phpGrammar = atom . grammars . grammarForScopeName ( 'text.html.php' ) ;
64+ } ) ;
7165
72- const { tokens} = phpGrammar . tokenizeLine ( '<?php "/mailto:/" ?>' ) ;
73- expect ( tokens [ 3 ] ) . toEqual ( { value : 'mailto:' , scopes : [ 'text.html.php' , 'meta.embedded.line.php' , 'source.php' , 'string.regexp.double-quoted.php' ] } ) ; } ) ;
74- } ) ) ;
66+ describe ( 'parsing PHP strings' , ( ) => {
67+ it ( 'does not parse links in a regex string' , function ( ) {
68+ // PHP is unique in that its root scope is `text.html.php`, meaning that even though
69+ // `string - string.regexp` won't match in a regex string, `text` still will.
70+ // This is the reason the injection selector is `text - string.regexp` instead.
71+ // https://github.com/atom/language-php/issues/219
72+
73+ waitsForPromise ( ( ) => atom . packages . activatePackage ( 'language-php' ) ) ;
74+
75+ runs ( ( ) => {
76+ const phpGrammar = atom . grammars . grammarForScopeName ( 'text.html.php' ) ;
77+ const { tokens} = phpGrammar . tokenizeLine ( '<?php "/mailto:/" ?>' ) ;
78+ expect ( tokens [ 3 ] ) . toEqual ( { value : 'mailto:' , scopes : [ 'text.html.php' , 'meta.embedded.line.php' , 'source.php' , 'string.regexp.double-quoted.php' ] } ) ;
79+ } ) ;
80+ } ) ;
81+ } ) ;
7582
76- describe ( 'parsing cfml strings' , function ( ) {
77- it ( 'does not include anything between (and including) pound signs' , function ( ) {
83+ describe ( 'parsing cfml strings' , function ( ) {
84+ it ( 'does not include anything between (and including) pound signs' , function ( ) {
7885 const plainGrammar = atom . grammars . selectGrammar ( ) ;
7986 const { tokens} = plainGrammar . tokenizeLine ( 'http://github.com/#username#' ) ;
8087 expect ( tokens [ 0 ] ) . toEqual ( { value : 'http://github.com/' , scopes : [ 'text.plain.null-grammar' , 'markup.underline.link.http.hyperlink' ] } ) ;
81- } ) ;
88+ } ) ;
8289
83- it ( 'still includes single pound signs' , function ( ) {
90+ it ( 'still includes single pound signs' , function ( ) {
8491 const plainGrammar = atom . grammars . selectGrammar ( ) ;
8592 const { tokens} = plainGrammar . tokenizeLine ( 'http://github.com/atom/#start-of-content' ) ;
8693 expect ( tokens [ 0 ] ) . toEqual ( { value : 'http://github.com/atom/#start-of-content' , scopes : [ 'text.plain.null-grammar' , 'markup.underline.link.http.hyperlink' ] } ) ;
94+ } ) ;
8795 } ) ;
88- } ) ;
8996
90- describe ( 'parsing matching parentheses' , function ( ) {
91- it ( 'still includes matching parentheses' , function ( ) {
97+ describe ( 'parsing matching parentheses' , function ( ) {
98+ it ( 'still includes matching parentheses' , function ( ) {
9299 const plainGrammar = atom . grammars . selectGrammar ( ) ;
93100 const { tokens} = plainGrammar . tokenizeLine ( 'https://en.wikipedia.org/wiki/Atom_(text_editor)' ) ;
94101 expect ( tokens [ 0 ] ) . toEqual ( { value : 'https://en.wikipedia.org/wiki/Atom_(text_editor)' , scopes : [ 'text.plain.null-grammar' , 'markup.underline.link.https.hyperlink' ] } ) ;
95- } ) ;
102+ } ) ;
96103
97- it ( 'does not include wrapping parentheses' , function ( ) {
104+ it ( 'does not include wrapping parentheses' , function ( ) {
98105 const plainGrammar = atom . grammars . selectGrammar ( ) ;
99106 const { tokens} = plainGrammar . tokenizeLine ( '(https://en.wikipedia.org/wiki/Atom_(text_editor))' ) ;
100107 expect ( tokens [ 1 ] ) . toEqual ( { value : 'https://en.wikipedia.org/wiki/Atom_(text_editor)' , scopes : [ 'text.plain.null-grammar' , 'markup.underline.link.https.hyperlink' ] } ) ;
108+ } ) ;
101109 } ) ;
102110} ) ;
103- } ) ;
0 commit comments