-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathsyntax.test.ts
More file actions
54 lines (43 loc) · 1.51 KB
/
syntax.test.ts
File metadata and controls
54 lines (43 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
import { readFileSync } from 'fs';
import { join } from 'path';
import * as assert from 'assert';
interface syntaxFile {
'repository': {
'function-declarations': {
'patterns': [
{
'begin':string
}
]
}
}
}
const extension_root: string = join(__dirname, '..', '..', '..');
const r_syntax_file: string = join(extension_root, 'syntax', 'r.json');
console.log(r_syntax_file);
const rsyntax_raw = readFileSync(r_syntax_file) as unknown;
const rsyntax: syntaxFile = JSON.parse(rsyntax_raw as string) as syntaxFile;
const function_pattern: string = rsyntax.repository['function-declarations'].patterns[0].begin;
suite('Syntax Highlighting', () => {
test('function-declarations - basic match', () => {
const re = new RegExp(function_pattern);
const line = 'x <- function(x) {';
const match = re.exec(line);
assert.ok(match);
assert.strictEqual(match[3], 'function');
});
test('function-declarations - extra spacing', () => {
const re = new RegExp(function_pattern);
const line = 'x <- function (x) {';
const match = re.exec(line);
assert.ok(match);
assert.strictEqual(match[3], 'function');
});
test('function-declarations - false function', () => {
const re = new RegExp(function_pattern);
const line = 'x <- functions';
const match = re.exec(line);
assert.strictEqual(match, null);
});
});