Skip to content

Commit 4b9f848

Browse files
committed
test: add helper function tests
1 parent aed3790 commit 4b9f848

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/helper.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { strictEqual } from 'assert';
2+
import {
3+
isUri,
4+
isString,
5+
isNumber,
6+
isBoolean,
7+
isObject,
8+
isArray,
9+
isOptionalString,
10+
isArrayOfString,
11+
arraysEqual,
12+
isPositionInString,
13+
} from '../src/lib/helper';
14+
import * as vscode from 'vscode';
15+
16+
suite('helper functions isTypeVariable tests', () => {
17+
test('isUri', () => {
18+
strictEqual(true, isUri(vscode.Uri.parse('file:///home/user/file.txt')));
19+
});
20+
test('isString', () => {
21+
strictEqual(true, isString('hello'));
22+
});
23+
test('isNumber', () => {
24+
strictEqual(true, isNumber(1));
25+
});
26+
test('isBoolean', () => {
27+
strictEqual(true, isBoolean(true));
28+
});
29+
test('isObject', () => {
30+
strictEqual(true, isObject({}));
31+
});
32+
test('isArray', () => {
33+
strictEqual(true, isArray([]));
34+
});
35+
test('isOptionalString', () => {
36+
strictEqual(true, isOptionalString('hello'));
37+
strictEqual(true, isOptionalString(undefined));
38+
});
39+
test('isArrayOfString', () => {
40+
strictEqual(true, isArrayOfString(['hello']));
41+
});
42+
test('arraysEqual', () => {
43+
strictEqual(true, arraysEqual(['hello'], ['hello']));
44+
strictEqual(false, arraysEqual(['hello'], [null]));
45+
strictEqual(false, arraysEqual(['hello'], ['hello', 'world']));
46+
strictEqual(false, arraysEqual(['hello'], ['world']));
47+
});
48+
});
49+
50+
suite('helper functions general tests', () => {
51+
test('isPositionInString', async () => {
52+
const doc = await vscode.workspace.openTextDocument({
53+
language: 'text',
54+
content: 'hello "world"',
55+
});
56+
const pos = new vscode.Position(0, 7);
57+
strictEqual(true, isPositionInString(doc, pos));
58+
});
59+
});

0 commit comments

Comments
 (0)