slovo/tests/type-aliases.surface.lower

107 lines
2.4 KiB
Plaintext

program main
type Count = i32
type Score = Count
type Text = string
type Counts = (array Count 3)
type CountVec = (vec Count)
type MaybeCount = (option Count)
type CountResult = (result Count Count)
type Measure = Measurement
type ReadingAlias = Reading
enum Reading
variant Empty
variant Value Count
struct Measurement
field amount: Count
field label: Text
fn bump(value: Count) -> Score
binary +
var value
int 1
fn make_counts(base: Count) -> Counts
array Count
var base
binary +
var base
int 1
binary +
var base
int 2
fn pick_count(values: Counts) -> Count
index
var values
int 1
fn make_measure(amount: Count) -> Measure
construct Measurement
field amount
var amount
field label
string "ok"
fn measure_amount(measure: Measure) -> Count
field-access amount
var measure
fn maybe_amount(amount: Count) -> MaybeCount
some Count
var amount
fn maybe_empty() -> MaybeCount
none Count
fn ok_amount(amount: Count) -> CountResult
ok Count Count
var amount
fn err_amount(code: Count) -> CountResult
err Count Count
var code
fn empty_counts() -> CountVec
call std.vec.i32.empty
fn reading_value(amount: Count) -> ReadingAlias
enum-variant Reading.Value
var amount
fn reading_score(reading: ReadingAlias) -> Count
match
subject
var reading
arm Reading.Empty
int 0
arm Reading.Value amount
var amount
fn main() -> i32
local let values: Counts
call make_counts
int 40
binary +
call pick_count
var values
call measure_amount
call make_measure
int 1
test "aliases erase through arrays and structs"
binary =
call main
int 42
test "aliases erase through option result vec and enum"
local let maybe: MaybeCount
call maybe_amount
int 7
local let result: CountResult
call ok_amount
int 8
if
is_some
var maybe
if
is_ok
var result
if
binary =
call std.vec.i32.len
call empty_counts
int 0
binary =
call reading_score
call reading_value
int 9
int 9
bool false
bool false
bool false