Esempio n. 1
0
// Parse parser operands.
func (operands *Label) Parse(source string) (string, bool) {
	label := operand.NewLabel()
	remains, ok := label.Parse(source)
	if !ok {
		return source, false
	}
	operands.Operands = []operand.Operand{label}
	return remains, true
}
Esempio n. 2
0
// Parse parser operands.
func (operands *LabelLabel) Parse(source string) (string, bool) {
	label1 := operand.NewLabel()
	remains, ok := label1.Parse(source)
	if !ok {
		return source, false
	}
	remains, ok = share.NewComma().Parse(remains)
	if !ok {
		return source, false
	}
	label2 := operand.NewLabel()
	remains, ok = label2.Parse(source)
	if !ok {
		return source, false
	}
	operands.Operands = []operand.Operand{label1, label2}
	return remains, true
}
Esempio n. 3
0
func TestOperandLabelParse(t *testing.T) {
	testCaseList := []testCaseForTestOperandLabelParse{
		// This is a comment line.
		{
			data:                       "; This is a comment",
			expectedRemains:            "; This is a comment",
			expectedOK:                 false,
			expectedOperandSingleValue: "",
			expectedHasValue:           false,
		},
		// A OperandLabel must be starts without any sapce.
		{
			data:                       "         BUF,LEN ",
			expectedRemains:            ",LEN ",
			expectedOK:                 true,
			expectedOperandSingleValue: "BUF",
			expectedHasValue:           true,
		},
		{
			data:                       "DATA1, DATA2",
			expectedRemains:            ", DATA2",
			expectedOK:                 true,
			expectedOperandSingleValue: "DATA1",
			expectedHasValue:           true,
		},
		{
			data: "		DATA1",
			expectedRemains:            "",
			expectedOK:                 true,
			expectedOperandSingleValue: "DATA1",
			expectedHasValue:           true,
		},
		{
			data:                       "DATA1 ; this is comment",
			expectedRemains:            "; this is comment",
			expectedOK:                 true,
			expectedOperandSingleValue: "DATA1",
			expectedHasValue:           true,
		},
	}
	for testIndex, testCase := range testCaseList {
		target := operand.NewLabel()
		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)
		}
		actualOperandSingleValue := target.SingleValue
		if actualOperandSingleValue != expectedOperandSingleValue {
			t.Errorf("testCase[%d]=%#v, expected=%#v, actual=%#v\n", testIndex, testData, expectedOperandSingleValue, actualOperandSingleValue)
		}
		actualHasValue := target.HasValue
		if actualHasValue != expectedHasValue {
			t.Errorf("testCase[%d]=%#v, expected=%#v, actual=%#v\n", testIndex, testData, expectedHasValue, actualHasValue)
		}
	}

}