| 1 |
package compile_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"strings" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"go.starlark.net/internal/compile" |
| 8 |
) |
| 9 |
|
| 10 |
// TestOpcodeNames checks that every opcode has a name, including the |
| 11 |
// highest-numbered one (a regression test for an off-by-one in |
| 12 |
// Opcode.String), and that out-of-range opcodes are reported as |
| 13 |
// illegal rather than out of bounds. |
| 14 |
func TestOpcodeNames(t *testing.T) { |
| 15 |
for op := compile.Opcode(0); op <= compile.OpcodeMax; op++ { |
| 16 |
if name := op.String(); strings.HasPrefix(name, "illegal op") { |
| 17 |
t.Errorf("opcode %d has no name", op) |
| 18 |
} |
| 19 |
} |
| 20 |
if name := (compile.OpcodeMax + 1).String(); !strings.HasPrefix(name, "illegal op") { |
| 21 |
t.Errorf("Opcode(OpcodeMax+1).String() = %q, want illegal op", name) |
| 22 |
} |
| 23 |
} |