forked from llir/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinst_aggregate_test.go
46 lines (40 loc) · 1.2 KB
/
inst_aggregate_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
package ir
import (
"testing"
"github.com/llir/llvm/ir/constant"
"github.com/llir/llvm/ir/types"
"github.com/llir/llvm/ir/value"
)
func TestTypeCheckInstExtractValue(t *testing.T) {
structType := types.NewStruct(types.I32, types.I64)
// Should succeed.
var v value.Value = constant.NewUndef(structType)
_ = v.String()
v = NewInsertValue(v, constant.NewInt(types.I32, 1), 0)
_ = v.String()
v = NewInsertValue(v, constant.NewInt(types.I64, 1), 1)
_ = v.String()
var panicErr error
func() {
defer func() { panicErr = recover().(error) }()
// Should panic because index 1 is I64, not I32.
v = NewInsertValue(v, constant.NewInt(types.I32, 1), 1)
t.Fatal("unreachable")
}()
expected := "insertvalue elem type mismatch, expected i64, got i32"
got := panicErr.Error()
if got != expected {
t.Errorf("expected %q, got %q", expected, got)
}
func() {
defer func() { panicErr = recover().(error) }()
// Should panic because index 0 is I32, not I64.
v = NewInsertValue(v, constant.NewInt(types.I64, 1), 0)
t.Fatal("unreachable")
}()
expected = "insertvalue elem type mismatch, expected i32, got i64"
got = panicErr.Error()
if got != expected {
t.Errorf("expected %q, got %q", expected, got)
}
}