blob: c9088928dc31c629063b83e75485733a83feda8e [file] [log] [blame]
cue eval -i bounds.cue
cmp stdout expect-stdout-cue
-- frontmatter.toml --
title = "Bounds"
description = ""
-- text.md --
Bounds define a lower bound, upper bound, or inequality for a certain value.
They work on numbers, strings, bytes, and and null.
The bound is defined for all values for which the corresponding comparison
operation is define.
For instance `>5.0` allows all floating point values greater than `5.0`,
whereas `<0` allows all negative numbers (int or float).
-- bounds.cue --
rn: >=3 & <8 // type int | float
ri: >=3 & <8 & int // type int
rf: >=3 & <=8.0 // type float
rs: >="a" & <"mo"
{
a: rn & 3.5
b: ri & 3.5
c: rf & 3
d: rs & "ma"
e: rs & "mu"
r1: rn & >=5 & <10
}
-- expect-stdout-cue --
a: 3.5
b: _|_ // conflicting values ri and 3.5 (mismatched types int and float)
c: 3
d: "ma"
e: _|_ // invalid value "mu" (out of bound <"mo")
r1: >=5 & <8