main.mx raw

   1  package main
   2  
   3  import (
   4  	"tests/regressions/should_compile/iter_apis/lib"
   5  )
   6  
   7  func main() {
   8  	// Termination: a batch program must still be stoppable, so the entry
   9  	// handles the channel the runtime closes on SIGINT/SIGTERM.
  10  	select {
  11  	case <-shutdown:
  12  		return
  13  	default:
  14  	}
  15  
  16  	if got := lib.SumSeq(7); got != 7 {
  17  		panic("generic Seq[V] round trip = " | got.String() | ", want 7")
  18  	}
  19  	m := map[string]int32{"a": 1, "b": 2, "c": 3}
  20  	if got := lib.SumValues(m); got != 6 {
  21  		panic("maps.Values sum = " | got.String() | ", want 6")
  22  	}
  23  	if got := lib.CountPairs(m); got != 3 {
  24  		panic("maps.All pairs = " | got.String() | ", want 3")
  25  	}
  26  	if got := lib.Keys(m); len(got) != 3 {
  27  		panic("maps.Keys yielded " | int32(len(got)).String() | " keys, want 3")
  28  	}
  29  	seq := lib.Collect(lib.CounterSeq())
  30  	if len(seq) != 3 || seq[0] != 0 || seq[1] != 1 || seq[2] != 2 {
  31  		panic("a hand-written iter.Seq did not collect to 0,1,2")
  32  	}
  33  	println("iterators ok")
  34  }
  35