From fb75994d097cb1d6a1a0ea871c2d2213aa4e3c31 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 19 Nov 2026 13:26:42 +0100 Subject: Path over contents evaluation --- lib/configuration/tests/path.t | 161 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 lib/configuration/tests/path.t (limited to 'lib/configuration/tests') diff --git a/lib/configuration/tests/path.t b/lib/configuration/tests/path.t new file mode 100644 index 0000000..1532643 --- /dev/null +++ b/lib/configuration/tests/path.t @@ -0,0 +1,161 @@ +Resolve a path from a content: each segment is the name of a reference field, +and the result is the target of the last segment. + + $ tests --path legalEntity entity.employee.country < { + > "list": [ + > { + > "id": "region_list", + > "field": [ { "name": "label", "label": {}, "type": "text" } ] + > }, + > { + > "id": "country_list", + > "field": [ + > { "name": "code", "label": {}, "type": "text" }, + > { + > "name": "region", + > "label": {}, + > "type": { "content": "region_list" } + > } + > ] + > } + > ], + > "content": [ + > { + > "id": "legalEntity", + > "section": [ + > { + > "field": [ + > { + > "name": "entity", + > "label": {}, + > "type": { "content": "entity" } + > } + > ] + > } + > ] + > }, + > { + > "id": "entity", + > "section": [ + > { + > "field": [ + > { + > "name": "employee", + > "label": {}, + > "type": { "content": "employee" } + > } + > ] + > } + > ] + > }, + > { + > "id": "employee", + > "section": [ + > { + > "field": [ + > { "name": "name", "label": {}, "type": "text" }, + > { + > "name": "country", + > "label": {}, + > "type": { "content": "country_list" } + > } + > ] + > } + > ] + > } + > ] + > } + > EOF + field country (reference -> list country_list) + +Intermediate segments resolve to the targeted content: + + $ tests --path legalEntity entity < { + > "content": [ + > { + > "id": "legalEntity", + > "section": [ + > { + > "field": [ + > { "name": "entity", "label": {}, "type": { "content": "entity" } } + > ] + > } + > ] + > }, + > { "id": "entity" } + > ] + > } + > EOF + field entity (reference -> content entity) + +The path can go through the fields of a list: + + $ tests --path legalEntity entity.employee.country.region < { + > "list": [ + > { "id": "region_list" }, + > { + > "id": "country_list", + > "field": [ + > { "name": "region", "label": {}, "type": { "content": "region_list" } } + > ] + > } + > ], + > "content": [ + > { + > "id": "legalEntity", + > "section": [ { "field": [ + > { "name": "entity", "label": {}, "type": { "content": "entity" } } + > ] } ] + > }, + > { + > "id": "entity", + > "section": [ { "field": [ + > { "name": "employee", "label": {}, "type": { "content": "employee" } } + > ] } ] + > }, + > { + > "id": "employee", + > "section": [ { "field": [ + > { "name": "country", "label": {}, "type": { "content": "country_list" } } + > ] } ] + > } + > ] + > } + > EOF + field region (reference -> list region_list) + +A segment that is not a reference field, or does not exist, does not resolve: + + $ tests --path legalEntity entity.employee.name < { + > "content": [ + > { + > "id": "legalEntity", + > "section": [ { "field": [ + > { "name": "entity", "label": {}, "type": { "content": "entity" } } + > ] } ] + > }, + > { + > "id": "entity", + > "section": [ { "field": [ + > { "name": "employee", "label": {}, "type": { "content": "employee" } } + > ] } ] + > }, + > { + > "id": "employee", + > "section": [ { "field": [ + > { "name": "name", "label": {}, "type": "text" } + > ] } ] + > } + > ] + > } + > EOF + field name (text) + + $ tests --path legalEntity unknown.path < { "content": [ { "id": "legalEntity" } ] } + > EOF + unresolved path unknown.path -- cgit v1.2.3