refactor common test helpers into test/

This way we can share them with multiple tests
This commit is contained in:
David Lechner
2020-06-10 21:59:34 -05:00
committed by David Lechner
parent 8ba4143fa7
commit 31c3e2b52e
16 changed files with 205 additions and 223 deletions
-15
View File
@@ -21,18 +21,3 @@ export function assert(condition: boolean, message: string): void {
export function hex(n: number, pad: number): string {
return `0x${n.toString(16).padStart(pad, '0')}`;
}
/**
* Looks up a nested property in an object.
* @param obj The object
* @param id The property path
*/
export function lookup(obj: object, id: string): string | undefined {
const value = id
.split('.')
.reduce((pv, cv) => pv && (pv as Record<string, object>)[cv], obj);
if (typeof value === 'string') {
return value;
}
return undefined;
}