summaryrefslogtreecommitdiff
path: root/Examples/test-suite/go/go_inout_runme.go
blob: 13c429b87ec7a5781cf7a526785ab0d621877ed0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main

import (
	"encoding/json"
	"fmt"
	"reflect"

	"./go_inout"
)

type S struct {
	A int
	B string
	C float64
}

func (p *S) MarshalJSON() ([]byte, error) {
	return json.Marshal(*p)
}

func main() {
	v := &S{12, "hi", 34.5}
	m := go_inout.Same(v)
	want := map[string]interface{}{
		// The type of A changes from int to float64 because
		// JSON has no ints.
		"A": float64(12),
		"B": "hi",
		"C": 34.5,
	}
	if !reflect.DeepEqual(m, want) {
		fmt.Println("got", m, "want", want)
		panic(m)
	}

	a := []string{"a", "bc", "def"}
	go_inout.DoubleArray(&a)
	dwant := []string{"a", "bc", "def", "aa", "bcbc", "defdef"}
	if !reflect.DeepEqual(a, dwant) {
		fmt.Println("got", a, "want", dwant)
		panic(a)
	}
}