From 33324c50cfb40be6e67af1f269594616d2177eb2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 31 Mar 2024 18:31:10 +0200 Subject: [PATCH] Update tests for `set-property` command --- .../parseSetAttribute/object-path-1.toml | 1 + .../parseSetAttribute/object-path-2.toml | 1 + .../api-output/parseSetCss/object-path-1.toml | 1 + .../api-output/parseSetCss/object-path-2.toml | 1 + .../api-output/parseSetProperty/basic-1.toml | 19 +++++++++++++- .../api-output/parseSetProperty/basic-2.toml | 19 +++++++++++++- .../api-output/parseSetProperty/basic-3.toml | 19 +++++++++++++- .../api-output/parseSetProperty/basic-4.toml | 21 ++++++++++++++-- .../api-output/parseSetProperty/basic-5.toml | 19 +++++++++++++- .../api-output/parseSetProperty/basic-6.toml | 21 ++++++++++++++-- .../parseSetProperty/multiline-2.toml | 19 +++++++++++++- .../parseSetProperty/multiline-3.toml | 19 +++++++++++++- .../parseSetProperty/object-path-1.toml | 24 ++++++++++++++++++ .../parseSetProperty/object-path-2.toml | 25 +++++++++++++++++++ .../api-output/parseSetProperty/xpath-3.toml | 19 +++++++++++++- tests/ui/property.goml | 7 ++++++ tools/api.js | 4 +++ 17 files changed, 228 insertions(+), 11 deletions(-) create mode 100644 tests/api-output/parseSetAttribute/object-path-1.toml create mode 100644 tests/api-output/parseSetAttribute/object-path-2.toml create mode 100644 tests/api-output/parseSetCss/object-path-1.toml create mode 100644 tests/api-output/parseSetCss/object-path-2.toml create mode 100644 tests/api-output/parseSetProperty/object-path-1.toml create mode 100644 tests/api-output/parseSetProperty/object-path-2.toml diff --git a/tests/api-output/parseSetAttribute/object-path-1.toml b/tests/api-output/parseSetAttribute/object-path-1.toml new file mode 100644 index 000000000..389b76ac4 --- /dev/null +++ b/tests/api-output/parseSetAttribute/object-path-1.toml @@ -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)""" diff --git a/tests/api-output/parseSetAttribute/object-path-2.toml b/tests/api-output/parseSetAttribute/object-path-2.toml new file mode 100644 index 000000000..389b76ac4 --- /dev/null +++ b/tests/api-output/parseSetAttribute/object-path-2.toml @@ -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)""" diff --git a/tests/api-output/parseSetCss/object-path-1.toml b/tests/api-output/parseSetCss/object-path-1.toml new file mode 100644 index 000000000..389b76ac4 --- /dev/null +++ b/tests/api-output/parseSetCss/object-path-1.toml @@ -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)""" diff --git a/tests/api-output/parseSetCss/object-path-2.toml b/tests/api-output/parseSetCss/object-path-2.toml new file mode 100644 index 000000000..389b76ac4 --- /dev/null +++ b/tests/api-output/parseSetCss/object-path-2.toml @@ -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)""" diff --git a/tests/api-output/parseSetProperty/basic-1.toml b/tests/api-output/parseSetProperty/basic-1.toml index f4eb4bac5..44fa2b0ec 100644 --- a/tests/api-output/parseSetProperty/basic-1.toml +++ b/tests/api-output/parseSetProperty/basic-1.toml @@ -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);""", ] diff --git a/tests/api-output/parseSetProperty/basic-2.toml b/tests/api-output/parseSetProperty/basic-2.toml index 631c7a16f..187c0b506 100644 --- a/tests/api-output/parseSetProperty/basic-2.toml +++ b/tests/api-output/parseSetProperty/basic-2.toml @@ -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);""", ] diff --git a/tests/api-output/parseSetProperty/basic-3.toml b/tests/api-output/parseSetProperty/basic-3.toml index f0712a0d1..98d3005fe 100644 --- a/tests/api-output/parseSetProperty/basic-3.toml +++ b/tests/api-output/parseSetProperty/basic-3.toml @@ -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);""", ] diff --git a/tests/api-output/parseSetProperty/basic-4.toml b/tests/api-output/parseSetProperty/basic-4.toml index 934bc2a82..e5c60f348 100644 --- a/tests/api-output/parseSetProperty/basic-4.toml +++ b/tests/api-output/parseSetProperty/basic-4.toml @@ -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);""", ] diff --git a/tests/api-output/parseSetProperty/basic-5.toml b/tests/api-output/parseSetProperty/basic-5.toml index 18a6796ac..e73c9ab3d 100644 --- a/tests/api-output/parseSetProperty/basic-5.toml +++ b/tests/api-output/parseSetProperty/basic-5.toml @@ -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);""", ] diff --git a/tests/api-output/parseSetProperty/basic-6.toml b/tests/api-output/parseSetProperty/basic-6.toml index 064a94141..8588fcc3d 100644 --- a/tests/api-output/parseSetProperty/basic-6.toml +++ b/tests/api-output/parseSetProperty/basic-6.toml @@ -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);""", ] diff --git a/tests/api-output/parseSetProperty/multiline-2.toml b/tests/api-output/parseSetProperty/multiline-2.toml index fcd2b8835..2318f73e1 100644 --- a/tests/api-output/parseSetProperty/multiline-2.toml +++ b/tests/api-output/parseSetProperty/multiline-2.toml @@ -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);""", ] diff --git a/tests/api-output/parseSetProperty/multiline-3.toml b/tests/api-output/parseSetProperty/multiline-3.toml index 478222440..ec03dddf3 100644 --- a/tests/api-output/parseSetProperty/multiline-3.toml +++ b/tests/api-output/parseSetProperty/multiline-3.toml @@ -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);""", ] diff --git a/tests/api-output/parseSetProperty/object-path-1.toml b/tests/api-output/parseSetProperty/object-path-1.toml new file mode 100644 index 000000000..51864baf6 --- /dev/null +++ b/tests/api-output/parseSetProperty/object-path-1.toml @@ -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);""", +] diff --git a/tests/api-output/parseSetProperty/object-path-2.toml b/tests/api-output/parseSetProperty/object-path-2.toml new file mode 100644 index 000000000..e3b61bbfc --- /dev/null +++ b/tests/api-output/parseSetProperty/object-path-2.toml @@ -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);""", +] diff --git a/tests/api-output/parseSetProperty/xpath-3.toml b/tests/api-output/parseSetProperty/xpath-3.toml index fcd2b8835..2318f73e1 100644 --- a/tests/api-output/parseSetProperty/xpath-3.toml +++ b/tests/api-output/parseSetProperty/xpath-3.toml @@ -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);""", ] diff --git a/tests/ui/property.goml b/tests/ui/property.goml index b70d88db0..51022271c 100644 --- a/tests/ui/property.goml +++ b/tests/ui/property.goml @@ -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"} @@ -14,6 +15,7 @@ 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"} @@ -21,3 +23,8 @@ 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"}) diff --git a/tools/api.js b/tools/api.js index 16a64e42d..cdbd25326 100644 --- a/tools/api.js +++ b/tools/api.js @@ -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) {