| 1 | package operand |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestConstants(t *testing.T) { |
| 6 | cases := []struct { |
| 7 | Const Constant |
| 8 | Asm string |
| 9 | Bytes int |
| 10 | }{ |
| 11 | {F32(3.1415), "$(3.1415)", 4}, |
| 12 | {F32(42), "$(42.0)", 4}, |
| 13 | {F64(3.1415), "$(3.1415)", 8}, |
| 14 | {F64(42), "$(42.0)", 8}, |
| 15 | {U8(42), "$0x2a", 1}, |
| 16 | {U16(42), "$0x002a", 2}, |
| 17 | {U32(42), "$0x0000002a", 4}, |
| 18 | {U64(42), "$0x000000000000002a", 8}, |
| 19 | {I8(-42), "$-42", 1}, |
| 20 | {I16(-42), "$-42", 2}, |
| 21 | {I32(-42), "$-42", 4}, |
| 22 | {I64(-42), "$-42", 8}, |
| 23 | {String("hello"), "$\"hello\"", 5}, |
| 24 | {String("quot:\"q\""), "$\"quot:\\\"q\\\"\"", 8}, |
| 25 | } |
| 26 | for _, c := range cases { |
| 27 | if c.Const.Asm() != c.Asm { |
| 28 | t.Errorf("%v.Asm() = %v; expect %v", c.Const, c.Const.Asm(), c.Asm) |
| 29 | } |
| 30 | if c.Const.Bytes() != c.Bytes { |
| 31 | t.Errorf("%v.Bytes() = %v; expect %v", c.Const, c.Const.Bytes(), c.Bytes) |
| 32 | } |
| 33 | } |
| 34 | } |