Exemplo n.º 1
0
// Parse parser operands.
func (operands *RegisterAddressX) Parse(source string) (string, bool) {
	// R
	r := operand.NewRegister()
	remains, ok := r.Parse(source)
	if !ok {
		return source, false
	}

	// ,(Comma)
	remains, ok = share.NewComma().Parse(remains)
	if !ok {
		return source, false
	}

	// ADR
	adr := operand.NewAddress()
	remains, ok = adr.Parse(remains)
	if !ok {
		return source, false
	}
	// ,(Comma)
	remains, ok = share.NewComma().Parse(remains)
	if !ok {
		return source, false
	}
	// X
	x := operand.NewRegister()
	remains, ok = x.Parse(remains)
	if !ok {
		return source, false
	}
	operands.Operands = []operand.Operand{r, adr, x}
	return remains, true
}
Exemplo n.º 2
0
// Parse parser operands.
func (operands *Address) Parse(source string) (string, bool) {
	// ADR
	adr := operand.NewAddress()
	remains, ok := adr.Parse(source)
	if !ok {
		return source, false
	}
	operands.Operands = []operand.Operand{adr}
	return remains, true
}
Exemplo n.º 3
0
func TestOperandAddressParse(t *testing.T) {
	testCaseList := []testCaseForTestOperandAddressParse{
		{
			data:                       "1000, DATA1",
			expectedRemains:            ", DATA1",
			expectedOK:                 true,
			expectedOperandSingleValue: "1000",
			expectedHasValue:           true,
		},
		{
			data:                       "#123 ; this is comment",
			expectedRemains:            "; this is comment",
			expectedOK:                 true,
			expectedOperandSingleValue: "#123",
			expectedHasValue:           true,
		},
		{
			data: "			DATAX ",
			expectedRemains:            "",
			expectedOK:                 true,
			expectedOperandSingleValue: "DATAX",
			expectedHasValue:           true,
		},
		{
			data:                       "=1000, DATA1",
			expectedRemains:            ", DATA1",
			expectedOK:                 true,
			expectedOperandSingleValue: "=1000",
			expectedHasValue:           true,
		},
		{
			data: "		=#ABCD",
			expectedRemains:            "",
			expectedOK:                 true,
			expectedOperandSingleValue: "=#ABCD",
			expectedHasValue:           true,
		},
		{
			data:                       "='STRING' ; this is comment",
			expectedRemains:            "; this is comment",
			expectedOK:                 true,
			expectedOperandSingleValue: "='STRING'",
			expectedHasValue:           true,
		},
	}
	for testIndex, testCase := range testCaseList {
		target := operand.NewAddress()
		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)
		}
		actualValue := target.Value()
		if actualValue != expectedOperandSingleValue {
			t.Errorf("testCase[%d]=%#v, expected=%#v, actual=%#v\n", testIndex, testData, expectedOperandSingleValue, actualValue)
		}
		actualHasValue := target.HasValue()
		if actualHasValue != expectedHasValue {
			t.Errorf("testCase[%d]=%#v, expected=%#v, actual=%#v\n", testIndex, testData, expectedHasValue, actualHasValue)
		}
	}

}