func (assembler *LineList) ParseEnd(currentLine string) error { source := token.NewSource(currentLine) end := line.NewEnd() err := end.Parse(source) if err != nil { return err } assembler.Lines = append(assembler.Lines, end) return nil }
func (assembler *LineList) ParseDC(currentLine string) error { source := token.NewSource(currentLine) temp := line.NewDC() err := temp.Parse(source) if err != nil { return err } assembler.Lines = append(assembler.Lines, temp) return nil }
func (assembler *LineList) ParseStart(currentLine string) error { source := token.NewSource(currentLine) start := line.NewStart() err := start.Parse(source) if err != nil { return err } assembler.Lines = append(assembler.Lines, start) return nil }
func TestEndParse(t *testing.T) { testCaseList := []testCaseForTestEndParse{ {data: ` END`}, {data: ` END ; COMMENT`}, } for _, testCase := range testCaseList { testData := testCase.data start := line.NewEnd() source := token.NewSource(testData) err := start.Parse(source) if err != nil { t.Error(err) } } }
func TestR1R2Parse(t *testing.T) { testCaseList := []testCaseForTestR1R2Parse{ {data: ` LD GR0, GR1`}, {data: ` LD GR2 , GR3 ; COMMENT`}, } for _, testCase := range testCaseList { testData := testCase.data r1r2 := line.NewR1R2() source := token.NewSource(testData) err := r1r2.Parse(source) if err != nil { t.Error(err) } // t.Error(r1r2) } }
func TestStartParse(t *testing.T) { testCaseList := []testCaseForTestStartParse{ {data: `EX11 START`}, {data: `EX11 START SLABEL`}, {data: `EX11 START SLABEL ; COMMENt`}, } for _, testCase := range testCaseList { testData := testCase.data start := line.NewStart() source := token.NewSource(testData) err := start.Parse(source) if err != nil { t.Error(err) } } }
func TestCommentParse(t *testing.T) { testCaseList := []testCaseForTestCommentParse{ {data: `; This is Comment`}, {data: ` ; This is comment`}, } for _, testCase := range testCaseList { testData := testCase.data source := token.NewSource(testData) register := token.NewComment() err := register.Parse(source) if err != nil { t.Error(err) } } }
func TestAdrParse(t *testing.T) { testCaseList := []testCaseForTestAdrParse{ {data: ` JPL ADR1`}, {data: ` JMI ADR1 ; COMMENT`}, {data: `LABEL JNZ ADR1 ; COMMENT`}, } for _, testCase := range testCaseList { testData := testCase.data adr := line.NewAdr() source := token.NewSource(testData) err := adr.Parse(source) if err != nil { t.Error(err) } // t.Error(adr) } }
func TestDSParse(t *testing.T) { testCaseList := []testCaseForTestDSParse{ {data: ` DS 1234`}, {data: ` DS #10 ; COMMENT`}, {data: `LABEL DS #FFFF ; COMMENT`}, } for _, testCase := range testCaseList { testData := testCase.data ds := line.NewDS() source := token.NewSource(testData) err := ds.Parse(source) if err != nil { t.Error(err) } // t.Error(ds) } }
func TestRParse(t *testing.T) { testCaseList := []testCaseForTestRParse{ {data: ` POP GR0`}, {data: ` POP GR1 ; COMMENT`}, {data: `LABEL POP GR5 ; COMMENT`}, } for _, testCase := range testCaseList { testData := testCase.data adr := line.NewR() source := token.NewSource(testData) err := adr.Parse(source) if err != nil { t.Error(err) } // t.Error(adr) } }
func TestDCParse(t *testing.T) { testCaseList := []testCaseForTestDCParse{ {data: ` DC 1234`}, {data: ` DC #10, 1234, '''test''' ; COMMENT`}, {data: `LABEL DC #FFFF, LABEL2, 'string', 10 ; COMMENT`}, } for _, testCase := range testCaseList { testData := testCase.data dc := line.NewDC() source := token.NewSource(testData) err := dc.Parse(source) if err != nil { t.Error(err) } // t.Error(dc.Operands) } }
func TestRAdrXParse(t *testing.T) { testCaseList := []testCaseForTestRAdrXParse{ {data: ` ADDA GR0, ADR1, GR1`}, {data: ` SUBA GR0, ADR1, GR1 ; COMMENT`}, {data: `LABEL SRL GR0, ADR1, GR1 ; COMMENT`}, } for _, testCase := range testCaseList { testData := testCase.data radrx := line.NewRAdrX() source := token.NewSource(testData) err := radrx.Parse(source) if err != nil { t.Error(err) } // t.Error(radrx) } }
func TestInOutParse(t *testing.T) { testCaseList := []testCaseForTestInOutParse{ {data: ` IN BUFF, LEN`}, {data: ` OUT MSG2, MLEN ; COMMENT`}, {data: `OK OUT MSG1, MLEN ; COMMENT`}, } for _, testCase := range testCaseList { testData := testCase.data inout := line.NewInOut() source := token.NewSource(testData) err := inout.Parse(source) if err != nil { t.Error(err) } // t.Error(inout) } }
func TestNoneParse(t *testing.T) { testCaseList := []testCaseForTestNoneParse{ {data: ` NOP`}, {data: ` RET ; COMMENT`}, {data: `LABEL NOP ; COMMENT`}, {data: `LABEL RPUSH ; COMMENT`}, {data: `LABEL RPOP ; COMMENT`}, } for _, testCase := range testCaseList { testData := testCase.data adr := line.NewNone() source := token.NewSource(testData) err := adr.Parse(source) if err != nil { t.Error(err) } // t.Error(adr) } }
func TestLabelParse(t *testing.T) { label := token.NewLabel() source := token.NewSource("MAIN START") err := label.Parse(source) if err != nil { t.Error(err) } if label.TextValue() != "MAIN" { t.Errorf("Label error %#v", label) } opcode := token.NewOpcode() err = opcode.Parse(source) if err != nil { t.Error(err) } if opcode.TextValue() != "START" { t.Errorf("Label error %#v", opcode) } }
func TestRegisterParse(t *testing.T) { testCaseList := []testCaseForTestRegisterParse{ {data: ` LD GR0, DATA1`}, {data: ` LD GR0, 65535`}, {data: ` LD GR0, #ABCD`}, {data: ` LD GR0, =12345`}, {data: ` LD GR0, =#1FE0`}, {data: ` LD GR0, ='string'`}, {data: ` LD GR0, ='''is esacped quote'`}, } for _, testCase := range testCaseList { testData := testCase.data source := token.NewSource(testData) opcode := token.NewOpcode() err := opcode.Parse(source) if err != nil { t.Error(err) } register := token.NewRegister() err = register.Parse(source) if err != nil { t.Error(err) } comma := token.NewComma() err = comma.Parse(source) if err != nil { t.Error(err) } address := token.NewAddress() err = address.Parse(source) if err != nil { t.Error(err) } } }