1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:58:11 +00:00

LibJS: Convert all remaining non-Array tests to the new system :)

This commit is contained in:
Matthew Olsson 2020-07-05 17:26:26 -07:00 committed by Andreas Kling
parent 918f4affd5
commit 15de2eda2b
72 changed files with 2394 additions and 1998 deletions

View file

@ -1,47 +1,45 @@
load("test-common.js");
test("iterate through empty string", () => {
const a = [];
for (const property in "") {
a.push(property);
}
expect(a).toEqual([]);
});
try {
assertVisitsAll(visit => {
for (const property in "") {
visit(property);
}
}, []);
test("iterate through number", () => {
const a = [];
for (const property in 123) {
a.push(property);
}
expect(a).toEqual([]);
});
assertVisitsAll(visit => {
for (const property in 123) {
visit(property);
}
}, []);
test("iterate through empty object", () => {
const a = [];
for (const property in {}) {
a.push(property);
}
expect(a).toEqual([]);
});
assertVisitsAll(visit => {
for (const property in {}) {
visit(property);
}
}, []);
test("iterate through string", () => {
const a = [];
for (const property in "hello") {
a.push(property);
}
expect(a).toEqual(["0", "1", "2", "3", "4"]);
});
assertVisitsAll(
visit => {
for (const property in "hello") {
visit(property);
}
},
["0", "1", "2", "3", "4"]
);
assertVisitsAll(
visit => {
for (const property in { a: 1, b: 2, c: 2 }) {
visit(property);
}
},
["a", "b", "c"]
);
test("iterate through object", () => {
const a = [];
for (const property in { a: 1, b: 2, c: 2 }) {
a.push(property);
}
expect(a).toEqual(["a", "b", "c"]);
});
test("use already-declared variable", () => {
var property;
for (property in "abc");
assert(property === "2");
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
expect(property).toBe("2");
});