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,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for OCaml 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('OCaml language can be registered', async () => {
|
|
19
|
+
const language = await syntax.getResource('ocaml');
|
|
20
|
+
assert.ok(language);
|
|
21
|
+
assert.equal(language.name, 'ocaml');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('OCaml: keyword matches let', async () => {
|
|
25
|
+
const language = await syntax.getResource('ocaml');
|
|
26
|
+
const matches = await language.getMatches(syntax, 'let x = 5');
|
|
27
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
28
|
+
assert.ok(keywords.some(m => m.value === 'let'));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('OCaml: keyword matches fun and function', async () => {
|
|
32
|
+
const language = await syntax.getResource('ocaml');
|
|
33
|
+
const matches = await language.getMatches(
|
|
34
|
+
syntax,
|
|
35
|
+
'let add = fun x y -> x + y'
|
|
36
|
+
);
|
|
37
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
38
|
+
assert.ok(keywords.some(m => m.value === 'fun'));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('OCaml: keyword matches match/with', async () => {
|
|
42
|
+
const language = await syntax.getResource('ocaml');
|
|
43
|
+
const code = 'match x with | Some v -> v | None -> 0';
|
|
44
|
+
const matches = await language.getMatches(syntax, code);
|
|
45
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
46
|
+
assert.ok(keywords.some(m => m.value === 'match'));
|
|
47
|
+
assert.ok(keywords.some(m => m.value === 'with'));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('OCaml: keyword matches type definition', async () => {
|
|
51
|
+
const language = await syntax.getResource('ocaml');
|
|
52
|
+
const matches = await language.getMatches(
|
|
53
|
+
syntax,
|
|
54
|
+
'type color = Red | Green | Blue'
|
|
55
|
+
);
|
|
56
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
57
|
+
assert.ok(keywords.some(m => m.value === 'type'));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('OCaml: keyword matches module', async () => {
|
|
61
|
+
const language = await syntax.getResource('ocaml');
|
|
62
|
+
const matches = await language.getMatches(
|
|
63
|
+
syntax,
|
|
64
|
+
'module MyModule = struct end'
|
|
65
|
+
);
|
|
66
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
67
|
+
assert.ok(keywords.some(m => m.value === 'module'));
|
|
68
|
+
assert.ok(keywords.some(m => m.value === 'struct'));
|
|
69
|
+
assert.ok(keywords.some(m => m.value === 'end'));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('OCaml: keyword matches if/then/else', async () => {
|
|
73
|
+
const language = await syntax.getResource('ocaml');
|
|
74
|
+
const matches = await language.getMatches(syntax, 'if x > 0 then 1 else 0');
|
|
75
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
76
|
+
assert.ok(keywords.some(m => m.value === 'if'));
|
|
77
|
+
assert.ok(keywords.some(m => m.value === 'then'));
|
|
78
|
+
assert.ok(keywords.some(m => m.value === 'else'));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('OCaml: keyword matches rec for recursive functions', async () => {
|
|
82
|
+
const language = await syntax.getResource('ocaml');
|
|
83
|
+
const matches = await language.getMatches(
|
|
84
|
+
syntax,
|
|
85
|
+
'let rec factorial n = if n = 0 then 1 else n * factorial (n - 1)'
|
|
86
|
+
);
|
|
87
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
88
|
+
assert.ok(keywords.some(m => m.value === 'rec'));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('OCaml: type matches basic types', async () => {
|
|
92
|
+
const language = await syntax.getResource('ocaml');
|
|
93
|
+
const matches = await language.getMatches(syntax, 'let x: int = 42');
|
|
94
|
+
const types = matches.filter(m => m.type === 'type');
|
|
95
|
+
assert.ok(types.length > 0);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('OCaml: type matches string type', async () => {
|
|
99
|
+
const language = await syntax.getResource('ocaml');
|
|
100
|
+
const matches = await language.getMatches(syntax, 'let s: string = "hello"');
|
|
101
|
+
const types = matches.filter(m => m.type === 'type');
|
|
102
|
+
assert.ok(types.some(m => m.value === 'string'));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('OCaml: type matches bool type', async () => {
|
|
106
|
+
const language = await syntax.getResource('ocaml');
|
|
107
|
+
const matches = await language.getMatches(syntax, 'let flag: bool = true');
|
|
108
|
+
const types = matches.filter(m => m.type === 'type');
|
|
109
|
+
assert.ok(types.some(m => m.value === 'bool'));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('OCaml: type matches option type', async () => {
|
|
113
|
+
const language = await syntax.getResource('ocaml');
|
|
114
|
+
const matches = await language.getMatches(syntax, 'let x: option = Some 5');
|
|
115
|
+
const types = matches.filter(m => m.type === 'type');
|
|
116
|
+
assert.ok(types.some(m => m.value === 'option'));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('OCaml: type matches list type', async () => {
|
|
120
|
+
const language = await syntax.getResource('ocaml');
|
|
121
|
+
const matches = await language.getMatches(
|
|
122
|
+
syntax,
|
|
123
|
+
'let numbers: list = [1; 2; 3]'
|
|
124
|
+
);
|
|
125
|
+
const types = matches.filter(m => m.type === 'type');
|
|
126
|
+
assert.ok(types.some(m => m.value === 'list'));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('OCaml: constant matches true and false', async () => {
|
|
130
|
+
const language = await syntax.getResource('ocaml');
|
|
131
|
+
const matches = await language.getMatches(
|
|
132
|
+
syntax,
|
|
133
|
+
'let x = true and y = false'
|
|
134
|
+
);
|
|
135
|
+
const constants = matches.filter(m => m.type === 'constant');
|
|
136
|
+
assert.ok(constants.some(m => m.value === 'true'));
|
|
137
|
+
assert.ok(constants.some(m => m.value === 'false'));
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('OCaml: access matches private', async () => {
|
|
141
|
+
const language = await syntax.getResource('ocaml');
|
|
142
|
+
const matches = await language.getMatches(syntax, 'private method foo = 42');
|
|
143
|
+
const access = matches.filter(m => m.type === 'access');
|
|
144
|
+
assert.ok(access.some(m => m.value === 'private'));
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('OCaml: access matches public', async () => {
|
|
148
|
+
const language = await syntax.getResource('ocaml');
|
|
149
|
+
const matches = await language.getMatches(syntax, 'public method bar = 100');
|
|
150
|
+
const access = matches.filter(m => m.type === 'access');
|
|
151
|
+
assert.ok(access.some(m => m.value === 'public'));
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('OCaml: operator matches arrow', async () => {
|
|
155
|
+
const language = await syntax.getResource('ocaml');
|
|
156
|
+
const matches = await language.getMatches(syntax, 'fun x -> x + 1');
|
|
157
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
158
|
+
assert.ok(operators.some(m => m.value === '->'));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('OCaml: operator matches cons operator', async () => {
|
|
162
|
+
const language = await syntax.getResource('ocaml');
|
|
163
|
+
const matches = await language.getMatches(syntax, '1 :: [2; 3]');
|
|
164
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
165
|
+
assert.ok(operators.some(m => m.value === '::'));
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('OCaml: operator matches assignment', async () => {
|
|
169
|
+
const language = await syntax.getResource('ocaml');
|
|
170
|
+
const matches = await language.getMatches(syntax, 'x := 10');
|
|
171
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
172
|
+
assert.ok(operators.some(m => m.value === ':='));
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('OCaml: operator matches pipe operators', async () => {
|
|
176
|
+
const language = await syntax.getResource('ocaml');
|
|
177
|
+
const matches = await language.getMatches(syntax, 'x |> f |> g');
|
|
178
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
179
|
+
assert.ok(operators.some(m => m.value === '|>'));
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('OCaml: operator matches pattern match pipe', async () => {
|
|
183
|
+
const language = await syntax.getResource('ocaml');
|
|
184
|
+
const matches = await language.getMatches(
|
|
185
|
+
syntax,
|
|
186
|
+
'match x with | 0 -> "zero" | _ -> "other"'
|
|
187
|
+
);
|
|
188
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
189
|
+
assert.ok(operators.some(m => m.value === '|'));
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('OCaml: operator matches not equal', async () => {
|
|
193
|
+
const language = await syntax.getResource('ocaml');
|
|
194
|
+
const matches = await language.getMatches(syntax, 'x <> y');
|
|
195
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
196
|
+
assert.ok(operators.some(m => m.value === '<>'));
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('OCaml: function matches after dot', async () => {
|
|
200
|
+
const language = await syntax.getResource('ocaml');
|
|
201
|
+
const matches = await language.getMatches(syntax, 'List.map');
|
|
202
|
+
const functions = matches.filter(m => m.type === 'function');
|
|
203
|
+
assert.ok(functions.some(m => m.value === 'map'));
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('OCaml: function matches function call', async () => {
|
|
207
|
+
const language = await syntax.getResource('ocaml');
|
|
208
|
+
const matches = await language.getMatches(syntax, 'print_endline("Hello")');
|
|
209
|
+
const functions = matches.filter(m => m.type === 'function');
|
|
210
|
+
assert.ok(functions.some(m => m.value === 'print_endline'));
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('OCaml: comment matches (* *) style', async () => {
|
|
214
|
+
const language = await syntax.getResource('ocaml');
|
|
215
|
+
const matches = await language.getMatches(syntax, '(* This is a comment *)');
|
|
216
|
+
const comments = matches.filter(m => m.type === 'comment');
|
|
217
|
+
assert.ok(comments.length > 0);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('OCaml: comment matches nested comments', async () => {
|
|
221
|
+
const language = await syntax.getResource('ocaml');
|
|
222
|
+
const matches = await language.getMatches(
|
|
223
|
+
syntax,
|
|
224
|
+
'(* outer (* inner *) outer *)'
|
|
225
|
+
);
|
|
226
|
+
const comments = matches.filter(m => m.type === 'comment');
|
|
227
|
+
assert.ok(comments.length > 0);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('OCaml: string matches double-quoted strings', async () => {
|
|
231
|
+
const language = await syntax.getResource('ocaml');
|
|
232
|
+
const matches = await language.getMatches(syntax, '"Hello, World!"');
|
|
233
|
+
const strings = matches.filter(m => m.type === 'string');
|
|
234
|
+
assert.ok(strings.length > 0);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('OCaml: number matches decimal', async () => {
|
|
238
|
+
const language = await syntax.getResource('ocaml');
|
|
239
|
+
const matches = await language.getMatches(syntax, '42');
|
|
240
|
+
const numbers = matches.filter(m => m.type === 'constant');
|
|
241
|
+
assert.ok(numbers.length > 0);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('OCaml: number matches hex', async () => {
|
|
245
|
+
const language = await syntax.getResource('ocaml');
|
|
246
|
+
const matches = await language.getMatches(syntax, '0xFF');
|
|
247
|
+
const numbers = matches.filter(m => m.type === 'constant');
|
|
248
|
+
assert.ok(numbers.length > 0);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('OCaml: camelCase type matches custom types', async () => {
|
|
252
|
+
const language = await syntax.getResource('ocaml');
|
|
253
|
+
const matches = await language.getMatches(syntax, 'let x: MyType = value');
|
|
254
|
+
const types = matches.filter(m => m.type === 'type');
|
|
255
|
+
assert.ok(types.length > 0);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('OCaml: complete function definition', async () => {
|
|
259
|
+
const code = `let rec sum_list lst =
|
|
260
|
+
match lst with
|
|
261
|
+
| [] -> 0
|
|
262
|
+
| hd :: tl -> hd + sum_list tl`;
|
|
263
|
+
const language = await syntax.getResource('ocaml');
|
|
264
|
+
const matches = await language.getMatches(syntax, code);
|
|
265
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
266
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
267
|
+
assert.ok(keywords.some(m => m.value === 'let'));
|
|
268
|
+
assert.ok(keywords.some(m => m.value === 'rec'));
|
|
269
|
+
assert.ok(keywords.some(m => m.value === 'match'));
|
|
270
|
+
assert.ok(keywords.some(m => m.value === 'with'));
|
|
271
|
+
assert.ok(operators.some(m => m.value === '::'));
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test('OCaml: pattern matching with types', async () => {
|
|
275
|
+
const code = `match value with
|
|
276
|
+
| Some x -> x
|
|
277
|
+
| None -> 0`;
|
|
278
|
+
const language = await syntax.getResource('ocaml');
|
|
279
|
+
const matches = await language.getMatches(syntax, code);
|
|
280
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
281
|
+
assert.ok(keywords.some(m => m.value === 'match'));
|
|
282
|
+
assert.ok(keywords.some(m => m.value === 'with'));
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('OCaml: module definition', async () => {
|
|
286
|
+
const code = `module Stack = struct
|
|
287
|
+
let empty = []
|
|
288
|
+
let push x s = x :: s
|
|
289
|
+
let pop = function
|
|
290
|
+
| [] -> None
|
|
291
|
+
| x :: xs -> Some (x, xs)
|
|
292
|
+
end`;
|
|
293
|
+
const language = await syntax.getResource('ocaml');
|
|
294
|
+
const matches = await language.getMatches(syntax, code);
|
|
295
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
296
|
+
assert.ok(keywords.some(m => m.value === 'module'));
|
|
297
|
+
assert.ok(keywords.some(m => m.value === 'struct'));
|
|
298
|
+
assert.ok(keywords.some(m => m.value === 'end'));
|
|
299
|
+
});
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Pascal/Delphi 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('Pascal language can be registered', async () => {
|
|
19
|
+
const language = await syntax.getResource('pascal');
|
|
20
|
+
assert.ok(language);
|
|
21
|
+
assert.equal(language.name, 'pascal');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('Pascal: keyword matches begin/end (case insensitive)', async () => {
|
|
25
|
+
const language = await syntax.getResource('pascal');
|
|
26
|
+
const matches = await language.getMatches(syntax, 'BEGIN program END');
|
|
27
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
28
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'begin'));
|
|
29
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'end'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('Pascal: keyword matches program', async () => {
|
|
33
|
+
const language = await syntax.getResource('pascal');
|
|
34
|
+
const matches = await language.getMatches(syntax, 'program HelloWorld;');
|
|
35
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
36
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'program'));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('Pascal: keyword matches var', async () => {
|
|
40
|
+
const language = await syntax.getResource('pascal');
|
|
41
|
+
const matches = await language.getMatches(syntax, 'var x: Integer;');
|
|
42
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
43
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'var'));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('Pascal: keyword matches procedure', async () => {
|
|
47
|
+
const language = await syntax.getResource('pascal');
|
|
48
|
+
const matches = await language.getMatches(syntax, 'procedure DoSomething;');
|
|
49
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
50
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'procedure'));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('Pascal: keyword matches function', async () => {
|
|
54
|
+
const language = await syntax.getResource('pascal');
|
|
55
|
+
const matches = await language.getMatches(
|
|
56
|
+
syntax,
|
|
57
|
+
'function Add(a, b: Integer): Integer;'
|
|
58
|
+
);
|
|
59
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
60
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'function'));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('Pascal: keyword matches if/then/else', async () => {
|
|
64
|
+
const language = await syntax.getResource('pascal');
|
|
65
|
+
const matches = await language.getMatches(
|
|
66
|
+
syntax,
|
|
67
|
+
'if x > 0 then y := 1 else y := 0'
|
|
68
|
+
);
|
|
69
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
70
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'if'));
|
|
71
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'then'));
|
|
72
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'else'));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('Pascal: keyword matches for/to/do', async () => {
|
|
76
|
+
const language = await syntax.getResource('pascal');
|
|
77
|
+
const matches = await language.getMatches(syntax, 'for i := 1 to 10 do');
|
|
78
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
79
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'for'));
|
|
80
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'to'));
|
|
81
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'do'));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('Pascal: keyword matches while/do', async () => {
|
|
85
|
+
const language = await syntax.getResource('pascal');
|
|
86
|
+
const matches = await language.getMatches(syntax, 'while x < 10 do');
|
|
87
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
88
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'while'));
|
|
89
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'do'));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('Pascal: keyword matches repeat/until', async () => {
|
|
93
|
+
const language = await syntax.getResource('pascal');
|
|
94
|
+
const matches = await language.getMatches(
|
|
95
|
+
syntax,
|
|
96
|
+
'repeat x := x + 1 until x > 10'
|
|
97
|
+
);
|
|
98
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
99
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'repeat'));
|
|
100
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'until'));
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('Pascal: keyword matches case/of', async () => {
|
|
104
|
+
const language = await syntax.getResource('pascal');
|
|
105
|
+
const matches = await language.getMatches(syntax, 'case x of 1: y := 1; end;');
|
|
106
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
107
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'case'));
|
|
108
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'of'));
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('Pascal: keyword matches record', async () => {
|
|
112
|
+
const language = await syntax.getResource('pascal');
|
|
113
|
+
const matches = await language.getMatches(
|
|
114
|
+
syntax,
|
|
115
|
+
'type Person = record name: String; end;'
|
|
116
|
+
);
|
|
117
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
118
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'record'));
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('Pascal: keyword matches class (Delphi)', async () => {
|
|
122
|
+
const language = await syntax.getResource('pascal');
|
|
123
|
+
const matches = await language.getMatches(
|
|
124
|
+
syntax,
|
|
125
|
+
'type TMyClass = class end;'
|
|
126
|
+
);
|
|
127
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
128
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'class'));
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('Pascal: keyword matches try/except/finally', async () => {
|
|
132
|
+
const language = await syntax.getResource('pascal');
|
|
133
|
+
const matches = await language.getMatches(
|
|
134
|
+
syntax,
|
|
135
|
+
'try DoSomething except end; try DoOther finally end;'
|
|
136
|
+
);
|
|
137
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
138
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'try'));
|
|
139
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'except'));
|
|
140
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'finally'));
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('Pascal: constant matches true/false (case insensitive)', async () => {
|
|
144
|
+
const language = await syntax.getResource('pascal');
|
|
145
|
+
const matches = await language.getMatches(
|
|
146
|
+
syntax,
|
|
147
|
+
'flag := TRUE; other := False;'
|
|
148
|
+
);
|
|
149
|
+
const constants = matches.filter(m => m.type === 'constant');
|
|
150
|
+
assert.ok(constants.some(m => m.value.toLowerCase() === 'true'));
|
|
151
|
+
assert.ok(constants.some(m => m.value.toLowerCase() === 'false'));
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('Pascal: constant matches nil', async () => {
|
|
155
|
+
const language = await syntax.getResource('pascal');
|
|
156
|
+
const matches = await language.getMatches(syntax, 'ptr := NIL;');
|
|
157
|
+
const constants = matches.filter(m => m.type === 'constant');
|
|
158
|
+
assert.ok(constants.some(m => m.value.toLowerCase() === 'nil'));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('Pascal: operator matches assignment :=', async () => {
|
|
162
|
+
const language = await syntax.getResource('pascal');
|
|
163
|
+
const matches = await language.getMatches(syntax, 'x := 10');
|
|
164
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
165
|
+
assert.ok(operators.some(m => m.value === ':='));
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('Pascal: operator matches comparison operators', async () => {
|
|
169
|
+
const language = await syntax.getResource('pascal');
|
|
170
|
+
const matches = await language.getMatches(
|
|
171
|
+
syntax,
|
|
172
|
+
'x = 5; y <> 3; z >= 1; w <= 2'
|
|
173
|
+
);
|
|
174
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
175
|
+
assert.ok(operators.some(m => m.value === '='));
|
|
176
|
+
assert.ok(operators.some(m => m.value === '<>'));
|
|
177
|
+
assert.ok(operators.some(m => m.value === '>='));
|
|
178
|
+
assert.ok(operators.some(m => m.value === '<='));
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('Pascal: operator matches arithmetic operators', async () => {
|
|
182
|
+
const language = await syntax.getResource('pascal');
|
|
183
|
+
const matches = await language.getMatches(syntax, 'x + y - z * w / 2');
|
|
184
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
185
|
+
assert.ok(operators.some(m => m.value === '+'));
|
|
186
|
+
assert.ok(operators.some(m => m.value === '-'));
|
|
187
|
+
assert.ok(operators.some(m => m.value === '*'));
|
|
188
|
+
assert.ok(operators.some(m => m.value === '/'));
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('Pascal: operator matches div and mod', async () => {
|
|
192
|
+
const language = await syntax.getResource('pascal');
|
|
193
|
+
const matches = await language.getMatches(syntax, 'x div 2; y mod 3');
|
|
194
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
195
|
+
assert.ok(operators.some(m => m.value.toLowerCase() === 'div'));
|
|
196
|
+
assert.ok(operators.some(m => m.value.toLowerCase() === 'mod'));
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('Pascal: operator matches logical operators', async () => {
|
|
200
|
+
const language = await syntax.getResource('pascal');
|
|
201
|
+
const matches = await language.getMatches(syntax, 'a and b or c xor d');
|
|
202
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
203
|
+
assert.ok(operators.some(m => m.value.toLowerCase() === 'and'));
|
|
204
|
+
assert.ok(operators.some(m => m.value.toLowerCase() === 'or'));
|
|
205
|
+
assert.ok(operators.some(m => m.value.toLowerCase() === 'xor'));
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('Pascal: operator matches bit shift operators', async () => {
|
|
209
|
+
const language = await syntax.getResource('pascal');
|
|
210
|
+
const matches = await language.getMatches(syntax, 'x shl 2; y shr 1');
|
|
211
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
212
|
+
assert.ok(operators.some(m => m.value.toLowerCase() === 'shl'));
|
|
213
|
+
assert.ok(operators.some(m => m.value.toLowerCase() === 'shr'));
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('Pascal: operator matches not', async () => {
|
|
217
|
+
const language = await syntax.getResource('pascal');
|
|
218
|
+
const matches = await language.getMatches(syntax, 'not flag');
|
|
219
|
+
const operators = matches.filter(m => m.type === 'operator');
|
|
220
|
+
assert.ok(operators.some(m => m.value.toLowerCase() === 'not'));
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('Pascal: comment matches curly brace style', async () => {
|
|
224
|
+
const language = await syntax.getResource('pascal');
|
|
225
|
+
const matches = await language.getMatches(syntax, '{ This is a comment }');
|
|
226
|
+
const comments = matches.filter(m => m.type === 'comment');
|
|
227
|
+
assert.ok(comments.length > 0);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('Pascal: comment matches (* *) style', async () => {
|
|
231
|
+
const language = await syntax.getResource('pascal');
|
|
232
|
+
const matches = await language.getMatches(syntax, '(* This is a comment *)');
|
|
233
|
+
const comments = matches.filter(m => m.type === 'comment');
|
|
234
|
+
assert.ok(comments.length > 0);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('Pascal: string matches single-quoted strings', async () => {
|
|
238
|
+
const language = await syntax.getResource('pascal');
|
|
239
|
+
const matches = await language.getMatches(syntax, "'Hello, World!'");
|
|
240
|
+
const strings = matches.filter(m => m.type === 'string');
|
|
241
|
+
assert.ok(strings.length > 0);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('Pascal: number matches decimal', async () => {
|
|
245
|
+
const language = await syntax.getResource('pascal');
|
|
246
|
+
const matches = await language.getMatches(syntax, '42');
|
|
247
|
+
const numbers = matches.filter(m => m.type === 'constant');
|
|
248
|
+
assert.ok(numbers.length > 0);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('Pascal: number matches hex', async () => {
|
|
252
|
+
const language = await syntax.getResource('pascal');
|
|
253
|
+
const matches = await language.getMatches(syntax, '$FF');
|
|
254
|
+
const numbers = matches.filter(m => m.type === 'constant');
|
|
255
|
+
assert.ok(numbers.length > 0);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('Pascal: function call matches', async () => {
|
|
259
|
+
const language = await syntax.getResource('pascal');
|
|
260
|
+
const matches = await language.getMatches(syntax, 'WriteLn(message)');
|
|
261
|
+
const functions = matches.filter(m => m.type === 'function');
|
|
262
|
+
assert.ok(functions.some(m => m.value === 'WriteLn'));
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('Pascal: CamelCase type matches', async () => {
|
|
266
|
+
const language = await syntax.getResource('pascal');
|
|
267
|
+
const matches = await language.getMatches(syntax, 'var obj: TMyObject;');
|
|
268
|
+
const types = matches.filter(m => m.type === 'type');
|
|
269
|
+
assert.ok(types.length > 0);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('Pascal: complete program structure', async () => {
|
|
273
|
+
const code = `program HelloWorld;
|
|
274
|
+
var
|
|
275
|
+
message: String;
|
|
276
|
+
begin
|
|
277
|
+
message := 'Hello, World!';
|
|
278
|
+
WriteLn(message);
|
|
279
|
+
end.`;
|
|
280
|
+
const language = await syntax.getResource('pascal');
|
|
281
|
+
const matches = await language.getMatches(syntax, code);
|
|
282
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
283
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'program'));
|
|
284
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'var'));
|
|
285
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'begin'));
|
|
286
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'end'));
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('Pascal: procedure definition', async () => {
|
|
290
|
+
const code = `procedure DisplaySum(a, b: Integer);
|
|
291
|
+
begin
|
|
292
|
+
WriteLn('Sum: ', a + b);
|
|
293
|
+
end;`;
|
|
294
|
+
const language = await syntax.getResource('pascal');
|
|
295
|
+
const matches = await language.getMatches(syntax, code);
|
|
296
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
297
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'procedure'));
|
|
298
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'begin'));
|
|
299
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'end'));
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test('Pascal: function definition', async () => {
|
|
303
|
+
const code = `function Add(a, b: Integer): Integer;
|
|
304
|
+
begin
|
|
305
|
+
Result := a + b;
|
|
306
|
+
end;`;
|
|
307
|
+
const language = await syntax.getResource('pascal');
|
|
308
|
+
const matches = await language.getMatches(syntax, code);
|
|
309
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
310
|
+
assert.ok(keywords.some(m => m.value.toLowerCase() === 'function'));
|
|
311
|
+
});
|