File: const_test.go

package info (click to toggle)
golang-github-mmcloughlin-avo 0.0~git20200523.4439b6b-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,304 kB
  • sloc: xml: 71,029; asm: 13,138; sh: 179; makefile: 35
file content (32 lines) | stat: -rw-r--r-- 770 bytes parent folder | download | duplicates (2)
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
package operand

import "testing"

func TestConstants(t *testing.T) {
	cases := []struct {
		Const Constant
		Asm   string
		Bytes int
	}{
		{F32(3.1415), "$(3.1415)", 4},
		{F64(3.1415), "$(3.1415)", 8},
		{U8(42), "$0x2a", 1},
		{U16(42), "$0x002a", 2},
		{U32(42), "$0x0000002a", 4},
		{U64(42), "$0x000000000000002a", 8},
		{I8(-42), "$-42", 1},
		{I16(-42), "$-42", 2},
		{I32(-42), "$-42", 4},
		{I64(-42), "$-42", 8},
		{String("hello"), "$\"hello\"", 5},
		{String("quot:\"q\""), "$\"quot:\\\"q\\\"\"", 8},
	}
	for _, c := range cases {
		if c.Const.Asm() != c.Asm {
			t.Errorf("%v.Asm() = %v; expect %v", c.Const, c.Const.Asm(), c.Asm)
		}
		if c.Const.Bytes() != c.Bytes {
			t.Errorf("%v.Bytes() = %v; expect %v", c.Const, c.Const.Bytes(), c.Bytes)
		}
	}
}