presently 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/presently +13 -0
- data/lib/presently/application.rb +104 -0
- data/lib/presently/clock.rb +77 -0
- data/lib/presently/display_view.rb +73 -0
- data/lib/presently/environment/application.rb +62 -0
- data/lib/presently/page.rb +38 -0
- data/lib/presently/page.xrb +31 -0
- data/lib/presently/presentation.rb +72 -0
- data/lib/presently/presentation_controller.rb +181 -0
- data/lib/presently/presenter_view.rb +264 -0
- data/lib/presently/slide.rb +148 -0
- data/lib/presently/slide_view.rb +92 -0
- data/lib/presently/state.rb +66 -0
- data/lib/presently/version.rb +9 -0
- data/lib/presently.rb +9 -0
- data/license.md +21 -0
- data/public/_components/@socketry/syntax/Syntax/CodeElement.js +337 -0
- data/public/_components/@socketry/syntax/Syntax/Errors.js +52 -0
- data/public/_components/@socketry/syntax/Syntax/Language/apache.js +49 -0
- data/public/_components/@socketry/syntax/Syntax/Language/applescript.js +157 -0
- data/public/_components/@socketry/syntax/Syntax/Language/assembly.js +42 -0
- data/public/_components/@socketry/syntax/Syntax/Language/bash-script.js +108 -0
- data/public/_components/@socketry/syntax/Syntax/Language/bash.js +32 -0
- data/public/_components/@socketry/syntax/Syntax/Language/basic.js +232 -0
- data/public/_components/@socketry/syntax/Syntax/Language/c++.js +1 -0
- data/public/_components/@socketry/syntax/Syntax/Language/c.js +1 -0
- data/public/_components/@socketry/syntax/Syntax/Language/clang.js +201 -0
- data/public/_components/@socketry/syntax/Syntax/Language/cpp.js +1 -0
- data/public/_components/@socketry/syntax/Syntax/Language/csharp.js +166 -0
- data/public/_components/@socketry/syntax/Syntax/Language/css.js +244 -0
- data/public/_components/@socketry/syntax/Syntax/Language/diff.js +24 -0
- data/public/_components/@socketry/syntax/Syntax/Language/go.js +135 -0
- data/public/_components/@socketry/syntax/Syntax/Language/haskell.js +110 -0
- data/public/_components/@socketry/syntax/Syntax/Language/html.js +69 -0
- data/public/_components/@socketry/syntax/Syntax/Language/io.js +68 -0
- data/public/_components/@socketry/syntax/Syntax/Language/java.js +134 -0
- data/public/_components/@socketry/syntax/Syntax/Language/javascript.js +89 -0
- data/public/_components/@socketry/syntax/Syntax/Language/json.js +36 -0
- data/public/_components/@socketry/syntax/Syntax/Language/lisp.js +38 -0
- data/public/_components/@socketry/syntax/Syntax/Language/lua.js +87 -0
- data/public/_components/@socketry/syntax/Syntax/Language/markdown.js +112 -0
- data/public/_components/@socketry/syntax/Syntax/Language/nginx.js +37 -0
- data/public/_components/@socketry/syntax/Syntax/Language/objective-c.js +1 -0
- data/public/_components/@socketry/syntax/Syntax/Language/ocaml.js +225 -0
- data/public/_components/@socketry/syntax/Syntax/Language/pascal.js +166 -0
- data/public/_components/@socketry/syntax/Syntax/Language/patch.js +2 -0
- data/public/_components/@socketry/syntax/Syntax/Language/perl5.js +317 -0
- data/public/_components/@socketry/syntax/Syntax/Language/php-script.js +112 -0
- data/public/_components/@socketry/syntax/Syntax/Language/php.js +18 -0
- data/public/_components/@socketry/syntax/Syntax/Language/plain.js +20 -0
- data/public/_components/@socketry/syntax/Syntax/Language/protobuf.js +77 -0
- data/public/_components/@socketry/syntax/Syntax/Language/python.js +208 -0
- data/public/_components/@socketry/syntax/Syntax/Language/ruby.js +124 -0
- data/public/_components/@socketry/syntax/Syntax/Language/scala.js +81 -0
- data/public/_components/@socketry/syntax/Syntax/Language/smalltalk.js +30 -0
- data/public/_components/@socketry/syntax/Syntax/Language/sql.js +865 -0
- data/public/_components/@socketry/syntax/Syntax/Language/super-collider.js +70 -0
- data/public/_components/@socketry/syntax/Syntax/Language/swift.js +176 -0
- data/public/_components/@socketry/syntax/Syntax/Language/xml.js +76 -0
- data/public/_components/@socketry/syntax/Syntax/Language/xrb.js +33 -0
- data/public/_components/@socketry/syntax/Syntax/Language/yaml.js +29 -0
- data/public/_components/@socketry/syntax/Syntax/Language.js +276 -0
- data/public/_components/@socketry/syntax/Syntax/Loader.js +78 -0
- data/public/_components/@socketry/syntax/Syntax/Match.js +546 -0
- data/public/_components/@socketry/syntax/Syntax/Rule.js +306 -0
- data/public/_components/@socketry/syntax/Syntax.js +356 -0
- data/public/_components/@socketry/syntax/bin/syntax-ast.js +42 -0
- data/public/_components/@socketry/syntax/examples/_template.html +53 -0
- data/public/_components/@socketry/syntax/examples/apache.html +72 -0
- data/public/_components/@socketry/syntax/examples/applescript.html +72 -0
- data/public/_components/@socketry/syntax/examples/assembly.html +74 -0
- data/public/_components/@socketry/syntax/examples/bash.html +90 -0
- data/public/_components/@socketry/syntax/examples/basic.html +87 -0
- data/public/_components/@socketry/syntax/examples/c.html +141 -0
- data/public/_components/@socketry/syntax/examples/clang.html +202 -0
- data/public/_components/@socketry/syntax/examples/csharp.html +110 -0
- data/public/_components/@socketry/syntax/examples/css-colors.html +179 -0
- data/public/_components/@socketry/syntax/examples/custom-theme.html +155 -0
- data/public/_components/@socketry/syntax/examples/diff.html +142 -0
- data/public/_components/@socketry/syntax/examples/examples.css +216 -0
- data/public/_components/@socketry/syntax/examples/go.html +413 -0
- data/public/_components/@socketry/syntax/examples/haskell.html +373 -0
- data/public/_components/@socketry/syntax/examples/html.html +316 -0
- data/public/_components/@socketry/syntax/examples/index.html +97 -0
- data/public/_components/@socketry/syntax/examples/io.html +552 -0
- data/public/_components/@socketry/syntax/examples/java.html +786 -0
- data/public/_components/@socketry/syntax/examples/javascript.html +199 -0
- data/public/_components/@socketry/syntax/examples/json.html +150 -0
- data/public/_components/@socketry/syntax/examples/lisp.html +476 -0
- data/public/_components/@socketry/syntax/examples/lua.html +737 -0
- data/public/_components/@socketry/syntax/examples/markdown.html +121 -0
- data/public/_components/@socketry/syntax/examples/mixed.html +306 -0
- data/public/_components/@socketry/syntax/examples/nginx.html +554 -0
- data/public/_components/@socketry/syntax/examples/ocaml.html +596 -0
- data/public/_components/@socketry/syntax/examples/pascal.html +762 -0
- data/public/_components/@socketry/syntax/examples/perl5.html +488 -0
- data/public/_components/@socketry/syntax/examples/php-script.html +142 -0
- data/public/_components/@socketry/syntax/examples/php.html +95 -0
- data/public/_components/@socketry/syntax/examples/plain.html +222 -0
- data/public/_components/@socketry/syntax/examples/protobuf.html +405 -0
- data/public/_components/@socketry/syntax/examples/python.html +82 -0
- data/public/_components/@socketry/syntax/examples/readme.md +79 -0
- data/public/_components/@socketry/syntax/examples/ruby.html +58 -0
- data/public/_components/@socketry/syntax/examples/scala.html +41 -0
- data/public/_components/@socketry/syntax/examples/smalltalk.html +436 -0
- data/public/_components/@socketry/syntax/examples/sql.html +373 -0
- data/public/_components/@socketry/syntax/examples/super-collider.html +55 -0
- data/public/_components/@socketry/syntax/examples/swift.html +176 -0
- data/public/_components/@socketry/syntax/examples/wrap-demo.html +103 -0
- data/public/_components/@socketry/syntax/examples/xml.html +112 -0
- data/public/_components/@socketry/syntax/examples/xrb.html +37 -0
- data/public/_components/@socketry/syntax/examples/yaml.html +72 -0
- data/public/_components/@socketry/syntax/license.md +21 -0
- data/public/_components/@socketry/syntax/package-lock.json +834 -0
- data/public/_components/@socketry/syntax/package.json +43 -0
- data/public/_components/@socketry/syntax/readme.md +162 -0
- data/public/_components/@socketry/syntax/test/Syntax/CodeElement.js +306 -0
- data/public/_components/@socketry/syntax/test/Syntax/ErrorHandling.js +85 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/apache.js +153 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/applescript.js +198 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/assembly.js +209 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/bash-script.js +225 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/bash.js +162 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/basic.js +265 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/clang.js +390 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/csharp.js +436 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/css.js +431 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/diff.js +206 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/go.js +386 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/haskell.js +454 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/html.js +111 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/io.js +229 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/java.js +362 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/javascript.js +101 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/json.js +101 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/lisp.js +224 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/lua.js +307 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/markdown.js +163 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/nginx.js +267 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/ocaml.js +299 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/pascal.js +311 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/perl5.js +333 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/php-script.js +197 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/php.js +92 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/plain.js +327 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/protobuf.js +294 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/python.js +213 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/ruby.js +70 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/scala.js +75 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/smalltalk.js +223 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/sql.js +281 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/super-collider.js +66 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/swift.js +71 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/xml.js +170 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/xrb.js +57 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/yaml.js +123 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language.js +62 -0
- data/public/_components/@socketry/syntax/test/Syntax/Match.js +40 -0
- data/public/_components/@socketry/syntax/test/Syntax/Rule.js +251 -0
- data/public/_components/@socketry/syntax/test/Syntax.js +38 -0
- data/public/_components/@socketry/syntax/test/helpers/ast-matcher.js +90 -0
- data/public/_components/@socketry/syntax/themes/base/apache.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/applescript.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/assembly.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/bash.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/basic.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/c.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/clang.css +0 -0
- data/public/_components/@socketry/syntax/themes/base/csharp.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/css.css +22 -0
- data/public/_components/@socketry/syntax/themes/base/diff.css +48 -0
- data/public/_components/@socketry/syntax/themes/base/go.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/haskell.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/html.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/io.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/java.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/javascript.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/json.css +41 -0
- data/public/_components/@socketry/syntax/themes/base/lisp.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/lua.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/markdown.css +16 -0
- data/public/_components/@socketry/syntax/themes/base/nginx.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/ocaml.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/pascal.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/perl5.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/php-script.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/php.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/plain.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/protobuf.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/python.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/ruby.css +23 -0
- data/public/_components/@socketry/syntax/themes/base/scala.css +3 -0
- data/public/_components/@socketry/syntax/themes/base/smalltalk.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/sql.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/super-collider.css +33 -0
- data/public/_components/@socketry/syntax/themes/base/swift.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/syntax.css +63 -0
- data/public/_components/@socketry/syntax/themes/base/xml.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/xrb.css +29 -0
- data/public/_components/@socketry/syntax/themes/base/yaml.css +1 -0
- data/public/_components/@socketry/syntax/themes/theming.md +233 -0
- data/public/_components/@socketry/syntax/update-examples.js +135 -0
- data/public/_static/index.css +593 -0
- data/public/application.js +147 -0
- data/readme.md +69 -0
- data/releases.md +3 -0
- data/templates/code.xrb +12 -0
- data/templates/default.xrb +5 -0
- data/templates/image.xrb +8 -0
- data/templates/section.xrb +5 -0
- data/templates/title.xrb +8 -0
- data/templates/translation.xrb +8 -0
- data/templates/two_column.xrb +8 -0
- metadata +280 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Plain text language syntax highlighting
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {test} from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import {JSDOM} from 'jsdom';
|
|
8
|
+
import Syntax from '../../../Syntax.js';
|
|
9
|
+
|
|
10
|
+
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');
|
|
11
|
+
global.window = dom.window;
|
|
12
|
+
global.document = dom.window.document;
|
|
13
|
+
global.HTMLElement = dom.window.HTMLElement;
|
|
14
|
+
global.customElements = dom.window.customElements;
|
|
15
|
+
|
|
16
|
+
const syntax = new Syntax();
|
|
17
|
+
|
|
18
|
+
test('Plain text language can be registered', async () => {
|
|
19
|
+
const language = await syntax.getResource('plain');
|
|
20
|
+
assert.ok(language);
|
|
21
|
+
assert.equal(language.name, 'plain');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('Plain: text alias works', async () => {
|
|
25
|
+
const plainLang = await syntax.getResource('plain');
|
|
26
|
+
const textLang = await syntax.getResource('text');
|
|
27
|
+
assert.equal(plainLang.name, 'plain');
|
|
28
|
+
assert.equal(textLang.name, 'plain');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('Plain: detects HTTP URLs', async () => {
|
|
32
|
+
const language = await syntax.getResource('plain');
|
|
33
|
+
const matches = await language.getMatches(
|
|
34
|
+
syntax,
|
|
35
|
+
'Visit http://example.com for more info'
|
|
36
|
+
);
|
|
37
|
+
const links = matches.filter(m => m.type === 'href');
|
|
38
|
+
assert.ok(links.length >= 1);
|
|
39
|
+
assert.ok(links.some(l => l.value.includes('http://example.com')));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('Plain: detects HTTPS URLs', async () => {
|
|
43
|
+
const language = await syntax.getResource('plain');
|
|
44
|
+
const matches = await language.getMatches(
|
|
45
|
+
syntax,
|
|
46
|
+
'Visit https://example.com for more info'
|
|
47
|
+
);
|
|
48
|
+
const links = matches.filter(m => m.type === 'href');
|
|
49
|
+
assert.ok(links.length >= 1);
|
|
50
|
+
assert.ok(links.some(l => l.value.includes('https://example.com')));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('Plain: detects FTP URLs', async () => {
|
|
54
|
+
const language = await syntax.getResource('plain');
|
|
55
|
+
const matches = await language.getMatches(
|
|
56
|
+
syntax,
|
|
57
|
+
'Download from ftp://files.example.com'
|
|
58
|
+
);
|
|
59
|
+
const links = matches.filter(m => m.type === 'href');
|
|
60
|
+
assert.ok(links.length >= 1);
|
|
61
|
+
assert.ok(links.some(l => l.value.includes('ftp://files.example.com')));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('Plain: detects multiple URLs', async () => {
|
|
65
|
+
const language = await syntax.getResource('plain');
|
|
66
|
+
const matches = await language.getMatches(
|
|
67
|
+
syntax,
|
|
68
|
+
'Visit http://example.com and https://another.com'
|
|
69
|
+
);
|
|
70
|
+
const links = matches.filter(m => m.type === 'href');
|
|
71
|
+
assert.ok(links.length >= 2);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('Plain: detects URLs with paths', async () => {
|
|
75
|
+
const language = await syntax.getResource('plain');
|
|
76
|
+
const matches = await language.getMatches(
|
|
77
|
+
syntax,
|
|
78
|
+
'Go to http://example.com/path/to/page'
|
|
79
|
+
);
|
|
80
|
+
const links = matches.filter(m => m.type === 'href');
|
|
81
|
+
assert.ok(links.some(l => l.value.includes('/path/to/page')));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('Plain: detects URLs with query strings', async () => {
|
|
85
|
+
const language = await syntax.getResource('plain');
|
|
86
|
+
const matches = await language.getMatches(
|
|
87
|
+
syntax,
|
|
88
|
+
'Search at http://example.com/search?q=test&lang=en'
|
|
89
|
+
);
|
|
90
|
+
const links = matches.filter(m => m.type === 'href');
|
|
91
|
+
assert.ok(links.some(l => l.value.includes('?q=test')));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('Plain: detects URLs with fragments', async () => {
|
|
95
|
+
const language = await syntax.getResource('plain');
|
|
96
|
+
const matches = await language.getMatches(
|
|
97
|
+
syntax,
|
|
98
|
+
'Jump to http://example.com/page#section'
|
|
99
|
+
);
|
|
100
|
+
const links = matches.filter(m => m.type === 'href');
|
|
101
|
+
assert.ok(links.some(l => l.value.includes('#section')));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('Plain: detects URLs with ports', async () => {
|
|
105
|
+
const language = await syntax.getResource('plain');
|
|
106
|
+
const matches = await language.getMatches(
|
|
107
|
+
syntax,
|
|
108
|
+
'Connect to http://localhost:8080'
|
|
109
|
+
);
|
|
110
|
+
const links = matches.filter(m => m.type === 'href');
|
|
111
|
+
assert.ok(links.some(l => l.value.includes(':8080')));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('Plain: webLink detects URLs and creates href matches', async () => {
|
|
115
|
+
const language = await syntax.getResource('plain');
|
|
116
|
+
const text = 'Visit http://example.com for info';
|
|
117
|
+
const matches = await language.getMatches(syntax, text);
|
|
118
|
+
|
|
119
|
+
// Check that matches contain href type
|
|
120
|
+
const hrefMatches = matches.filter(m => m.type === 'href');
|
|
121
|
+
assert.ok(hrefMatches.length >= 1);
|
|
122
|
+
assert.ok(hrefMatches[0].value.includes('http://example.com'));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('Plain: webLink creates proper match types', async () => {
|
|
126
|
+
const language = await syntax.getResource('plain');
|
|
127
|
+
const text = 'Visit http://example.com';
|
|
128
|
+
const matches = await language.getMatches(syntax, text);
|
|
129
|
+
const links = matches.filter(m => m.type === 'href');
|
|
130
|
+
|
|
131
|
+
assert.ok(links.length >= 1);
|
|
132
|
+
assert.ok(links[0].expression);
|
|
133
|
+
assert.equal(links[0].expression.type, 'href');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('Plain: webLink preserves URL content', async () => {
|
|
137
|
+
const language = await syntax.getResource('plain');
|
|
138
|
+
const text = 'Before http://example.com after';
|
|
139
|
+
const matches = await language.getMatches(syntax, text);
|
|
140
|
+
const links = matches.filter(m => m.type === 'href');
|
|
141
|
+
|
|
142
|
+
assert.ok(links.length >= 1);
|
|
143
|
+
assert.ok(links[0].value.includes('http://example.com'));
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('Plain: webLink handles multiple URLs', async () => {
|
|
147
|
+
const language = await syntax.getResource('plain');
|
|
148
|
+
const text = 'First http://one.com and second https://two.com';
|
|
149
|
+
const matches = await language.getMatches(syntax, text);
|
|
150
|
+
const links = matches.filter(m => m.type === 'href');
|
|
151
|
+
|
|
152
|
+
assert.ok(links.length >= 2);
|
|
153
|
+
assert.ok(links.some(l => l.value.includes('http://one.com')));
|
|
154
|
+
assert.ok(links.some(l => l.value.includes('https://two.com')));
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('Plain: webLink handles complex URLs', async () => {
|
|
158
|
+
const language = await syntax.getResource('plain');
|
|
159
|
+
const text = 'Search http://example.com/search?q=hello world&lang=en';
|
|
160
|
+
const matches = await language.getMatches(syntax, text);
|
|
161
|
+
const links = matches.filter(m => m.type === 'href');
|
|
162
|
+
|
|
163
|
+
assert.ok(links.length >= 1);
|
|
164
|
+
assert.ok(links[0].value.includes('search'));
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('Plain: handles plain text without URLs', async () => {
|
|
168
|
+
const language = await syntax.getResource('plain');
|
|
169
|
+
const text = 'This is just plain text with no links';
|
|
170
|
+
const matches = await language.getMatches(syntax, text);
|
|
171
|
+
const links = matches.filter(m => m.type === 'href');
|
|
172
|
+
assert.equal(links.length, 0);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('Plain: handles empty text', async () => {
|
|
176
|
+
const language = await syntax.getResource('plain');
|
|
177
|
+
const matches = await language.getMatches(syntax, '');
|
|
178
|
+
assert.equal(matches.length, 0);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('Plain: handles text with email-like patterns', async () => {
|
|
182
|
+
const language = await syntax.getResource('plain');
|
|
183
|
+
const text = 'Contact user@example.com for help';
|
|
184
|
+
const matches = await language.getMatches(syntax, text);
|
|
185
|
+
// Email addresses are not matched as URLs (they don't have http://)
|
|
186
|
+
const links = matches.filter(m => m.type === 'href');
|
|
187
|
+
// Should not match email unless it has a protocol
|
|
188
|
+
assert.equal(links.length, 0);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('Plain: detects URLs at start of line', async () => {
|
|
192
|
+
const language = await syntax.getResource('plain');
|
|
193
|
+
const matches = await language.getMatches(
|
|
194
|
+
syntax,
|
|
195
|
+
'http://example.com is the URL'
|
|
196
|
+
);
|
|
197
|
+
const links = matches.filter(m => m.type === 'href');
|
|
198
|
+
assert.ok(links.length >= 1);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('Plain: detects URLs at end of line', async () => {
|
|
202
|
+
const language = await syntax.getResource('plain');
|
|
203
|
+
const matches = await language.getMatches(
|
|
204
|
+
syntax,
|
|
205
|
+
'The URL is http://example.com'
|
|
206
|
+
);
|
|
207
|
+
const links = matches.filter(m => m.type === 'href');
|
|
208
|
+
assert.ok(links.length >= 1);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('Plain: detects URLs with subdomains', async () => {
|
|
212
|
+
const language = await syntax.getResource('plain');
|
|
213
|
+
const matches = await language.getMatches(
|
|
214
|
+
syntax,
|
|
215
|
+
'Visit https://api.staging.example.com'
|
|
216
|
+
);
|
|
217
|
+
const links = matches.filter(m => m.type === 'href');
|
|
218
|
+
assert.ok(links.some(l => l.value.includes('api.staging.example.com')));
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('Plain: detects URLs with IP addresses', async () => {
|
|
222
|
+
const language = await syntax.getResource('plain');
|
|
223
|
+
const matches = await language.getMatches(
|
|
224
|
+
syntax,
|
|
225
|
+
'Server at http://192.168.1.1'
|
|
226
|
+
);
|
|
227
|
+
const links = matches.filter(m => m.type === 'href');
|
|
228
|
+
assert.ok(links.some(l => l.value.includes('192.168.1.1')));
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('Plain: detects URLs with authentication', async () => {
|
|
232
|
+
const language = await syntax.getResource('plain');
|
|
233
|
+
const matches = await language.getMatches(
|
|
234
|
+
syntax,
|
|
235
|
+
'Login at http://user:pass@example.com'
|
|
236
|
+
);
|
|
237
|
+
const links = matches.filter(m => m.type === 'href');
|
|
238
|
+
assert.ok(links.some(l => l.value.includes('user:pass@')));
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('Plain: handles text with email-like patterns', async () => {
|
|
242
|
+
const language = await syntax.getResource('plain');
|
|
243
|
+
const text = 'Contact user@example.com for help';
|
|
244
|
+
const matches = await language.getMatches(syntax, text);
|
|
245
|
+
// Email addresses are not matched as URLs (they don't have http://)
|
|
246
|
+
const links = matches.filter(m => m.type === 'href');
|
|
247
|
+
// Should not match email unless it has a protocol
|
|
248
|
+
assert.equal(links.length, 0);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('Plain: detects URLs at start of line', async () => {
|
|
252
|
+
const language = await syntax.getResource('plain');
|
|
253
|
+
const matches = await language.getMatches(
|
|
254
|
+
syntax,
|
|
255
|
+
'http://example.com is the URL'
|
|
256
|
+
);
|
|
257
|
+
const links = matches.filter(m => m.type === 'href');
|
|
258
|
+
assert.ok(links.length >= 1);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('Plain: detects URLs at end of line', async () => {
|
|
262
|
+
const language = await syntax.getResource('plain');
|
|
263
|
+
const matches = await language.getMatches(
|
|
264
|
+
syntax,
|
|
265
|
+
'The URL is http://example.com'
|
|
266
|
+
);
|
|
267
|
+
const links = matches.filter(m => m.type === 'href');
|
|
268
|
+
assert.ok(links.length >= 1);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('Plain: detects URLs with subdomains', async () => {
|
|
272
|
+
const language = await syntax.getResource('plain');
|
|
273
|
+
const matches = await language.getMatches(
|
|
274
|
+
syntax,
|
|
275
|
+
'Visit https://api.staging.example.com'
|
|
276
|
+
);
|
|
277
|
+
const links = matches.filter(m => m.type === 'href');
|
|
278
|
+
assert.ok(links.some(l => l.value.includes('api.staging.example.com')));
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('Plain: detects URLs with IP addresses', async () => {
|
|
282
|
+
const language = await syntax.getResource('plain');
|
|
283
|
+
const matches = await language.getMatches(
|
|
284
|
+
syntax,
|
|
285
|
+
'Server at http://192.168.1.1'
|
|
286
|
+
);
|
|
287
|
+
const links = matches.filter(m => m.type === 'href');
|
|
288
|
+
assert.ok(links.some(l => l.value.includes('192.168.1.1')));
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test('Plain: processes multiline text with URLs', async () => {
|
|
292
|
+
const language = await syntax.getResource('plain');
|
|
293
|
+
const text = `First line with http://example.com
|
|
294
|
+
Second line with https://another.com
|
|
295
|
+
Third line without URL`;
|
|
296
|
+
const matches = await language.getMatches(syntax, text);
|
|
297
|
+
const links = matches.filter(m => m.type === 'href');
|
|
298
|
+
assert.ok(links.length >= 2);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test('Plain: handles URLs with trailing punctuation', async () => {
|
|
302
|
+
const language = await syntax.getResource('plain');
|
|
303
|
+
const text = 'Check out http://example.com. It is great!';
|
|
304
|
+
const matches = await language.getMatches(syntax, text);
|
|
305
|
+
const links = matches.filter(m => m.type === 'href');
|
|
306
|
+
// URL should not include the trailing period
|
|
307
|
+
assert.ok(links.length >= 1);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('Plain: handles URLs in parentheses', async () => {
|
|
311
|
+
const language = await syntax.getResource('plain');
|
|
312
|
+
const text = 'See documentation (http://example.com) for details';
|
|
313
|
+
const matches = await language.getMatches(syntax, text);
|
|
314
|
+
const links = matches.filter(m => m.type === 'href');
|
|
315
|
+
assert.ok(links.length >= 1);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test('Plain: detects file:// URLs', async () => {
|
|
319
|
+
const language = await syntax.getResource('plain');
|
|
320
|
+
const matches = await language.getMatches(
|
|
321
|
+
syntax,
|
|
322
|
+
'Open file://localhost/path/to/file.txt'
|
|
323
|
+
);
|
|
324
|
+
const links = matches.filter(m => m.type === 'href');
|
|
325
|
+
assert.ok(links.length >= 1);
|
|
326
|
+
assert.ok(links.some(l => l.value.includes('file://')));
|
|
327
|
+
});
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Protocol Buffers (protobuf) language syntax highlighting
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {test} from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import {JSDOM} from 'jsdom';
|
|
8
|
+
import Syntax from '../../../Syntax.js';
|
|
9
|
+
|
|
10
|
+
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');
|
|
11
|
+
global.window = dom.window;
|
|
12
|
+
global.document = dom.window.document;
|
|
13
|
+
global.HTMLElement = dom.window.HTMLElement;
|
|
14
|
+
global.customElements = dom.window.customElements;
|
|
15
|
+
|
|
16
|
+
const syntax = new Syntax();
|
|
17
|
+
|
|
18
|
+
test('Protocol Buffers language can be registered', async () => {
|
|
19
|
+
const language = await syntax.getResource('protobuf');
|
|
20
|
+
assert.ok(language);
|
|
21
|
+
assert.equal(language.name, 'protobuf');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('Protobuf: keyword message', async () => {
|
|
25
|
+
const language = await syntax.getResource('protobuf');
|
|
26
|
+
const matches = await language.getMatches(syntax, 'message Person { }');
|
|
27
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
28
|
+
assert.ok(keywords.some(k => k.value === 'message'));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('Protobuf: keyword enum', async () => {
|
|
32
|
+
const language = await syntax.getResource('protobuf');
|
|
33
|
+
const matches = await language.getMatches(syntax, 'enum Status { }');
|
|
34
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
35
|
+
assert.ok(keywords.some(k => k.value === 'enum'));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('Protobuf: keyword service', async () => {
|
|
39
|
+
const language = await syntax.getResource('protobuf');
|
|
40
|
+
const matches = await language.getMatches(syntax, 'service MyService { }');
|
|
41
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
42
|
+
assert.ok(keywords.some(k => k.value === 'service'));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('Protobuf: keyword rpc', async () => {
|
|
46
|
+
const language = await syntax.getResource('protobuf');
|
|
47
|
+
const matches = await language.getMatches(
|
|
48
|
+
syntax,
|
|
49
|
+
'rpc GetUser(Request) returns (Response);'
|
|
50
|
+
);
|
|
51
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
52
|
+
assert.ok(keywords.some(k => k.value === 'rpc'));
|
|
53
|
+
assert.ok(keywords.some(k => k.value === 'returns'));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('Protobuf: keyword import', async () => {
|
|
57
|
+
const language = await syntax.getResource('protobuf');
|
|
58
|
+
const matches = await language.getMatches(syntax, 'import "other.proto";');
|
|
59
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
60
|
+
assert.ok(keywords.some(k => k.value === 'import'));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('Protobuf: keyword package', async () => {
|
|
64
|
+
const language = await syntax.getResource('protobuf');
|
|
65
|
+
const matches = await language.getMatches(syntax, 'package com.example;');
|
|
66
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
67
|
+
assert.ok(keywords.some(k => k.value === 'package'));
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('Protobuf: keyword option', async () => {
|
|
71
|
+
const language = await syntax.getResource('protobuf');
|
|
72
|
+
const matches = await language.getMatches(
|
|
73
|
+
syntax,
|
|
74
|
+
'option java_package = "com.example";'
|
|
75
|
+
);
|
|
76
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
77
|
+
assert.ok(keywords.some(k => k.value === 'option'));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('Protobuf: keyword extend', async () => {
|
|
81
|
+
const language = await syntax.getResource('protobuf');
|
|
82
|
+
const matches = await language.getMatches(syntax, 'extend Message { }');
|
|
83
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
84
|
+
assert.ok(keywords.some(k => k.value === 'extend'));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('Protobuf: constants true and false', async () => {
|
|
88
|
+
const language = await syntax.getResource('protobuf');
|
|
89
|
+
const matches = await language.getMatches(
|
|
90
|
+
syntax,
|
|
91
|
+
'option allow = true; option deny = false;'
|
|
92
|
+
);
|
|
93
|
+
const constants = matches.filter(m => m.type === 'constant');
|
|
94
|
+
assert.ok(constants.some(c => c.value === 'true'));
|
|
95
|
+
assert.ok(constants.some(c => c.value === 'false'));
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('Protobuf: type string', async () => {
|
|
99
|
+
const language = await syntax.getResource('protobuf');
|
|
100
|
+
const matches = await language.getMatches(syntax, 'string name = 1;');
|
|
101
|
+
const types = matches.filter(m => m.type === 'type');
|
|
102
|
+
assert.ok(types.some(t => t.value === 'string'));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('Protobuf: type int32', async () => {
|
|
106
|
+
const language = await syntax.getResource('protobuf');
|
|
107
|
+
const matches = await language.getMatches(syntax, 'int32 age = 2;');
|
|
108
|
+
const types = matches.filter(m => m.type === 'type');
|
|
109
|
+
assert.ok(types.some(t => t.value === 'int32'));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('Protobuf: type int64', async () => {
|
|
113
|
+
const language = await syntax.getResource('protobuf');
|
|
114
|
+
const matches = await language.getMatches(syntax, 'int64 timestamp = 3;');
|
|
115
|
+
const types = matches.filter(m => m.type === 'type');
|
|
116
|
+
assert.ok(types.some(t => t.value === 'int64'));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('Protobuf: type bool', async () => {
|
|
120
|
+
const language = await syntax.getResource('protobuf');
|
|
121
|
+
const matches = await language.getMatches(syntax, 'bool active = 4;');
|
|
122
|
+
const types = matches.filter(m => m.type === 'type');
|
|
123
|
+
assert.ok(types.some(t => t.value === 'bool'));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('Protobuf: type double', async () => {
|
|
127
|
+
const language = await syntax.getResource('protobuf');
|
|
128
|
+
const matches = await language.getMatches(syntax, 'double price = 5;');
|
|
129
|
+
const types = matches.filter(m => m.type === 'type');
|
|
130
|
+
assert.ok(types.some(t => t.value === 'double'));
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('Protobuf: type float', async () => {
|
|
134
|
+
const language = await syntax.getResource('protobuf');
|
|
135
|
+
const matches = await language.getMatches(syntax, 'float ratio = 6;');
|
|
136
|
+
const types = matches.filter(m => m.type === 'type');
|
|
137
|
+
assert.ok(types.some(t => t.value === 'float'));
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('Protobuf: type bytes', async () => {
|
|
141
|
+
const language = await syntax.getResource('protobuf');
|
|
142
|
+
const matches = await language.getMatches(syntax, 'bytes data = 7;');
|
|
143
|
+
const types = matches.filter(m => m.type === 'type');
|
|
144
|
+
assert.ok(types.some(t => t.value === 'bytes'));
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('Protobuf: fixed-size integer types', async () => {
|
|
148
|
+
const language = await syntax.getResource('protobuf');
|
|
149
|
+
const matches = await language.getMatches(
|
|
150
|
+
syntax,
|
|
151
|
+
'fixed32 a = 1; fixed64 b = 2; sfixed32 c = 3; sfixed64 d = 4;'
|
|
152
|
+
);
|
|
153
|
+
const types = matches.filter(m => m.type === 'type');
|
|
154
|
+
assert.ok(types.some(t => t.value === 'fixed32'));
|
|
155
|
+
assert.ok(types.some(t => t.value === 'fixed64'));
|
|
156
|
+
assert.ok(types.some(t => t.value === 'sfixed32'));
|
|
157
|
+
assert.ok(types.some(t => t.value === 'sfixed64'));
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('Protobuf: signed integer types', async () => {
|
|
161
|
+
const language = await syntax.getResource('protobuf');
|
|
162
|
+
const matches = await language.getMatches(
|
|
163
|
+
syntax,
|
|
164
|
+
'sint32 x = 1; sint64 y = 2;'
|
|
165
|
+
);
|
|
166
|
+
const types = matches.filter(m => m.type === 'type');
|
|
167
|
+
assert.ok(types.some(t => t.value === 'sint32'));
|
|
168
|
+
assert.ok(types.some(t => t.value === 'sint64'));
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('Protobuf: unsigned integer types', async () => {
|
|
172
|
+
const language = await syntax.getResource('protobuf');
|
|
173
|
+
const matches = await language.getMatches(
|
|
174
|
+
syntax,
|
|
175
|
+
'uint32 a = 1; uint64 b = 2;'
|
|
176
|
+
);
|
|
177
|
+
const types = matches.filter(m => m.type === 'type');
|
|
178
|
+
assert.ok(types.some(t => t.value === 'uint32'));
|
|
179
|
+
assert.ok(types.some(t => t.value === 'uint64'));
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('Protobuf: access modifier optional', async () => {
|
|
183
|
+
const language = await syntax.getResource('protobuf');
|
|
184
|
+
const matches = await language.getMatches(syntax, 'optional string name = 1;');
|
|
185
|
+
const access = matches.filter(m => m.type === 'access');
|
|
186
|
+
assert.ok(access.some(a => a.value === 'optional'));
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('Protobuf: access modifier required', async () => {
|
|
190
|
+
const language = await syntax.getResource('protobuf');
|
|
191
|
+
const matches = await language.getMatches(syntax, 'required int32 id = 1;');
|
|
192
|
+
const access = matches.filter(m => m.type === 'access');
|
|
193
|
+
assert.ok(access.some(a => a.value === 'required'));
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('Protobuf: access modifier repeated', async () => {
|
|
197
|
+
const language = await syntax.getResource('protobuf');
|
|
198
|
+
const matches = await language.getMatches(syntax, 'repeated string tags = 1;');
|
|
199
|
+
const access = matches.filter(m => m.type === 'access');
|
|
200
|
+
assert.ok(access.some(a => a.value === 'repeated'));
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('Protobuf: field names', async () => {
|
|
204
|
+
const language = await syntax.getResource('protobuf');
|
|
205
|
+
const matches = await language.getMatches(syntax, 'string user_name = 1;');
|
|
206
|
+
const variables = matches.filter(m => m.type === 'variable');
|
|
207
|
+
assert.ok(variables.some(v => v.value === 'user_name'));
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('Protobuf: CamelCase type names', async () => {
|
|
211
|
+
const language = await syntax.getResource('protobuf');
|
|
212
|
+
const matches = await language.getMatches(syntax, 'MyCustomType field = 1;');
|
|
213
|
+
const types = matches.filter(m => m.type === 'type');
|
|
214
|
+
assert.ok(types.some(t => t.value === 'MyCustomType'));
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('Protobuf: single-line comments', async () => {
|
|
218
|
+
const language = await syntax.getResource('protobuf');
|
|
219
|
+
const matches = await language.getMatches(
|
|
220
|
+
syntax,
|
|
221
|
+
'// This is a comment\nstring name = 1;'
|
|
222
|
+
);
|
|
223
|
+
const comments = matches.filter(m => m.type === 'comment');
|
|
224
|
+
assert.ok(comments.length >= 1);
|
|
225
|
+
assert.ok(comments.some(c => c.value.includes('//')));
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('Protobuf: multi-line comments', async () => {
|
|
229
|
+
const language = await syntax.getResource('protobuf');
|
|
230
|
+
const matches = await language.getMatches(
|
|
231
|
+
syntax,
|
|
232
|
+
'/* Multi\nline */\nstring name = 1;'
|
|
233
|
+
);
|
|
234
|
+
const comments = matches.filter(m => m.type === 'comment');
|
|
235
|
+
assert.ok(comments.some(c => c.value.includes('Multi')));
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('Protobuf: double-quoted strings', async () => {
|
|
239
|
+
const language = await syntax.getResource('protobuf');
|
|
240
|
+
const matches = await language.getMatches(syntax, 'option name = "value";');
|
|
241
|
+
const strings = matches.filter(m => m.type === 'string');
|
|
242
|
+
assert.ok(strings.some(s => s.value === '"value"'));
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test('Protobuf: single-quoted strings', async () => {
|
|
246
|
+
const language = await syntax.getResource('protobuf');
|
|
247
|
+
const matches = await language.getMatches(syntax, "option name = 'value';");
|
|
248
|
+
const strings = matches.filter(m => m.type === 'string');
|
|
249
|
+
assert.ok(strings.some(s => s.value === "'value'"));
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test('Protobuf: decimal numbers', async () => {
|
|
253
|
+
const language = await syntax.getResource('protobuf');
|
|
254
|
+
const matches = await language.getMatches(syntax, 'int32 field = 123;');
|
|
255
|
+
const numbers = matches.filter(
|
|
256
|
+
m => m.type === 'constant' && /^\d/.test(m.value)
|
|
257
|
+
);
|
|
258
|
+
assert.ok(numbers.length >= 1);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('Protobuf: complete message definition', async () => {
|
|
262
|
+
const language = await syntax.getResource('protobuf');
|
|
263
|
+
const code = `message Person {
|
|
264
|
+
string name = 1;
|
|
265
|
+
int32 age = 2;
|
|
266
|
+
}`;
|
|
267
|
+
const matches = await language.getMatches(syntax, code);
|
|
268
|
+
assert.ok(matches.some(m => m.type === 'keyword' && m.value === 'message'));
|
|
269
|
+
assert.ok(matches.some(m => m.type === 'type' && m.value === 'string'));
|
|
270
|
+
assert.ok(matches.some(m => m.type === 'type' && m.value === 'int32'));
|
|
271
|
+
assert.ok(matches.some(m => m.type === 'variable' && m.value === 'name'));
|
|
272
|
+
assert.ok(matches.some(m => m.type === 'variable' && m.value === 'age'));
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test('Protobuf: enum definition', async () => {
|
|
276
|
+
const language = await syntax.getResource('protobuf');
|
|
277
|
+
const code = `enum Status {
|
|
278
|
+
UNKNOWN = 0;
|
|
279
|
+
ACTIVE = 1;
|
|
280
|
+
}`;
|
|
281
|
+
const matches = await language.getMatches(syntax, code);
|
|
282
|
+
assert.ok(matches.some(m => m.type === 'keyword' && m.value === 'enum'));
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('Protobuf: service definition', async () => {
|
|
286
|
+
const language = await syntax.getResource('protobuf');
|
|
287
|
+
const code = `service UserService {
|
|
288
|
+
rpc GetUser(UserRequest) returns (UserResponse);
|
|
289
|
+
}`;
|
|
290
|
+
const matches = await language.getMatches(syntax, code);
|
|
291
|
+
assert.ok(matches.some(m => m.type === 'keyword' && m.value === 'service'));
|
|
292
|
+
assert.ok(matches.some(m => m.type === 'keyword' && m.value === 'rpc'));
|
|
293
|
+
assert.ok(matches.some(m => m.type === 'keyword' && m.value === 'returns'));
|
|
294
|
+
});
|