forked from onivim/oni2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguageInfoTest.re
104 lines (101 loc) · 4.03 KB
/
LanguageInfoTest.re
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
open Oni_Core;
open TestFramework;
// Language info, with multiple loaded extensions to check order of loading
// works.
let li =
[
"extensions/shellscript/package.json",
"extensions/json/package.json",
"extensions/typescript-basics/package.json",
]
|> List.fold_left(
(prev, curr) => {
switch (
Exthost.Extension.Scanner.load(
~category=Exthost.Extension.Scanner.Default,
curr,
)
) {
| Some(s) => [s, ...prev]
| None => prev
}
},
[],
)
|> Exthost.LanguageInfo.ofExtensions;
let buf = Buffer.ofLines(~font=Font.default(), [|"#!/bin/bash", "ls *"|]);
describe("LanguageInfo", ({describe, _}) => {
describe("get language from file path", ({test, _}) => {
test("get language from file path: Oni2 Path", ({expect, _}) => {
let lang =
Exthost.LanguageInfo.getLanguageFromFilePath(li, "oni://terminal/");
expect.string(lang).toEqual("terminal");
});
test("get language from file path: extension", ({expect, _}) => {
// Extension match
let fp = "/home/oni2/git/oni2/test.sh";
let lang = Exthost.LanguageInfo.getLanguageFromFilePath(li, fp);
expect.string(lang).toEqual("shellscript");
});
test(
"get language from file path: extension (no file name)", ({expect, _}) => {
// "Extension" match
let fp = "/home/oni2/git/oni2/.bash_profile";
let lang = Exthost.LanguageInfo.getLanguageFromFilePath(li, fp);
expect.string(lang).toEqual("shellscript");
});
test("get language from file path: file name", ({expect, _}) => {
// Exact file name match to shellscript
let fp = "/home/oni2/git/oni2/PKGBUILD";
let lang = Exthost.LanguageInfo.getLanguageFromFilePath(li, fp);
expect.string(lang).toEqual("shellscript");
});
test("get language from file path: file name pattern", ({expect, _}) => {
// Pattern > extension, so this json file is a jsonc file as stated in the
// TS package.json.
let fp = "/home/oni2/git/oni2/tsconfig.base.json";
let lang = Exthost.LanguageInfo.getLanguageFromFilePath(li, fp);
expect.string(lang).toEqual("jsonc");
});
});
describe("get language from buffer", ({test, _}) => {
test("get language from buffer: Oni2 Path", ({expect, _}) => {
let lang =
Exthost.LanguageInfo.getLanguageFromFilePath(li, "oni://terminal/");
expect.string(lang).toEqual("terminal");
});
test("get language from buffer: extension", ({expect, _}) => {
let buf = Buffer.setFilePath(Some("/home/oni2/git/oni2/test.sh"), buf);
let lang = Exthost.LanguageInfo.getLanguageFromBuffer(li, buf);
expect.string(lang).toEqual("shellscript");
});
test("get language from buffer: extension (no file name)", ({expect, _}) => {
let buf =
Buffer.setFilePath(Some("/home/oni2/git/oni2/.bash_profile"), buf);
let lang = Exthost.LanguageInfo.getLanguageFromBuffer(li, buf);
expect.string(lang).toEqual("shellscript");
});
test("get language from buffer: file name", ({expect, _}) => {
let buf =
Buffer.setFilePath(Some("/home/oni2/git/oni2/PKGBUILD"), buf);
let lang = Exthost.LanguageInfo.getLanguageFromBuffer(li, buf);
expect.string(lang).toEqual("shellscript");
});
test("get language from buffer: file name pattern", ({expect, _}) => {
let buf =
Buffer.setFilePath(
Some("/home/oni2/git/oni2/tsconfig.base.json"),
buf,
);
let lang = Exthost.LanguageInfo.getLanguageFromBuffer(li, buf);
expect.string(lang).toEqual("jsonc");
});
test("get language from buffer: first line", ({expect, _}) => {
// Only unique buffer test. The rest are all fall throughs based on the file name, and the first line is the last resort.
let buf =
Buffer.setFilePath(Some("/home/oni2/git/oni2/my_script"), buf);
let lang = Exthost.LanguageInfo.getLanguageFromBuffer(li, buf);
expect.string(lang).toEqual("shellscript");
});
});
});