github.com/llir/llvm@v0.3.6/ir/global_test.go (about) 1 package ir_test 2 3 import ( 4 "testing" 5 6 "github.com/google/go-cmp/cmp" 7 "github.com/llir/llvm/ir" 8 "github.com/llir/llvm/ir/constant" 9 "github.com/llir/llvm/ir/types" 10 ) 11 12 func TestAssignGlobalIDs(t *testing.T) { 13 // ref: https://github.com/llir/llvm/issues/148 14 const want = `@0 = global [15 x i8] c"Hello, world!\0A\00" 15 @1 = global i32 0 16 17 define i32 @2() { 18 0: 19 ret i32 1 20 } 21 ` 22 23 m := ir.NewModule() 24 25 // should be @0 26 s := "Hello, world!\n\x00" 27 i := constant.NewCharArrayFromString(s) 28 m.NewGlobalDef("", i) 29 30 // should be @1 31 i32 := types.I32 32 zero := constant.NewInt(i32, 0) 33 m.NewGlobalDef("", zero) 34 35 // should be @2 36 one := constant.NewInt(i32, 1) 37 m.NewFunc("", i32).NewBlock("").NewRet(one) 38 39 // Compare module output. 40 got := m.String() 41 if diff := cmp.Diff(want, got); diff != "" { 42 t.Errorf("module mismatch (-want +got):\n%s", diff) 43 } 44 }