summaryrefslogtreecommitdiff
path: root/lib/configuration/tests
diff options
context:
space:
mode:
Diffstat (limited to 'lib/configuration/tests')
-rw-r--r--lib/configuration/tests/configuration.t55
-rw-r--r--lib/configuration/tests/errors.t103
2 files changed, 149 insertions, 9 deletions
diff --git a/lib/configuration/tests/configuration.t b/lib/configuration/tests/configuration.t
index 880e690..5d14bbb 100644
--- a/lib/configuration/tests/configuration.t
+++ b/lib/configuration/tests/configuration.t
@@ -76,20 +76,17 @@ Cycles between elements are accepted when they are not mandatory to each other
-Lists are declared in the "list" key, with a source given either as a plain
-kind string or as an object with a "type" and an optional "file". A reference
-field can target a list, like a content:
+Lists are declared in the "list" key. A reference field can target a list,
+like a content:
$ tests --configuration <<EOF
> {
> "list": [
> {
- > "id": "user_type_list",
- > "source": "csv"
+ > "id": "user_type_list"
> },
> {
- > "id": "status_list",
- > "source": { "type": "csv", "file": "status.csv" }
+ > "id": "status_list"
> }
> ],
> "content": [
@@ -119,3 +116,47 @@ field can target a list, like a content:
> }
> EOF
+
+Lists can declare their own fields, directly under the "field" key (there is
+no section in a list). A reference field in a list can target another list:
+
+ $ tests --configuration <<EOF
+ > {
+ > "list": [
+ > {
+ > "id": "country_list",
+ > "field": [
+ > { "name": "name", "label": {}, "type": "text" },
+ > { "name": "code", "label": {}, "type": "text" }
+ > ]
+ > },
+ > {
+ > "id": "user_type_list",
+ > "field": [
+ > {
+ > "name": "country",
+ > "label": {},
+ > "type": { "content": "country_list" }
+ > }
+ > ]
+ > }
+ > ],
+ > "content": [
+ > {
+ > "id": "entity",
+ > "section": [
+ > {
+ > "field": [
+ > {
+ > "name": "user_type",
+ > "label": {},
+ > "type": { "content": "user_type_list" }
+ > }
+ > ]
+ > }
+ > ]
+ > }
+ > ]
+ > }
+ > EOF
+
diff --git a/lib/configuration/tests/errors.t b/lib/configuration/tests/errors.t
index 99ad465..b23f237 100644
--- a/lib/configuration/tests/errors.t
+++ b/lib/configuration/tests/errors.t
@@ -222,8 +222,7 @@ A list ID follows the same rules as a content ID:
> {
> "list": [
> {
- > "id": "foo.bar",
- > "source": "csv"
+ > "id": "foo.bar"
> }
> ],
> "content": []
@@ -235,3 +234,103 @@ A list ID follows the same rules as a content ID:
in field "id":
Expected an identifier with only the accepted characters, but got
"foo.bar"
+
+A reference field in a list can only target another list, not a content:
+
+ $ tests --configuration <<EOF
+ > {
+ > "list": [
+ > {
+ > "id": "user_type_list",
+ > "field": [
+ > {
+ > "name": "entity",
+ > "label": {},
+ > "type": { "content": "entity" }
+ > }
+ > ]
+ > }
+ > ],
+ > "content": [ { "id": "entity" } ]
+ > }
+ > EOF
+ in field "list":
+ while decoding a list:
+ element 0:
+ in field "field":
+ while decoding a list:
+ element 0:
+ in field "type":
+ I tried the following decoders but they all failed:
+ "text" decoder:
+ Expected a string, but got { "content": "entity" }
+ "content" decoder:
+ References in a list can only target a list declared before it, but got
+ { "content": "entity" }
+
+A list cannot reference itself:
+
+ $ tests --configuration <<EOF
+ > {
+ > "list": [
+ > {
+ > "id": "user_type_list",
+ > "field": [
+ > {
+ > "name": "parent",
+ > "label": {},
+ > "type": { "content": "user_type_list" }
+ > }
+ > ]
+ > }
+ > ],
+ > "content": []
+ > }
+ > EOF
+ in field "list":
+ while decoding a list:
+ element 0:
+ in field "field":
+ while decoding a list:
+ element 0:
+ in field "type":
+ I tried the following decoders but they all failed:
+ "text" decoder:
+ Expected a string, but got { "content": "user_type_list" }
+ "content" decoder:
+ References in a list can only target a list declared before it, but got
+ { "content": "user_type_list" }
+
+A list cannot reference a list declared after it:
+
+ $ tests --configuration <<EOF
+ > {
+ > "list": [
+ > {
+ > "id": "first_list",
+ > "field": [
+ > {
+ > "name": "other",
+ > "label": {},
+ > "type": { "content": "second_list" }
+ > }
+ > ]
+ > },
+ > { "id": "second_list" }
+ > ],
+ > "content": []
+ > }
+ > EOF
+ in field "list":
+ while decoding a list:
+ element 0:
+ in field "field":
+ while decoding a list:
+ element 0:
+ in field "type":
+ I tried the following decoders but they all failed:
+ "text" decoder:
+ Expected a string, but got { "content": "second_list" }
+ "content" decoder:
+ References in a list can only target a list declared before it, but got
+ { "content": "second_list" }