MCPcopy Create free account
hub / github.com/djhworld/simple-computer / TestDATAInstruction

Function TestDATAInstruction

asm/instructions_test.go:361–399  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

359}
360
361func TestDATAInstruction(t *testing.T) {
362 var TABLE map[Instruction][]uint16 = map[Instruction][]uint16{
363 DATA{REG0, NUMBER{0x0001}}: []uint16{0x20, 0x0001},
364 DATA{REG1, NUMBER{0x0002}}: []uint16{0x21, 0x0002},
365 DATA{REG2, NUMBER{0x0003}}: []uint16{0x22, 0x0003},
366 DATA{REG3, NUMBER{0x0004}}: []uint16{0x23, 0x0004},
367 DATA{REG0, SYMBOL{"foo"}}: []uint16{0x20, 0xA000},
368 DATA{REG1, SYMBOL{"bar"}}: []uint16{0x21, 0xB000},
369 DATA{REG2, SYMBOL{"baz"}}: []uint16{0x22, 0xC000},
370 DATA{REG3, SYMBOL{"bee"}}: []uint16{0x23, 0xD000},
371 }
372
373 dummySymbolResolver := func(s SYMBOL) (uint16, error) {
374 switch s.Name {
375 case "foo":
376 return 0xA000, nil
377 case "bar":
378 return 0xB000, nil
379 case "baz":
380 return 0xC000, nil
381 case "bee":
382 return 0xD000, nil
383 default:
384 return 0x0000, fmt.Errorf("received unknown symbol")
385 }
386 }
387
388 for ins, expected := range TABLE {
389 if emit, err := ins.Emit(nil, dummySymbolResolver); err == nil {
390 if reflect.DeepEqual(emit, expected) == false {
391 t.Logf("Expected %v got %v when testing %s", expected, emit, ins)
392 t.FailNow()
393 }
394 } else {
395 t.Logf("Got error %v when testing %s", err, ins)
396 t.FailNow()
397 }
398 }
399}
400
401func TestIOInstructionsString(t *testing.T) {
402 var TABLE map[Instruction]string = map[Instruction]string{

Callers

nothing calls this directly

Calls 1

EmitMethod · 0.65

Tested by

no test coverage detected