func TestOperandListNumberParse(t *testing.T) { testCaseList := []testCaseForTestOperandListNumberParse{ { data: "DATA1", expectedRemains: "DATA1", expectedOK: false, }, { data: "1234 ; this is comment", expectedRemains: "; this is comment", expectedOK: true, }, { data: " #ABCD", expectedRemains: "", expectedOK: true, }, } for testIndex, testCase := range testCaseList { target := operandlist.NewNumber() testData := testCase.data expectedRemains := testCase.expectedRemains expectedOK := testCase.expectedOK // expectedOperandSingleValue := testCase.expectedOperandSingleValue // expectedHasValue := testCase.expectedHasValue actualRemains, actualOK := target.Parse(testData) if actualRemains != expectedRemains { t.Errorf("testCase[%d]=%#v, expected=%#v, actual=%#v\n", testIndex, testData, expectedRemains, actualRemains) } if actualOK != expectedOK { t.Errorf("testCase[%d]=%#v, expected=%#v, actual=%#v\n", testIndex, testData, expectedOK, actualOK) } } }
// AcceptableOprandLists returns a list of OperandList. func (opcode *Opcode) AcceptableOprandLists() *operandlist.ListOfList { switch opcode.OpcodeValue { case OpcodeValueSTART: return operandlist.NewListOfList(operandlist.NewNone(), operandlist.NewLabel()) case OpcodeValueEND: return operandlist.NewListOfList(operandlist.NewNone()) case OpcodeValueDS: return operandlist.NewListOfList(operandlist.NewNumber()) case OpcodeValueDC: return operandlist.NewListOfList(operandlist.NewConstants()) case OpcodeValueIN: return operandlist.NewListOfList(operandlist.NewLabelLabel()) case OpcodeValueOUT: return operandlist.NewListOfList(operandlist.NewLabelLabel()) case OpcodeValueRPUSH: return operandlist.NewListOfList(operandlist.NewNone()) case OpcodeValueRPOP: return operandlist.NewListOfList(operandlist.NewNone()) case OpcodeValueNOP: return operandlist.NewListOfList(operandlist.NewNone()) case OpcodeValueLD: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueST: return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueLAD: return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueADDA: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueSUBA: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueADDL: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueSUBL: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueAND: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueOR: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueXOR: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueCPA: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueCPL: return operandlist.NewListOfList(operandlist.NewR1R2(), operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueSLA: return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueSRA: return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueSLL: return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueSRL: return operandlist.NewListOfList(operandlist.NewRegisterAddressX(), operandlist.NewRegisterAddress()) case OpcodeValueJMI: return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress()) case OpcodeValueJNZ: return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress()) case OpcodeValueJZE: return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress()) case OpcodeValueJUMP: return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress()) case OpcodeValueJPL: return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress()) case OpcodeValueJOV: return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress()) case OpcodeValuePUSH: return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress()) case OpcodeValuePOP: return operandlist.NewListOfList(operandlist.NewRegister()) case OpcodeValueCALL: return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress()) case OpcodeValueRET: return operandlist.NewListOfList(operandlist.NewNone()) case OpcodeValueSVC: return operandlist.NewListOfList(operandlist.NewAddressX(), operandlist.NewAddress()) } return operandlist.NewListOfList() }