Skip to content

Commit

Permalink
Merge pull request #624 from GuillaumeGomez/more-bools
Browse files Browse the repository at this point in the history
Allow to use `boolean` values in more commands
  • Loading branch information
GuillaumeGomez authored Oct 25, 2024
2 parents 7289128 + 769aed9 commit 0f1897d
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/commands/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,13 @@ function parseAssertObjPropertyInner(parser, assertFalse, objName) {
'object-path': [],
},
valueTypes: {
'string': {},
'number': {
string: {},
number: {
allowNegative: true,
allowFloat: true,
},
'ident': {
boolean: {},
ident: {
allowed: ['null'],
},
},
Expand Down
18 changes: 16 additions & 2 deletions src/commands/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ function parseObjPropertyInner(parser, objName) {
},
valueTypes: {
// In case it's an ident, we only want to allow `null`.
ident: {
allowed: ['null'],
},
string: {},
boolean: {},
number: {
allowFloat: true,
allowNegative: true,
Expand All @@ -142,7 +146,13 @@ function parseObjPropertyInner(parser, objName) {

for (const [key, value] of json) {
const k_s = value.key.kind === 'object-path' ? key : `["${key}"]`;
content.push(`[${k_s}, "${value.value}"]`);
if (value.kind === 'string') {
content.push(`[${k_s}, "${value.value}"]`);
} else if (value.kind === 'ident') {
content.push(`[${k_s}, undefined]`);
} else {
content.push(`[${k_s}, ${value.value}]`);
}
}

if (content.length === 0) {
Expand All @@ -169,7 +179,11 @@ await page.evaluate(() => {
}
object = object[subPath];
}
object[path[path.length - 1]] = value;
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const ${varDict} = [
${indentString(content.join(',\n'), 2)}
Expand Down
8 changes: 6 additions & 2 deletions tests/api-output/parseSetDocumentProperty/basic-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ instructions = [
}
object = object[subPath];
}
object[path[path.length - 1]] = value;
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], \"2\"]
[[\"a\"], 2]
];
for (const [parsePropKey, parsePropValue] of parsePropDict) {
setObjValue(document, parsePropKey, parsePropValue);
Expand Down
26 changes: 26 additions & 0 deletions tests/api-output/parseSetDocumentProperty/basic-2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
instructions = [
"""await page.evaluate(() => {
function setObjValue(object, path, value) {
for (let i = 0; i < path.length - 1; ++i) {
const subPath = path[i];
if (object[subPath] === undefined || object[subPath] === null) {
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], true]
];
for (const [parsePropKey, parsePropValue] of parsePropDict) {
setObjValue(document, parsePropKey, parsePropValue);
}
});""",
]
wait = false
checkResult = true
26 changes: 26 additions & 0 deletions tests/api-output/parseSetDocumentProperty/basic-3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
instructions = [
"""await page.evaluate(() => {
function setObjValue(object, path, value) {
for (let i = 0; i < path.length - 1; ++i) {
const subPath = path[i];
if (object[subPath] === undefined || object[subPath] === null) {
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], \"b\"]
];
for (const [parsePropKey, parsePropValue] of parsePropDict) {
setObjValue(document, parsePropKey, parsePropValue);
}
});""",
]
wait = false
checkResult = true
6 changes: 5 additions & 1 deletion tests/api-output/parseSetDocumentProperty/escape-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ instructions = [
}
object = object[subPath];
}
object[path[path.length - 1]] = value;
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], \"2\"],
Expand Down
8 changes: 6 additions & 2 deletions tests/api-output/parseSetDocumentProperty/object-path-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ instructions = [
}
object = object[subPath];
}
object[path[path.length - 1]] = value;
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\",\"b\"], \"2\"]
[[\"a\",\"b\"], 2]
];
for (const [parsePropKey, parsePropValue] of parsePropDict) {
setObjValue(document, parsePropKey, parsePropValue);
Expand Down
6 changes: 5 additions & 1 deletion tests/api-output/parseSetDocumentProperty/object-path-2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ instructions = [
}
object = object[subPath];
}
object[path[path.length - 1]] = value;
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], \"2\"],
Expand Down
8 changes: 6 additions & 2 deletions tests/api-output/parseSetWindowProperty/basic-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ instructions = [
}
object = object[subPath];
}
object[path[path.length - 1]] = value;
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], \"2\"]
[[\"a\"], 2]
];
for (const [parsePropKey, parsePropValue] of parsePropDict) {
setObjValue(window, parsePropKey, parsePropValue);
Expand Down
26 changes: 26 additions & 0 deletions tests/api-output/parseSetWindowProperty/basic-2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
instructions = [
"""await page.evaluate(() => {
function setObjValue(object, path, value) {
for (let i = 0; i < path.length - 1; ++i) {
const subPath = path[i];
if (object[subPath] === undefined || object[subPath] === null) {
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], true]
];
for (const [parsePropKey, parsePropValue] of parsePropDict) {
setObjValue(window, parsePropKey, parsePropValue);
}
});""",
]
wait = false
checkResult = true
26 changes: 26 additions & 0 deletions tests/api-output/parseSetWindowProperty/basic-3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
instructions = [
"""await page.evaluate(() => {
function setObjValue(object, path, value) {
for (let i = 0; i < path.length - 1; ++i) {
const subPath = path[i];
if (object[subPath] === undefined || object[subPath] === null) {
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], \"b\"]
];
for (const [parsePropKey, parsePropValue] of parsePropDict) {
setObjValue(window, parsePropKey, parsePropValue);
}
});""",
]
wait = false
checkResult = true
6 changes: 5 additions & 1 deletion tests/api-output/parseSetWindowProperty/escape-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ instructions = [
}
object = object[subPath];
}
object[path[path.length - 1]] = value;
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], \"2\"],
Expand Down
8 changes: 6 additions & 2 deletions tests/api-output/parseSetWindowProperty/object-path-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ instructions = [
}
object = object[subPath];
}
object[path[path.length - 1]] = value;
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\",\"b\"], \"2\"]
[[\"a\",\"b\"], 2]
];
for (const [parsePropKey, parsePropValue] of parsePropDict) {
setObjValue(window, parsePropKey, parsePropValue);
Expand Down
6 changes: 5 additions & 1 deletion tests/api-output/parseSetWindowProperty/object-path-2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ instructions = [
}
object = object[subPath];
}
object[path[path.length - 1]] = value;
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
const parsePropDict = [
[[\"a\"], \"2\"],
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/property.goml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ assert-window-property-false: {"wa"."wo": "a"}
set-window-property: {"wa"."wo": "a"}
assert-window-property: {"wa"."wo": "a"}

set-window-property: {"size": true}
assert-window-property: {"size": true}
set-window-property: {"size": 12}
assert-window-property: {"size": 12}

assert-document-property-false: {"size": "a"}
set-document-property: {"size": "a"}
assert-document-property: {"size": "a"}

set-document-property: {"size": true}
assert-document-property: {"size": true}
set-document-property: {"size": 12}
assert-document-property: {"size": 12}

// object-path
assert-document-property-false: {"wa"."wo": "a"}
set-document-property: {"wa"."wo": "a"}
Expand Down
2 changes: 2 additions & 0 deletions tools/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2311,6 +2311,8 @@ function checkObjProperty(x, func) {
func('{"a": "2", "a": {"b": 1}}', 'err-5');

func('{"a": 2}', 'basic-1');
func('{"a": true}', 'basic-2');
func('{"a": "b"}', 'basic-3');
func('{"a": "2", "\\"b": "\'b"}', 'escape-1');

// object-path
Expand Down

0 comments on commit 0f1897d

Please sign in to comment.