mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
420 lines
7.9 KiB
YAML
420 lines
7.9 KiB
YAML
# Copyright (c) Microsoft Corporation.
|
|
# Licensed under the MIT License.
|
|
|
|
cases:
|
|
- note: abs
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = [abs(-9), abs(9), abs(-9.1), abs(9.1)]
|
|
|
|
# Undefined
|
|
y { false }
|
|
z = abs(y)
|
|
query: data.test
|
|
want_result:
|
|
x: [9, 9, 9.1, 9.1]
|
|
|
|
- note: abs-extra-args
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = abs(-9, 10)
|
|
query: data.test.x
|
|
error: "`abs` expects 1 argument"
|
|
|
|
- note: abs-invalid-type
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = abs("-9")
|
|
query: data.test.x
|
|
error: "`abs` expects numeric argument"
|
|
|
|
- note: ceil
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = [ceil(9.1), ceil(-9.1), ceil(9), ceil(-9)]
|
|
# Undefined
|
|
y { false }
|
|
z = ceil(y)
|
|
query: data.test
|
|
want_result:
|
|
x: [10, -9, 9, -9]
|
|
|
|
- note: ceil-extra-args
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = ceil(-9, 10)
|
|
query: data.test.x
|
|
error: "`ceil` expects 1 argument"
|
|
|
|
- note: ceil-invalid-type
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = ceil("-9")
|
|
query: data.test.x
|
|
error: "`ceil` expects numeric argument"
|
|
|
|
- note: floor
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = [floor(9.1), floor(-9.1), floor(9), floor(-9)]
|
|
# Undefined
|
|
y { false }
|
|
z = floor(y)
|
|
query: data.test
|
|
want_result:
|
|
x: [9, -10, 9, -9]
|
|
|
|
- note: floor-extra-args
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = floor(-9, 10)
|
|
query: data.test.x
|
|
error: "`floor` expects 1 argument"
|
|
|
|
- note: floor-invalid-type
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = floor("-9")
|
|
query: data.test.x
|
|
error: "`floor` expects numeric argument"
|
|
|
|
- note: numbers.range
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
r1 = numbers.range(1, 5)
|
|
r2 = numbers.range(5, 1)
|
|
r3 = numbers.range(-1, -5)
|
|
r4 = numbers.range(-5, -1)
|
|
|
|
# Single item range
|
|
r5 = numbers.range(8, 8)
|
|
|
|
# Non-integer start and end result in Undefined.
|
|
r6 = numbers.range(1.01, 5)
|
|
r7 = numbers.range(1, 5.01)
|
|
|
|
y { false }
|
|
r8 = numbers.range(y, 10)
|
|
r9 = numbers.range(10, y)
|
|
|
|
query: data.test
|
|
want_result:
|
|
r1: [1, 2, 3, 4, 5]
|
|
r2: [5, 4, 3, 2, 1]
|
|
r3: [-1, -2, -3, -4, -5]
|
|
r4: [-5, -4, -3, -2, -1]
|
|
r5: [8]
|
|
|
|
- note: numbers.range-less-args
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = numbers.range(1)
|
|
query: data.test.x
|
|
error: "`numbers.range` expects 2 arguments"
|
|
|
|
- note: numbers.range-more-args
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = numbers.range(1, 2, 3)
|
|
query: data.test.x
|
|
error: "`numbers.range` expects 2 arguments"
|
|
|
|
- note: numbers.range-invalid-start
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = numbers.range("1", 2)
|
|
query: data.test.x
|
|
error: "`numbers.range` expects numeric argument"
|
|
|
|
- note: numbers.range-invalid-end
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = numbers.range(1, "2")
|
|
query: data.test.x
|
|
error: "`numbers.range` expects numeric argument"
|
|
|
|
- note: round
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = [round(-9.4), round(-9.5), round(-9.6),
|
|
round(9.4), round(9.5), round(9.6),
|
|
round(8), round(-8)]
|
|
|
|
# Undefined
|
|
y { false }
|
|
z = round(y)
|
|
query: data.test.x
|
|
want_result: [-9, -10, -10, 9, 10, 10, 8, -8]
|
|
|
|
- note: round-extra-args
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = round(-9, 10)
|
|
query: data.test.x
|
|
error: "`round` expects 1 argument"
|
|
|
|
- note: round-invalid-type
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = round("-9")
|
|
query: data.test.x
|
|
error: "`round` expects numeric argument"
|
|
|
|
- note: rand.intn
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = rand.intn("x", 50000)
|
|
y = rand.intn("y", 50000)
|
|
z = [p |
|
|
p := rand.intn("x", 50000)
|
|
]
|
|
a = rand.intn("x", 25000)
|
|
|
|
results = [
|
|
x == z[0],
|
|
x != y,
|
|
x != a,
|
|
rand.intn("b", 0)
|
|
]
|
|
query: data.test.results
|
|
want_result: [true, true, true, 0]
|
|
|
|
- note: rand.intn-undefined
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
y { false }
|
|
r1 = rand.intn(y, 10)
|
|
r2 = rand.intn(10, y)
|
|
r3 = rand.intn("a", 10.3)
|
|
query: data.test
|
|
want_result: {}
|
|
|
|
- note: rand.intn-extra-args
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = rand.intn("abc", 10, 11)
|
|
query: data.test.x
|
|
error: "`rand.intn` expects 2 arguments"
|
|
|
|
- note: rand.intn-less-args
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = rand.intn("abc")
|
|
query: data.test.x
|
|
error: "`rand.intn` expects 2 arguments"
|
|
|
|
- note: rand.intn-invalid-type-1
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = rand.intn(1, 2)
|
|
query: data.test.x
|
|
error: "`rand.intn` expects string argument"
|
|
|
|
- note: rand.intn-invalid-type-2
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = rand.intn("a", "b")
|
|
query: data.test.x
|
|
error: "`rand.intn` expects numeric argument"
|
|
|
|
|
|
- note: div
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
import future.keywords.if
|
|
|
|
x = 1/3
|
|
|
|
# Undefined
|
|
y if false
|
|
a = 1 / 0
|
|
b = y / 1
|
|
c = 1 / y
|
|
d = 13.3 % 3
|
|
e = 13 % 3.1
|
|
query: data.test
|
|
want_result:
|
|
x: 0.3333333333333333
|
|
|
|
- note: div-non-numeric
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = "1" / 9
|
|
query: data.test.x
|
|
error: "`div` expects numeric argument."
|
|
|
|
- note: mod
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = 10%3
|
|
|
|
# Undefined
|
|
y { false }
|
|
a = 1 % 0
|
|
b = y % 1
|
|
c = 1 % y
|
|
query: data.test
|
|
want_result:
|
|
x : 1
|
|
|
|
- note: mod-non-numeric
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = "1" % 9
|
|
query: data.test.x
|
|
error: "`mod` expects numeric argument."
|
|
|
|
- note: mod-undefined
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
a { false }
|
|
x = a % 10
|
|
query: data.test
|
|
want_result: {}
|
|
|
|
- note: mod-by-zero
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = 1%0
|
|
query: data.test
|
|
want_result: {}
|
|
|
|
- note: mul
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = 3 * -1 * 4.5
|
|
# Undefined
|
|
y { false }
|
|
a = 1 * y
|
|
b = y * 1
|
|
query: data.test
|
|
want_result:
|
|
x: -13.5
|
|
|
|
- note: mul-non-numeric
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = "1" * 9
|
|
query: data.test.x
|
|
error: "`mul` expects numeric argument."
|
|
|
|
- note: add
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = 3 + -1 + 4.5
|
|
# Undefined
|
|
y { false }
|
|
a = 1 + y
|
|
b = y + 1
|
|
query: data.test
|
|
want_result:
|
|
x: 6.5
|
|
|
|
- note: add-non-numeric
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = "1" + 9
|
|
query: data.test.x
|
|
error: "`add` expects numeric argument."
|
|
|
|
- note: sub
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = 3 - -1 - 4.5
|
|
# Undefined
|
|
y { false }
|
|
a = 1 - y
|
|
b = y - 1
|
|
query: data.test
|
|
want_result:
|
|
x: -0.5
|
|
|
|
- note: sub-non-numeric
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = "1" - 9
|
|
query: data.test.x
|
|
error: "`sub` expects numeric argument."
|
|
|
|
- note: all
|
|
data: {}
|
|
modules:
|
|
- |
|
|
package test
|
|
x = 16 / 2 % 5 / 2
|
|
query: data.test
|
|
want_result:
|
|
x: 1.5
|
|
|
|
# TODO: Lockdown associativity and precedence of operators.
|