forked from golang/vscode-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/stateUtils.ts: add command to reset memento state
It may sometimes be necessary to reset the memento state, particularly for testing the extension's behavior when the state is different. Change-Id: I8cfed3b8b49a0f5064b4927e86772d32ea358a54 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/285679 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
- Loading branch information
Showing
5 changed files
with
177 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright 2021 The Go Authors. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------*/ | ||
|
||
import * as assert from 'assert'; | ||
import * as vscode from 'vscode'; | ||
import { getMementoKeys, getWorkspaceState, resetItemsState, setWorkspaceState, updateWorkspaceState } from '../../src/stateUtils'; | ||
import { MockMemento } from '../mocks/MockMemento'; | ||
|
||
suite('Workspace State Modification Tests', () => { | ||
let defaultMemento: vscode.Memento; | ||
|
||
setup(async () => { | ||
defaultMemento = getWorkspaceState(); | ||
}); | ||
|
||
teardown(async () => { | ||
setWorkspaceState(defaultMemento); | ||
}); | ||
|
||
test('test getMementoKeys', () => { | ||
interface TestCase { | ||
keys: string[]; | ||
values: any[]; | ||
want: string[]; | ||
} | ||
const testCases: TestCase[] = [ | ||
{keys: [], values: [], want: []}, | ||
{keys: ['hello'], values: [false], want: ['hello']}, | ||
{keys: ['hello', 'goodbye'], values: [false, 25], want: ['hello', 'goodbye']}, | ||
]; | ||
|
||
testCases.forEach((tc) => { | ||
setWorkspaceState(new MockMemento()); | ||
|
||
const keys = tc.keys; | ||
const values = tc.values; | ||
assert.strictEqual(keys.length, values.length, 'List of keys and values does not have same length'); | ||
|
||
for (let i = 0; i < keys.length; i ++) { | ||
updateWorkspaceState(keys[i], values[i]); | ||
} | ||
|
||
const got = getMementoKeys(getWorkspaceState()); | ||
const want = tc.want; | ||
|
||
assert.strictEqual(got.length, tc.want.length); | ||
got.forEach((key) => { | ||
assert.ok(want.includes(key)); | ||
}); | ||
}); | ||
}); | ||
|
||
test('test resetItemsState', () => { | ||
interface TestCase { | ||
keys: string[]; | ||
values: any[]; | ||
items: string[]; | ||
want: string[]; | ||
} | ||
const testCases: TestCase[] = [ | ||
{keys: [], values: [], items: undefined, want: []}, | ||
{keys: ['hello'], values: [false], items: undefined, want: ['hello']}, | ||
{keys: ['hello', 'goodbye'], values: [false, 25], items: undefined, want: ['hello', 'goodbye']}, | ||
|
||
{keys: [], values: [], items: [], want: []}, | ||
{keys: ['hello'], values: [false], items: [], want: ['hello']}, | ||
{keys: ['hello', 'goodbye'], values: [false, 25], items: [], want: ['hello', 'goodbye']}, | ||
|
||
{keys: ['hello'], values: [false], items: ['hello'], want: []}, | ||
{keys: ['hello', 'goodbye'], values: [false, 25], items: ['hello'], want: ['goodbye']}, | ||
|
||
{keys: ['hello'], values: [false], items: ['hello'], want: []}, | ||
{keys: ['hello', 'goodbye'], values: [false, 25], items: ['hello', 'goodbye'], want: []}, | ||
]; | ||
|
||
testCases.forEach((tc) => { | ||
setWorkspaceState(new MockMemento()); | ||
|
||
const keys = tc.keys; | ||
const values = tc.values; | ||
assert.strictEqual(keys.length, values.length, 'List of keys and values does not have same length'); | ||
|
||
for (let i = 0; i < keys.length; i ++) { | ||
updateWorkspaceState(keys[i], values[i]); | ||
} | ||
|
||
resetItemsState(tc.items, updateWorkspaceState); | ||
const got = getMementoKeys(getWorkspaceState()); | ||
const want = tc.want; | ||
|
||
assert.strictEqual(got.length, want.length); | ||
got.forEach((key) => { | ||
assert.ok(want.includes(key)); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |