slovo/tests/primitive-struct-fields.slo
2026-05-22 08:38:43 +02:00

67 lines
1.7 KiB
Plaintext

(module main)
(struct PrimitiveRecord
(id i32)
(active bool)
(label string))
(fn make_record ((id i32) (label string)) -> PrimitiveRecord
(PrimitiveRecord (id id) (active (= id 7)) (label label)))
(fn expected_record () -> PrimitiveRecord
(make_record 7 "alpha"))
(fn inactive_record () -> PrimitiveRecord
(PrimitiveRecord (id 3) (active false) (label "beta")))
(fn echo_record ((record PrimitiveRecord)) -> PrimitiveRecord
record)
(fn local_record ((label string)) -> PrimitiveRecord
(let record PrimitiveRecord (make_record 7 label))
(echo_record record))
(fn record_id ((record PrimitiveRecord)) -> i32
(. record id))
(fn record_active ((record PrimitiveRecord)) -> bool
(. record active))
(fn record_label ((record PrimitiveRecord)) -> string
(. record label))
(fn label_matches ((record PrimitiveRecord) (label string)) -> bool
(= (. record label) label))
(fn active_score ((record PrimitiveRecord)) -> i32
(if (. record active)
(. record id)
0))
(fn label_len ((record PrimitiveRecord)) -> i32
(std.string.len (. record label)))
(test "primitive struct i32 field access"
(= (record_id (expected_record)) 7))
(test "primitive struct bool field predicate"
(record_active (expected_record)))
(test "primitive struct bool field false branch"
(= (active_score (inactive_record)) 0))
(test "primitive struct string field equality"
(label_matches (expected_record) "alpha"))
(test "primitive struct string field length"
(= (label_len (expected_record)) 5))
(test "primitive struct local param return call flow"
(= (active_score (local_record "alpha")) 7))
(test "primitive struct string field access return"
(= (record_label (local_record "alpha")) "alpha"))
(fn main () -> i32
(active_score (local_record "alpha")))