program main
  enum Reading
    variant Missing
    variant Value i32
    variant Offset i32
  fn missing() -> Reading
    enum-variant Reading.Missing
  fn value(payload: i32) -> Reading
    enum-variant Reading.Value
      var payload
  fn echo(reading: Reading) -> Reading
    var reading
  fn local_reading(payload: i32) -> Reading
    local let reading: Reading
      enum-variant Reading.Value
        var payload
    var reading
  fn same_reading(left: Reading, right: Reading) -> bool
    binary =
      var left
      var right
  fn reading_code(reading: Reading) -> i32
    match
      subject
        var reading
      arm Reading.Missing
        int 0
      arm Reading.Value payload
        var payload
      arm Reading.Offset payload
        binary +
          var payload
          int 100
  fn call_flow(payload: i32) -> Reading
    call echo
      call local_reading
        var payload
  fn main() -> i32
    call reading_code
      call call_flow
        int 42
  test "enum payload constructor equality"
    binary =
      enum-variant Reading.Value
        int 7
      call value
        int 7
  test "enum payload equality compares payload"
    if
      binary =
        enum-variant Reading.Value
          int 7
        enum-variant Reading.Value
          int 8
      bool false
      bool true
  test "enum payloadless equality"
    binary =
      enum-variant Reading.Missing
      call missing
  test "enum payload local return call flow"
    binary =
      call call_flow
        int 9
      enum-variant Reading.Value
        int 9
  test "enum payload parameter equality"
    call same_reading
      call value
        int 11
      enum-variant Reading.Value
        int 11
  test "enum payload match missing"
    binary =
      call reading_code
        enum-variant Reading.Missing
      int 0
  test "enum payload match value"
    binary =
      call reading_code
        enum-variant Reading.Value
          int 12
      int 12
  test "enum payload match offset"
    binary =
      call reading_code
        enum-variant Reading.Offset
          int 5
      int 105
