Skip to content

Commit 6cbef71

Browse files
committed
[Test] Add vscode test
This commit adds vscode mocha test ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee <[email protected]>
1 parent 9a5d82e commit 6cbef71

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/Tests/Utils/vscode.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* NOTE This is for the purpose of testing the functions of the library
19+
* being provided and writing down how to use it, not testing the function
20+
* of this project.
21+
*/
22+
23+
import * as vscode from "vscode";
24+
25+
import { assert } from "chai";
26+
import { TestBuilder } from "../TestBuilder";
27+
28+
suite("vscode", function () {
29+
suite("workspace", function () {
30+
let testBuilder: TestBuilder;
31+
32+
setup(() => {
33+
testBuilder = new TestBuilder(this);
34+
testBuilder.setUp();
35+
});
36+
37+
suite("#workspaceEdit", async function () {
38+
testBuilder.writeFileSync("test.txt", `"A": "a"`);
39+
const uri = vscode.Uri.file(testBuilder.getPath("test.txt"));
40+
41+
let document = await vscode.workspace.openTextDocument(uri);
42+
43+
const edit = new vscode.WorkspaceEdit();
44+
edit.replace(
45+
document.uri,
46+
new vscode.Range(0, 0, document.lineCount, 0),
47+
`"A":"b"`
48+
);
49+
50+
await vscode.workspace.applyEdit(edit);
51+
await document.save();
52+
53+
const newText: string = document.getText();
54+
const newCont = JSON.parse(newText);
55+
assert.strictEqual(newCont["A"], "b");
56+
});
57+
58+
teardown(() => {
59+
testBuilder.tearDown();
60+
});
61+
});
62+
});

0 commit comments

Comments
 (0)