Skip to content

Commit

Permalink
internal/core/validate: initial implementation
Browse files Browse the repository at this point in the history
This implements the Validate method of the old
implementation.

As CUE now recursively evaluates unconditionally,
this now is as simple as walking
the values and checking for properties.

Change-Id: Ibdbba6e2b268c2f02be46dc24132c7f7bc7039b1
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6506
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jul 19, 2020
1 parent 08a9fdb commit 38a19f8
Show file tree
Hide file tree
Showing 55 changed files with 628 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cue/testdata/basicrewrite/000_errors.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ e: true
e: (_|_(from source) == _|_(from source))
}
-- out/eval --
Errors:
from source:
./in.cue:1:4
from source:
./in.cue:2:11

Result:
(_|_){
// [user]
a: (_|_){
Expand Down
9 changes: 9 additions & 0 deletions cue/testdata/basicrewrite/001_regexp.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ e3: _|_ // conflicting values !="a" and <5 (mismatched types string and number)
e3: (!="a" & <5)
}
-- out/eval --
Errors:
invalid value *adt.BoundValue (mismatched types number and string)
invalid value *adt.Vertex (out of bound *adt.BoundValue)
cannot use *adt.Num (type int) as type (string|bytes):
./in.cue:18:5
cannot use *adt.Bool (type bool) as type (string|bytes):
./in.cue:19:5

Result:
(_|_){
// [eval]
c1: (bool){ true }
Expand Down
25 changes: 25 additions & 0 deletions cue/testdata/basicrewrite/002_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,31 @@ e8: _|_ // invalid operation 1.0 mod 1 (mismatched types float and int)
e8: (1.0 mod 1)
}
-- out/eval --
Errors:
failed arithmetic: division by zero:
./in.cue:8:10
failed arithmetic: division undefined:
./in.cue:9:10
division by zero:
./in.cue:13:9
division by zero:
./in.cue:14:9
division by zero:
./in.cue:15:9
division by zero:
./in.cue:16:9
invalid operands *adt.Num and *adt.String to '+' (type int and string):
./in.cue:23:5
invalid operands *adt.Num and *adt.Num to 'div' (type float and int):
./in.cue:29:5
invalid operands *adt.Num and *adt.Num to 'rem' (type int and float):
./in.cue:30:5
invalid operands *adt.Num and *adt.Num to 'quo' (type int and float):
./in.cue:31:5
invalid operands *adt.Num and *adt.Num to 'mod' (type float and int):
./in.cue:32:5

Result:
(_|_){
// [eval]
i1: (int){ 1 }
Expand Down
19 changes: 19 additions & 0 deletions cue/testdata/basicrewrite/003_integer-specific_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ me2: _|_ // invalid operation 2 mod 1.0 (mismatched types int and float)
me2: (2 mod 1.0)
}
-- out/eval --
Errors:
invalid operands *adt.Num and *adt.Num to 'quo' (type float and int):
./in.cue:5:6
invalid operands *adt.Num and *adt.Num to 'quo' (type int and float):
./in.cue:6:6
invalid operands *adt.Num and *adt.Num to 'rem' (type float and int):
./in.cue:12:6
invalid operands *adt.Num and *adt.Num to 'rem' (type int and float):
./in.cue:13:6
invalid operands *adt.Num and *adt.Num to 'div' (type float and int):
./in.cue:19:6
invalid operands *adt.Num and *adt.Num to 'div' (type int and float):
./in.cue:20:6
invalid operands *adt.Num and *adt.Num to 'mod' (type float and int):
./in.cue:26:6
invalid operands *adt.Num and *adt.Num to 'mod' (type int and float):
./in.cue:27:6

Result:
(_|_){
// [eval]
q1: (int){ 2 }
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/basicrewrite/004_booleans.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ e: _|_ // conflicting values true and false
e: !true
}
-- out/eval --
Errors:
incompatible values *adt.Bool and *adt.Bool

Result:
(_|_){
// [eval]
t: (bool){ true }
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/basicrewrite/005_boolean_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ f: _|_ // conflicting values true and false
f: (true & false)
}
-- out/eval --
Errors:
incompatible values *adt.Bool and *adt.Bool

Result:
(_|_){
// [eval]
a: (bool){ true }
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/basicrewrite/006_basic_type.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ f: true
f: bool
}
-- out/eval --
Errors:
invalid value *adt.BasicType (mismatched types float and int)

Result:
(_|_){
// [eval]
a: (int){ 1 }
Expand Down
7 changes: 7 additions & 0 deletions cue/testdata/basicrewrite/007_strings_and_bytes.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ e1: _|_ // invalid operation 'b' + "c" (mismatched types bytes and string)
e1: ('b' + "c")
}
-- out/eval --
Errors:
invalid operands *adt.String and *adt.Bytes to '+' (type string and bytes):
./in.cue:10:5
invalid operands *adt.Bytes and *adt.String to '+' (type bytes and string):
./in.cue:11:5

Result:
(_|_){
// [eval]
s0: (string){ "foobar" }
Expand Down
9 changes: 9 additions & 0 deletions cue/testdata/basicrewrite/010_lists.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ e5: [1, 2, 4, _|_, // invalid value 8 (out of bound <=5)
])
}
-- out/eval --
Errors:
conflicting types
invalid value *adt.Num (out of bound *adt.BoundValue)
invalid list index d (type string):
./in.cue:5:12
invalid negative index *adt.Num:
./in.cue:6:8

