specsuite: Tests for the expression language operators

This commit is contained in:
Martin Atkins 2019-09-11 15:03:26 -07:00
parent 48fbad7bf4
commit ee38c67330
3 changed files with 234 additions and 0 deletions

View File

@ -0,0 +1,68 @@
equality "==" {
exactly = "a" == "a"
not = "a" == "b"
type_mismatch_number = "1" == 1
type_mismatch_bool = "true" == true
}
equality "!=" {
exactly = "a" != "a"
not = "a" != "b"
type_mismatch_number = "1" != 1
type_mismatch_bool = "true" != true
}
inequality "<" {
lt = 1 < 2
gt = 2 < 1
eq = 1 < 1
}
inequality "<=" {
lt = 1 <= 2
gt = 2 <= 1
eq = 1 <= 1
}
inequality ">" {
lt = 1 > 2
gt = 2 > 1
eq = 1 > 1
}
inequality ">=" {
lt = 1 >= 2
gt = 2 >= 1
eq = 1 >= 1
}
arithmetic {
add = 2 + 3.5
add_big = 3.14159265358979323846264338327950288419716939937510582097494459 + 1
sub = 3.5 - 2
sub_neg = 2 - 3.5
mul = 2 * 4.5
div = 1 / 10
mod = 11 % 5
mod_frac = 11 % 5.1
}
logical_binary "&&" {
tt = true && true
ft = false && true
tf = true && false
ff = false && false
}
logical_binary "||" {
tt = true || true
ft = false || true
tf = true || false
ff = false || false
}
logical_unary "!" {
t = !true
f = !false
}
conditional {
t = true ? "a" : "b"
f = false ? "a" : "b"
}

View File

@ -0,0 +1,57 @@
object {
block_map "equality" {
labels = ["operator"]
object {
attr "exactly" { type = any }
attr "not" { type = any }
attr "type_mismatch_number" { type = any }
attr "type_mismatch_bool" { type = any }
}
}
block_map "inequality" {
labels = ["operator"]
object {
attr "lt" { type = any }
attr "gt" { type = any }
attr "eq" { type = any }
}
}
block "arithmetic" {
object {
attr "add" { type = any }
attr "add_big" { type = any }
attr "sub" { type = any }
attr "sub_neg" { type = any }
attr "mul" { type = any }
attr "div" { type = any }
attr "mod" { type = any }
attr "mod_frac" { type = any }
}
}
block_map "logical_binary" {
labels = ["operator"]
object {
attr "tt" { type = any }
attr "ft" { type = any }
attr "tf" { type = any }
attr "ff" { type = any }
}
}
block_map "logical_unary" {
labels = ["operator"]
object {
attr "t" { type = any }
attr "f" { type = any }
}
}
block "conditional" {
object {
attr "t" { type = any }
attr "f" { type = any }
}
}
}

View File

@ -0,0 +1,109 @@
result = {
equality = {
"==" = {
exactly = true
not = false
type_mismatch_number = false
type_mismatch_bool = false
}
"!=" = {
exactly = false
not = true
type_mismatch_number = true
type_mismatch_bool = true
}
}
inequality = {
"<" = {
lt = true
gt = false
eq = false
}
"<=" = {
lt = true
gt = false
eq = true
}
">" = {
lt = false
gt = true
eq = false
}
">=" = {
lt = false
gt = true
eq = true
}
}
arithmetic = {
add = 5.5
add_big = 4.14159265358979323846264338327950288419716939937510582097494459
sub = 1.5
sub_neg = -1.5
mul = 9
div = 0.1
mod = 1
mod_frac = 0.8000000000000000002
}
logical_binary = {
"&&" = {
tt = true
tf = false
ft = false
ff = false
}
"||" = {
tt = true
tf = true
ft = true
ff = false
}
}
logical_unary = {
"!" = {
t = false
f = true
}
}
conditional = {
t = "a"
f = "b"
}
}
result_type = object({
equality = map(object({
exactly = bool
not = bool
type_mismatch_number = bool
type_mismatch_bool = bool
}))
inequality = map(object({
lt = bool
gt = bool
eq = bool
}))
arithmetic = object({
add = number
add_big = number
sub = number
sub_neg = number
mul = number
div = number
mod = number
mod_frac = number
})
logical_binary = map(object({
tt = bool
tf = bool
ft = bool
ff = bool
}))
logical_unary = map(object({
t = bool
f = bool
}))
conditional = object({
t = string
f = string
})
})