(module main)

(enum Signal Red Yellow Green)

(fn red () -> Signal
  (Signal.Red))

(fn yellow () -> Signal
  (Signal.Yellow))

(fn echo ((signal Signal)) -> Signal
  signal)

(fn local_signal () -> Signal
  (let signal Signal (Signal.Green))
  signal)

(fn same_signal ((left Signal) (right Signal)) -> bool
  (= left right))

(fn signal_code ((signal Signal)) -> i32
  (match signal
    ((Signal.Red)
      1)
    ((Signal.Yellow)
      (let code i32 2)
      code)
    ((Signal.Green)
      3)))

(fn call_flow () -> Signal
  (echo (local_signal)))

(test "enum constructor equality"
  (= (Signal.Red) (red)))

(test "enum local return call flow"
  (= (call_flow) (Signal.Green)))

(test "enum parameter equality"
  (same_signal (yellow) (Signal.Yellow)))

(test "enum match red"
  (= (signal_code (Signal.Red)) 1))

(test "enum match multi expression arm"
  (= (signal_code (Signal.Yellow)) 2))

(test "enum match green"
  (= (signal_code (call_flow)) 3))

(fn main () -> i32
  (signal_code (call_flow)))
