mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Inital by-type split
Split type.class from CssTypeSelector to CssCompositeSelector, probably support type#id.class selectors Apply review comments, refactor css-selectors internally Applied refactoring, all tests pass, button does not notify changes Add tests for the css selectors parser. Added tests for css-selectors Added basic implementation of mayMatch and changeMap for css match state Implemented TKUnit.assertDeepEqual to check key and key/values in Map and Set Watch for property and pseudoClass changes Add one child group test Add typings for animations Added mechanism to enable/disable listeners for pseudo classes Count listeners instead of checking handlers, reverse subscription and unsubscription
This commit is contained in:
@ -227,6 +227,82 @@ export function assertEqual(actual: any, expected: any, message?: string) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Assert two json like objects are deep equal.
|
||||
*/
|
||||
export function assertDeepEqual(actual, expected, path: any[] = []): void {
|
||||
let typeofActual = typeof actual;
|
||||
let typeofExpected = typeof expected;
|
||||
if (typeofActual !== typeofExpected) {
|
||||
throw new Error("At /" + path.join("/") + " types of actual " + typeofActual + " and expected " + typeofExpected + " differ.");
|
||||
} else if (typeofActual === "object" || typeofActual === "array") {
|
||||
if (expected instanceof Map) {
|
||||
if (actual instanceof Map) {
|
||||
expected.forEach((value, key) => {
|
||||
if (actual.has(key)) {
|
||||
assertDeepEqual(actual.get(key), value, path.concat([key]));
|
||||
} else {
|
||||
throw new Error("At /" + path.join("/") + " expected Map has key '" + key + "' but actual does not.");
|
||||
}
|
||||
});
|
||||
actual.forEach((value, key) => {
|
||||
if (!expected.has(key)) {
|
||||
throw new Error("At /" + path.join("/") + " actual Map has key '" + key + "' but expected does not.");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
throw new Error("At /" + path.join("/") + " expected is Map but actual is not.");
|
||||
}
|
||||
}
|
||||
if (expected instanceof Set) {
|
||||
if (actual instanceof Set) {
|
||||
expected.forEach(i => {
|
||||
if (!actual.has(i)) {
|
||||
throw new Error("At /" + path.join("/") + " expected Set has item '" + i + "' but actual does not.");
|
||||
}
|
||||
});
|
||||
actual.forEach(i => {
|
||||
if (!expected.has(i)) {
|
||||
throw new Error("At /" + path.join("/") + " actual Set has item '" + i + "' but expected does not.");
|
||||
}
|
||||
})
|
||||
} else {
|
||||
throw new Error("At /" + path.join("/") + " expected is Set but actual is not.");
|
||||
}
|
||||
}
|
||||
for (let key in actual) {
|
||||
if (!(key in expected)) {
|
||||
throw new Error("At /" + path.join("/") + " found unexpected key " + key + ".");
|
||||
}
|
||||
assertDeepEqual(actual[key], expected[key], path.concat([key]));
|
||||
}
|
||||
for (let key in expected) {
|
||||
if (!(key in actual)) {
|
||||
throw new Error("At /" + path.join("/") + " expected a key " + key + ".");
|
||||
}
|
||||
}
|
||||
} else if (actual !== expected) {
|
||||
throw new Error("At /" + path.join("/") + " actual: '" + actual + "' and expected: '" + expected + "' differ.");
|
||||
}
|
||||
}
|
||||
|
||||
export function assertDeepSuperset(actual, expected, path: any[] = []): void {
|
||||
let typeofActual = typeof actual;
|
||||
let typeofExpected = typeof expected;
|
||||
if (typeofActual !== typeofExpected) {
|
||||
throw new Error("At /" + path.join("/") + " types of actual " + typeofActual + " and expected " + typeofExpected + " differ.");
|
||||
} else if (typeofActual === "object" || typeofActual === "array") {
|
||||
for (let key in expected) {
|
||||
if (!(key in actual)) {
|
||||
throw new Error("At /" + path.join("/") + " expected a key " + key + ".");
|
||||
}
|
||||
assertDeepSuperset(actual[key], expected[key], path.concat([key]));
|
||||
}
|
||||
} else if (actual !== expected) {
|
||||
throw new Error("At /" + path.join("/") + " actual: '" + actual + "' and expected: '" + expected + "' differ.");
|
||||
}
|
||||
}
|
||||
|
||||
export function assertNull(actual: any, message?: string) {
|
||||
if (actual !== null && actual !== undefined) {
|
||||
throw new Error(message + " Actual: " + actual + " is not null/undefined");
|
||||
|
Reference in New Issue
Block a user