You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have a json-file with two structures inside. And depending on data in one structure I validate data in the second one.
Without regexp all works as expected. But with regexp I have a problem and need help)
Validation task description:
If description.someapp.level1.folder.aaa exists, I check existence of object_aaa in list: "/tmp/content-1.yml".structure.xyz.list1. If object_aaa does not exist, error will be raised for user: "ERROR: object_aaa does not exist".
Expected test results:
"folder" element
List object
Name
Test
+
+
aaa
test ok
+
-
bbb
test fail
-
-
ccc
test ok (don't check because no "ccc" element inside "folder" structure)
package cue_rules
import "list"
{
...
description?: {
someapp?: {
level1?: {
folder?: {
aaa?: {...},
bbb?: {...},
ccc?: {...}
}
}
}
}
["/tmp/content-1.yml"]: "structure"?: {
...
"xyz"!: {
list1="list1"!: [...]
...
if description.someapp.level1.folder.aaa != null {
"ERROR: object_aaa does not exist": list.Contains(list1,"object_aaa") & true
}
if description.someapp.level1.folder.bbb != null {
"ERROR: object_bbb does not exist": list.Contains(list1,"object_bbb") & true
}
if description.someapp.level1.folder.ccc != null {
"ERROR: object_ccc does not exist": list.Contains(list1,"object_ccc") & true
}
}
}
}
All works fine:
$ cue vet data.json noregexp_check_rules.cue
"/tmp/content-1.yml".structure.xyz."ERROR: object_bbb does not exist": conflicting values true and false:
./noregexp_check_rules.cue:6:1
./noregexp_check_rules.cue:20:27
./noregexp_check_rules.cue:28:7
./noregexp_check_rules.cue:29:45
./noregexp_check_rules.cue:29:81
But if I want to use instead of "someapp" something like "qwerty-123.456-app" or "asdfgh-000.111-app" , I have to use regex: ".+app".
withregexp_check_rules.cue:
package cue_rules
import "list"
{
...
description?: {
".+app"?: {
level1?: {
folder?: {
aaa?: {...},
bbb?: {...},
ccc?: {...}
}
}
}
}
["/tmp/content-1.yml"]: "structure"?: {
...
"xyz"!: {
list1="list1"!: [...]
...
if ("description..+app.level1.folder.aaa") != null {
"ERROR: object_aaa does not exist": list.Contains(list1,"object_aaa") & true
}
if ("description..+app.level1.folder.bbb") != null {
"ERROR: object_bbb does not exist": list.Contains(list1,"object_bbb") & true
}
if ("description..+app.level1.folder.ccc") != null {
"ERROR: object_ccc does not exist": list.Contains(list1,"object_ccc") & true
}
}
}
}
Here "if" statements not working correct:
$ cue vet data.json withregexp_check_rules.cue
"/tmp/content-1.yml".structure.xyz."ERROR: object_bbb does not exist": conflicting values true and false:
./withregexp_check_rules.cue:5:1
./withregexp_check_rules.cue:19:27
./withregexp_check_rules.cue:27:7
./withregexp_check_rules.cue:28:45
./withregexp_check_rules.cue:28:81
"/tmp/content-1.yml".structure.xyz."ERROR: object_ccc does not exist": conflicting values true and false:
./withregexp_check_rules.cue:5:1
./withregexp_check_rules.cue:19:27
./withregexp_check_rules.cue:30:7
./withregexp_check_rules.cue:31:45
./withregexp_check_rules.cue:31:81
I suppose the raison is that cue interprets ("description..+app.level1.folder.ccc") statement as a string.
I tried to use alias for regexp inside "description" scope, but I got error: "description: unreferenced alias or let clause".
Question: how I can reference ".+app" regexp from "description" scope inside of "/tmp/content-1.yml".structure.xyz.list scope? How to correctly write "if" statement?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I have a json-file with two structures inside. And depending on data in one structure I validate data in the second one.
Without regexp all works as expected. But with regexp I have a problem and need help)
Validation task description:
If description.someapp.level1.folder.aaa exists, I check existence of object_aaa in list: "/tmp/content-1.yml".structure.xyz.list1. If object_aaa does not exist, error will be raised for user: "ERROR: object_aaa does not exist".
Expected test results:
Example (success):
data.json:
noregexp_check_rules.cue:
All works fine:
But if I want to use instead of "someapp" something like "qwerty-123.456-app" or "asdfgh-000.111-app" , I have to use regex: ".+app".
withregexp_check_rules.cue:
Here "if" statements not working correct:
I suppose the raison is that cue interprets ("description..+app.level1.folder.ccc") statement as a string.
I tried to use alias for regexp inside "description" scope, but I got error: "description: unreferenced alias or let clause".
Question: how I can reference ".+app" regexp from "description" scope inside of "/tmp/content-1.yml".structure.xyz.list scope? How to correctly write "if" statement?
Beta Was this translation helpful? Give feedback.
All reactions