mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
support of or-functions (#18)
* support of multiple definitions of the same function * handle functions producing an error Signed-off-by: eric-therond <eric.therond.fr@gmail.com>
This commit is contained in:
@@ -45,3 +45,17 @@ cases:
|
||||
want_result:
|
||||
a: -11
|
||||
|
||||
- note: call-return-undefined
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
inc(x) = y {
|
||||
x > 10 # This will evaluate to false.
|
||||
y = 100 # y will be undefined.
|
||||
}
|
||||
|
||||
a1 = inc(5)
|
||||
query: data.test
|
||||
want_result: {}
|
||||
|
||||
154
tests/interpreter/cases/call/or.yaml
Normal file
154
tests/interpreter/cases/call/or.yaml
Normal file
@@ -0,0 +1,154 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cases:
|
||||
- note: or-error-output
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
inc(x) = x + 1
|
||||
inc(x) = x + 4
|
||||
|
||||
a1 = inc(5)
|
||||
query: data.test
|
||||
error: functions must not produce multiple outputs for same inputs
|
||||
|
||||
- note: or-ok
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
inc(x) = x + 1
|
||||
inc(x) = x + 1
|
||||
|
||||
a1 = inc(5)
|
||||
query: data.test
|
||||
want_result:
|
||||
a1: 6
|
||||
|
||||
- note: or-true
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
inc(x) = 7 == x
|
||||
inc(x) = 7 == x
|
||||
|
||||
a1 = inc(7)
|
||||
query: data.test
|
||||
want_result:
|
||||
a1: true
|
||||
|
||||
- note: or-false
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
inc(x) = 8 == x
|
||||
inc(x) = 3 == x
|
||||
|
||||
a1 = inc(2)
|
||||
query: data.test
|
||||
want_result:
|
||||
a1: false
|
||||
|
||||
- note: or-undefined
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
inc(x) = x + 1
|
||||
inc(x) = x + 1
|
||||
inc(x) = y {
|
||||
x > 10 # This will evaluate to false.
|
||||
y = 100 # y will be undefined.
|
||||
}
|
||||
|
||||
a1 = inc(5)
|
||||
query: data.test
|
||||
want_result:
|
||||
a1: 6
|
||||
|
||||
- note: or-first-undefined
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
inc(x) = y {
|
||||
x > 10 # This will evaluate to false.
|
||||
y = 100 # y will be undefined.
|
||||
}
|
||||
inc(x) = x + 1
|
||||
inc(x) = x + 1
|
||||
|
||||
a1 = inc(5)
|
||||
query: data.test
|
||||
want_result:
|
||||
a1: 6
|
||||
|
||||
- note: or-all-undefined
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
inc(x1) = y1 {
|
||||
x1 > 10 # This will evaluate to false.
|
||||
y1 = 100 # y will be undefined.
|
||||
}
|
||||
inc(x2) = y2 {
|
||||
x2 > 10 # This will evaluate to false.
|
||||
y2 = 100 # y will be undefined.
|
||||
}
|
||||
|
||||
a1 = inc(5)
|
||||
query: data.test
|
||||
want_result: {}
|
||||
|
||||
- note: or-one-error
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
fcn(x) = y {
|
||||
y = x + 1
|
||||
}
|
||||
|
||||
fcn(x) = y {
|
||||
y = concat(" ", ["hello", x])
|
||||
}
|
||||
|
||||
a1 = fcn("world")
|
||||
a2 = fcn(5)
|
||||
query: data.test
|
||||
want_result:
|
||||
a1:
|
||||
set!: [hello world]
|
||||
a2:
|
||||
set!: [6]
|
||||
|
||||
- note: or-all-error
|
||||
data: {}
|
||||
modules:
|
||||
- |
|
||||
package test
|
||||
|
||||
fcn(x) = y {
|
||||
y = x + 1
|
||||
}
|
||||
|
||||
fcn(x) = y {
|
||||
y = x + 1
|
||||
}
|
||||
|
||||
a1 = fcn("world")
|
||||
query: data.test
|
||||
error: "`add` expects numeric argument. Got `\"world\"` instead"
|
||||
Reference in New Issue
Block a user