Result:
(_|_){
// [eval]
list: (#list){
Expand Down
5 changes: 5 additions & 0 deletions cue/testdata/basicrewrite/011_list_arithmetic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ e: _|_ // negative number -1 multiplies list
e: (〈0;list〉 * -1)
}
-- out/eval --
Errors:
cannot convert negative number to uint64:
./in.cue:10:9

Result:
(_|_){
// [eval]
list: (#list){
Expand Down
7 changes: 7 additions & 0 deletions cue/testdata/basicrewrite/012_selecting.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ h: _|_ // invalid operation: [3].b (type list does not support selection)
].b
}
-- out/eval --
Errors:
invalid struct selector 4 (type int):
./in.cue:4:16
invalid list index b (type string):
./in.cue:7:13

Result:
(_|_){
// [eval]
obj: (struct){
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/basicrewrite/013_obj_unify.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ e: _|_ // conflicting values 1 and {a: 3} (mismatched types int and struct)
}
}
-- out/eval --
Errors:
conflicting values struct and int

Result:
(_|_){
// [eval]
o1: (struct){
Expand Down
10 changes: 10 additions & 0 deletions cue/testdata/basicrewrite/015_types.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ m: _|_ // invalid operation -false (- bool)
m: -false
}
-- out/eval --
Errors:
invalid value *adt.BasicType (mismatched types string and int)
value can never become concrete:
./in.cue:7:5
invalid operation +*adt.UnaryExpr (+ bool):
./in.cue:8:5
invalid operation -*adt.UnaryExpr (- bool):
./in.cue:9:5

Result:
(_|_){
// [eval]
i: (int){ int }
Expand Down
5 changes: 5 additions & 0 deletions cue/testdata/basicrewrite/016_comparison.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ err: _|_ // invalid operation 2 == "s" (mismatched types int and string)
err: (2 == "s")
}
-- out/eval --
Errors:
invalid operands *adt.Num and *adt.String to '==' (type int and string):
./in.cue:9:6

Result:
(_|_){
// [eval]
lss: (bool){ true }
Expand Down
5 changes: 5 additions & 0 deletions cue/testdata/basicrewrite/017_null.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ call: _|_ // cannot call non-function null (type null)
call: null()
}
-- out/eval --
Errors:
cannot call non-function *adt.Null (type null):
./in.cue:9:7

Result:
(_|_){
// [eval]
eql: (bool){ true }
Expand Down
5 changes: 5 additions & 0 deletions cue/testdata/comprehensions/for.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ y: {} // check that empty struct after reference works.
k: { for v in e { v } }
e: int
-- out/eval --
Errors:
invalid operand e (found int, want list or struct):
./in.cue:7:15

Result:
(_|_){
// [eval]
b: (struct){
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/cycle/021_delayed_constraint_failure.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ b: _|_ // conflicting values 210 and 200
x: (〈0;x〉 + 1)
}
-- out/eval --
Errors:
incompatible values *adt.Num and *adt.Num

Result:
(_|_){
// [eval]
a: (int){ 100 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ a: {
}
}
-- out/eval --
Errors:
incompatible values *adt.String and *adt.String

Result:
(_|_){
// [eval]
a: (_|_){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ z3: z1-3 & 8
z3: 8
}
-- out/eval --
Errors:
incompatible values *adt.Num and *adt.Num:
./in.cue:44:6

Result:
(_|_){
// [eval]
xa1: (int){ 8 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ z3: 8
z3: 8
}
-- out/eval --
Errors:
incompatible values *adt.Num and *adt.Num:
./in.cue:37:6

Result:
(_|_){
// [eval]
xa1: (int){ 8 }
Expand Down
5 changes: 5 additions & 0 deletions cue/testdata/definitions/026_combined_definitions.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ d1: #D1 & {
}
}
-- out/eval --
Errors:
field `b` not allowed
field `c` not allowed

Result:
(_|_){
// [eval]
#D1: (#struct){
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/definitions/032_definitions_with_embedding.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
})
}
-- out/eval --
Errors:
field `d` not allowed

Result:
(_|_){
// [eval]
#E: (#struct){
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/definitions/033_Issue_#153.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Junk: {
})
}
-- out/eval --
Errors:
field `b` not allowed

Result:
(_|_){
// [eval]
listOfCloseds: (_|_){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ a: _|_ // field "f3" not allowed in closed struct
})
}
-- out/eval --
Errors:
cannot mix bulk optional fields with dynamic fields, embeddings, or comprehensions within the same struct
field `f3` not allowed

Result:
(_|_){
// [eval]
#A: (#struct){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ d: _|_ // field "aaa" not allowed in closed struct
})
}
-- out/eval --
Errors:
field `aaa` not allowed

Result:
(_|_){
// [eval]
#A: (#struct){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ a: #S & {
})
}
-- out/eval --
Errors:
field `b` not allowed

Result:
(_|_){
// [eval]
#S: (#struct){
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/eval/closed_disjunction.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ b: #A & {
d: 4
}
-- out/eval --
Errors:
field `d` not allowed

Result:
(_|_){
// [eval]
#A: (#struct){
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/eval/closedness.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ a: #A & {
}
}
-- out/eval --
Errors:
field `e` not allowed

Result:
(_|_){
// [eval]
#E: (#struct){
Expand Down
4 changes: 4 additions & 0 deletions cue/testdata/eval/disjunctions.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ e: b & { val: "foo" }
f: b & { name: "str", val: 3 }

-- out/eval --
Errors:
invalid value *adt.BasicType (mismatched types string and int)

Result:
(_|_){
// [eval]
a: (int){ |(*(int){ 1 }, (int){ int }) }
Expand Down
5 changes: 5 additions & 0 deletions cue/testdata/export/007.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ e: _|_ // undefined field "t"
}
}
-- out/eval --
Errors:
undefined field c:
./in.cue:1:41

Result:
(_|_){
// [eval]
#a: (#struct){
Expand Down

0 comments on commit 38a19f8

Please sign in to comment.