(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func TestCommitCommand(t *testing.T) { |
| 32 | ctx := log.Testing(t) |
| 33 | for _, test := range []struct { |
| 34 | name string |
| 35 | f func(*Builder) |
| 36 | expected []asm.Instruction |
| 37 | }{ |
| 38 | { |
| 39 | "Call with used return value", |
| 40 | func(b *Builder) { |
| 41 | b.BeginCommand(10, 0) |
| 42 | b.Push(value.U8(1)) |
| 43 | b.Call(FunctionInfo{0, 123, protocol.Type_Uint8, 1}) |
| 44 | b.Store(value.AbsolutePointer(0x10000)) |
| 45 | b.CommitCommand() |
| 46 | }, |
| 47 | []asm.Instruction{ |
| 48 | asm.Label{Value: 10}, |
| 49 | asm.Push{Value: value.U8(1)}, |
| 50 | asm.Call{PushReturn: true, ApiIndex: 0, FunctionID: 123}, |
| 51 | asm.Store{Destination: value.AbsolutePointer(0x10000)}, |
| 52 | }, |
| 53 | }, |
| 54 | { |
| 55 | "Call with unused return value", |
| 56 | func(b *Builder) { |
| 57 | b.BeginCommand(10, 0) |
| 58 | b.Push(value.U8(1)) |
| 59 | b.Call(FunctionInfo{1, 123, protocol.Type_Uint8, 1}) |
| 60 | b.CommitCommand() |
| 61 | }, |
| 62 | []asm.Instruction{ |
| 63 | asm.Label{Value: 10}, |
| 64 | asm.Push{Value: value.U8(1)}, |
| 65 | asm.Call{PushReturn: false, ApiIndex: 1, FunctionID: 123}, |
| 66 | }, |
| 67 | }, |
| 68 | { |
| 69 | "Remove unused push", |
| 70 | func(b *Builder) { |
| 71 | b.BeginCommand(10, 0) |
| 72 | b.Push(value.U32(12)) |
| 73 | b.CommitCommand() |
| 74 | }, |
| 75 | []asm.Instruction{ |
| 76 | asm.Label{Value: 10}, |
| 77 | }, |
| 78 | }, |
| 79 | { |
| 80 | "Unused pushes", |
| 81 | func(b *Builder) { |
| 82 | b.BeginCommand(10, 0) |
| 83 | b.Push(value.U32(12)) |
| 84 | b.Push(value.U32(34)) |
| 85 | b.Push(value.U32(56)) |
| 86 | b.CommitCommand() |
| 87 | }, |
| 88 | []asm.Instruction{ |
nothing calls this directly
no test coverage detected