main.mx raw
1 package main
2
3 import (
4 "os"
5 "tests/regressions/should_compile/sovereign_map_store/lib"
6 )
7
8 func chk(name, got, want string) {
9 if got != want {
10 println("FAIL: " | name | " got [" | got | "] want [" | want | "]")
11 os.Exit(1)
12 }
13 }
14
15 func main() {
16 // Termination: a batch program must still be stoppable, so the entry
17 // handles the channel the runtime closes on SIGINT/SIGTERM.
18 select {
19 case <-shutdown:
20 return
21 default:
22 }
23
24 rounds := int32(500)
25 err := lib.Load(rounds)
26 if err != nil {
27 println("FAIL: load: " | err.Error())
28 os.Exit(1)
29 }
30 if lib.Marks() != rounds {
31 println("FAIL: marks ", lib.Marks(), " want ", rounds)
32 os.Exit(1)
33 }
34
35 // Every one of these values was produced by an allocation inside a
36 // map-only method. The loader that called it has returned, so a frame
37 // arena there means these now read recycled memory.
38 want := ""
39 for i := int32(0); i < rounds; i++ {
40 want = want | "ab"
41 }
42 chk("grown value", string(lib.Value([]byte("acc"))), want)
43
44 exts := lib.Exts([]byte("image/jpeg"))
45 if int32(len(exts)) != rounds {
46 println("FAIL: jpeg extension count ", len(exts), " want ", rounds)
47 os.Exit(1)
48 }
49 for i := int32(0); i < rounds; i++ {
50 if string(exts[i]) != ".jpg" {
51 println("FAIL: jpeg extension ", i, " = [" | string(exts[i]) | "]")
52 os.Exit(1)
53 }
54 }
55 exts = lib.Exts([]byte("text/html"))
56 if int32(len(exts)) != rounds || string(exts[rounds-1]) != ".html" {
57 println("FAIL: html extensions wrong")
58 os.Exit(1)
59 }
60 println("ok")
61 }
62