tests: Assert: use parameter destructuring for optional parameters
This commit is contained in:
@@ -37,12 +37,15 @@ tests.register("Focus and move windows", 1, () => {
|
||||
function testLayout(shortcutName: string, grid: KwinClient[][]) {
|
||||
qtMock.fireShortcut(shortcutName);
|
||||
const screen = new MockQmlRect(0, 0, screenWidth, screenHeight);
|
||||
Assert.grid(config, screen, grid, 1);
|
||||
Assert.grid(config, screen, grid, { skip: 1 });
|
||||
}
|
||||
|
||||
function testFocus(shortcutName: string, expectedFocus: KwinClient) {
|
||||
qtMock.fireShortcut(shortcutName);
|
||||
Assert.assert(workspaceMock.activeWindow === expectedFocus, `wrong activeWindow: ${workspaceMock.activeWindow?.pid}`, 1);
|
||||
Assert.assert(workspaceMock.activeWindow === expectedFocus, {
|
||||
message: `wrong activeWindow: ${workspaceMock.activeWindow?.pid}`,
|
||||
skip: 1,
|
||||
});
|
||||
};
|
||||
|
||||
testLayout("karousel-column-move-right", [ [client1], [client2], [client3] ]);
|
||||
|
||||
@@ -15,7 +15,10 @@ tests.register("WindowRuleEnforcer", 1, () => {
|
||||
const enforcer = new WindowRuleEnforcer(JSON.parse(defaultWindowRules));
|
||||
for (const testCase of testCases) {
|
||||
const kwinClient: any = createKwinClient(testCase.tiledByDefault, testCase.resourceClass, testCase.caption);
|
||||
Assert.assert(enforcer.shouldTile(kwinClient) === testCase.shouldTile, "failed case: " + JSON.stringify(testCase));
|
||||
Assert.assert(
|
||||
enforcer.shouldTile(kwinClient) === testCase.shouldTile,
|
||||
{ message: "failed case: " + JSON.stringify(testCase) },
|
||||
);
|
||||
}
|
||||
|
||||
function createKwinClient(normalWindow: boolean, resourceClass: string, caption: string) {
|
||||
|
||||
@@ -10,7 +10,10 @@ tests.register("Clients.canTileEver", 1, () => {
|
||||
|
||||
for (const testCase of testCases) {
|
||||
const kwinClient: any = createKwinClient(testCase.clientProperties);
|
||||
Assert.assert(Clients.canTileEver(kwinClient) === testCase.tileable, "failed case: " + JSON.stringify(testCase));
|
||||
Assert.assert(
|
||||
Clients.canTileEver(kwinClient) === testCase.tileable,
|
||||
{ message: "failed case: " + JSON.stringify(testCase) },
|
||||
);
|
||||
}
|
||||
|
||||
function createKwinClient(properties: { resourceClass: string, caption: string }) {
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
namespace Assert {
|
||||
export function assert(assertion: boolean, message?: string, skip: number = 0) {
|
||||
type Options = {
|
||||
message?: string,
|
||||
skip?: number,
|
||||
}
|
||||
|
||||
export function assert(
|
||||
assertion: boolean,
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
if (assertion) {
|
||||
return;
|
||||
}
|
||||
@@ -31,35 +39,69 @@ namespace Assert {
|
||||
Message: ${message}`);
|
||||
}
|
||||
|
||||
export function equal(actual: any, expected: any, skip: number = 0) {
|
||||
export function equal(
|
||||
actual: any,
|
||||
expected: any,
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
assert(
|
||||
expected == actual,
|
||||
buildMessage(actual, expected, "Values not equal"),
|
||||
skip+1
|
||||
{
|
||||
message: buildMessage(actual, expected, "Values not equal", message),
|
||||
skip: skip + 1,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function equalArrays(actual: any[], expected: any[], skip: number = 0) {
|
||||
export function equalArrays(
|
||||
actual: any[],
|
||||
expected: any[],
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
assert(
|
||||
actual.length === expected.length && actual.every((item, index) => item === expected[index]),
|
||||
buildMessage(actual, expected, "Arrays not equal"),
|
||||
skip+1
|
||||
{
|
||||
message: buildMessage(actual, expected, "Arrays not equal", message),
|
||||
skip: skip + 1,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function equalRects(actual: QmlRect, expected: QmlRect, skip: number = 0) {
|
||||
export function equalRects(
|
||||
actual: QmlRect,
|
||||
expected: QmlRect,
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
assert(
|
||||
rectEquals(expected, actual),
|
||||
buildMessage(actual, expected, "QmlRect not equal"),
|
||||
skip+1
|
||||
{
|
||||
message: buildMessage(actual, expected, "QmlRect not equal", message),
|
||||
skip: skip + 1,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function rect(actual: QmlRect, x: number, y: number, width: number, height: number, skip: number = 0) {
|
||||
equalRects(actual, new MockQmlRect(x, y, width, height), skip+1);
|
||||
export function rect(
|
||||
actual: QmlRect,
|
||||
x: number,
|
||||
y: number,
|
||||
width: number,
|
||||
height: number,
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
equalRects(
|
||||
actual,
|
||||
new MockQmlRect(x, y, width, height),
|
||||
{ message: message, skip: skip+1 },
|
||||
);
|
||||
}
|
||||
|
||||
export function grid(config: Config, screen: QmlRect, grid: KwinClient[][], skip: number = 0) {
|
||||
export function grid(
|
||||
config: Config,
|
||||
screen: QmlRect,
|
||||
grid: KwinClient[][],
|
||||
{ message, skip=0 }: Options = {},
|
||||
) {
|
||||
// assumes uniformly sized windows within columns of width 100
|
||||
function getRectInGrid(column: number, window: number, nColumns: number, nWindows: number) {
|
||||
const columnHeight = screen.height - config.gapsOuterTop - config.gapsOuterBottom;
|
||||
@@ -79,7 +121,11 @@ namespace Assert {
|
||||
const nWindows = column.length;
|
||||
for (let iWindow = 0; iWindow < nWindows; iWindow++) {
|
||||
const window = column[iWindow];
|
||||
equalRects(window.frameGeometry, getRectInGrid(iColumn, iWindow, nColumns, nWindows), skip+1);
|
||||
equalRects(
|
||||
window.frameGeometry,
|
||||
getRectInGrid(iColumn, iWindow, nColumns, nWindows),
|
||||
{ message: message, skip: skip+1 },
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user