-
Notifications
You must be signed in to change notification settings - Fork 0
/
typemap_test.go
55 lines (44 loc) · 1015 Bytes
/
typemap_test.go
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
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"encoding/json"
"os"
"testing"
)
func TestTypeMap1(t *testing.T) {
const filename = "test-map.json"
defer os.Remove(filename)
f, err := os.Create(filename)
if err != nil {
t.Fatal(err)
}
var mapping []TypeMap
mapping = append(mapping, TypeMap{"Timepoint", "std::chrono::steady_clock::timepoint", false})
mapping = append(mapping, TypeMap{"StringMap", "std::map<std::string, std::string>", true})
e := json.NewEncoder(f)
err = e.Encode(mapping)
if err != nil {
f.Close()
os.Remove(f.Name())
t.Fatal(err)
}
err = f.Close()
if err != nil {
t.Fatal(err)
}
initTypeMap()
cpp, ref := mapGoToCpp("int")
if cpp != "int" {
t.Fatalf("Go %q mapped to C++ %q", "int", cpp)
}
if ref {
t.Fatalf("Go \"int\" mapped to pass-by-ref type %q", cpp)
}
err = readTypeMap(filename)
if err != nil {
t.Fatal(err)
}
cpp, ref = mapGoToCpp("Timepoint")
if cpp != "std::chrono::steady_clock::timepoint" {
t.Fatalf("Go %q mapped to C++ %q", "Timepoint", cpp)
}
}