Skip to content

Commit

Permalink
Update tests for set-property command
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Mar 31, 2024
1 parent 087edf0 commit 33324c5
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/api-output/parseSetAttribute/object-path-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """type \"object-path\" (`\"b\".\"a\"`) as key is not allowed in this JSON dict, allowed types are: [`string`] (second element of the tuple)"""
1 change: 1 addition & 0 deletions tests/api-output/parseSetAttribute/object-path-2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """type \"object-path\" (`\"b\".\"a\"`) as key is not allowed in this JSON dict, allowed types are: [`string`] (second element of the tuple)"""
1 change: 1 addition & 0 deletions tests/api-output/parseSetCss/object-path-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """type \"object-path\" (`\"b\".\"a\"`) as key is not allowed in this JSON dict, allowed types are: [`string`] (second element of the tuple)"""
1 change: 1 addition & 0 deletions tests/api-output/parseSetCss/object-path-2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error = """type \"object-path\" (`\"b\".\"a\"`) as key is not allowed in this JSON dict, allowed types are: [`string`] (second element of the tuple)"""
19 changes: 18 additions & 1 deletion tests/api-output/parseSetProperty/basic-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ instructions = [
"""let parseSetPropertyElem = await page.$(\"a\");
if (parseSetPropertyElem === null) { throw '\"a\" not found'; }
await page.evaluate(e => {
e[\"\\\"b\"] = \"c\";
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"\\\"b\"], \"c\");
}, parseSetPropertyElem);""",
]
19 changes: 18 additions & 1 deletion tests/api-output/parseSetProperty/basic-2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ instructions = [
"""let parseSetPropertyElem = await page.$(\"a\");
if (parseSetPropertyElem === null) { throw '\"a\" not found'; }
await page.evaluate(e => {
e[\"b\"] = \"\\\"c\";
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\"], \"\\\"c\");
}, parseSetPropertyElem);""",
]
19 changes: 18 additions & 1 deletion tests/api-output/parseSetProperty/basic-3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ instructions = [
"""let parseSetPropertyElem = await page.$(\"a\");
if (parseSetPropertyElem === null) { throw '\"a\" not found'; }
await page.evaluate(e => {
e[\"b\"] = \"c\";
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\"], \"c\");
}, parseSetPropertyElem);""",
]
21 changes: 19 additions & 2 deletions tests/api-output/parseSetProperty/basic-4.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@ instructions = [
"""let parseSetPropertyElem = await page.$(\"a\");
if (parseSetPropertyElem === null) { throw '\"a\" not found'; }
await page.evaluate(e => {
e[\"b\"] = \"c\";
e[\"d\"] = \"e\";
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\"], \"c\");
setObjValue(e, [\"d\"], \"e\");
}, parseSetPropertyElem);""",
]
19 changes: 18 additions & 1 deletion tests/api-output/parseSetProperty/basic-5.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ instructions = [
"""let parseSetPropertyElem = await page.$(\"a\");
if (parseSetPropertyElem === null) { throw '\"a\" not found'; }
await page.evaluate(e => {
delete e[\"b\"];
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\"], undefined);
}, parseSetPropertyElem);""",
]
21 changes: 19 additions & 2 deletions tests/api-output/parseSetProperty/basic-6.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@ instructions = [
"""let parseSetPropertyElem = await page.$(\"a\");
if (parseSetPropertyElem === null) { throw '\"a\" not found'; }
await page.evaluate(e => {
delete e[\"b\"];
e[\"a\"] = \"b\";
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\"], undefined);
setObjValue(e, [\"a\"], \"b\");
}, parseSetPropertyElem);""",
]
19 changes: 18 additions & 1 deletion tests/api-output/parseSetProperty/multiline-2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ instructions = [
if (parseSetPropertyElem.length === 0) { throw 'XPath \"//a\" not found'; }
parseSetPropertyElem = parseSetPropertyElem[0];
await page.evaluate(e => {
e[\"b\"] = \"c\";
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\"], \"c\");
}, parseSetPropertyElem);""",
]
19 changes: 18 additions & 1 deletion tests/api-output/parseSetProperty/multiline-3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ instructions = [
if (parseSetPropertyElem.length === 0) { throw 'XPath \"//a\" not found'; }
parseSetPropertyElem = parseSetPropertyElem[0];
await page.evaluate(e => {
e[\"b\"] = \"c\\n\";
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\"], \"c\\n\");
}, parseSetPropertyElem);""",
]
24 changes: 24 additions & 0 deletions tests/api-output/parseSetProperty/object-path-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
instructions = [
"""let parseSetPropertyElem = await page.$(\"a\");
if (parseSetPropertyElem === null) { throw '\"a\" not found'; }
await page.evaluate(e => {
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\",\"a\"], \"c\");
}, parseSetPropertyElem);""",
]
25 changes: 25 additions & 0 deletions tests/api-output/parseSetProperty/object-path-2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
instructions = [
"""let parseSetPropertyElem = await page.$(\"a\");
if (parseSetPropertyElem === null) { throw '\"a\" not found'; }
await page.evaluate(e => {
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\",\"a\"], \"c\");
setObjValue(e, [\"d\"], \"x\");
}, parseSetPropertyElem);""",
]
19 changes: 18 additions & 1 deletion tests/api-output/parseSetProperty/xpath-3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ instructions = [
if (parseSetPropertyElem.length === 0) { throw 'XPath \"//a\" not found'; }
parseSetPropertyElem = parseSetPropertyElem[0];
await page.evaluate(e => {
e[\"b\"] = \"c\";
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) {
if (value === undefined) {
return;
}
object[subPath] = {};
}
object = object[subPath];
}
if (value === undefined) {
delete object[path[path.length - 1]];
} else {
object[path[path.length - 1]] = value;
}
}
setObjValue(e, [\"b\"], \"c\");
}, parseSetPropertyElem);""",
]
7 changes: 7 additions & 0 deletions tests/ui/property.goml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ assert-window-property-false: {"size": "a"}
set-window-property: {"size": "a"}
assert-window-property: {"size": "a"}

// object-path
assert-window-property-false: {"wa"."wo": "a"}
set-window-property: {"wa"."wo": "a"}
assert-window-property: {"wa"."wo": "a"}
Expand All @@ -14,10 +15,16 @@ assert-document-property-false: {"size": "a"}
set-document-property: {"size": "a"}
assert-document-property: {"size": "a"}

// object-path
assert-document-property-false: {"wa"."wo": "a"}
set-document-property: {"wa"."wo": "a"}
assert-document-property: {"wa"."wo": "a"}

assert-property-false: ("header", {"yolo": "a"})
set-property: ("header", {"yolo": "a"})
assert-property: ("header", {"yolo": "a"})

// object-path
assert-property-false: ("header", {"ab"."c": "a"})
set-property: ("header", {"ab"."c": "a"})
assert-property: ("header", {"ab"."c": "a"})
4 changes: 4 additions & 0 deletions tools/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ function checkAttributeProperty(x, func) {

// Multiline string.
func('("//a", {"b": "c\n"})', 'multiline-3');

// object-path
func('("a", {"b"."a": "c"})', 'object-path-1');
func('("a", {"b"."a": "c", "d": "x"})', 'object-path-2');
}

function checkClick(x, func) {
Expand Down

0 comments on commit 33324c5

Please sign in to comment.