diskii/lib/basic/applesoft/applesoft_test.go
Zellyn Hunter e6508a39b4 Add first pass of integer basic decoding
It doesn't do proper spacing yet - the intbasic code listing is
extremely tricky to undestand.
2016-11-22 21:01:51 -05:00

58 lines
2.6 KiB
Go

// Copyright © 2016 Zellyn Hunter <zellyn@gmail.com>
package applesoft
import (
"testing"
"github.com/zellyn/diskii/lib/basic"
)
// helloBinary is a simple basic program used for testing. Listing
// below.
var helloBinary = []byte{
0x11, 0x08, 0x0A, 0x00, 0xBA, 0x22, 0x04, 0x43, 0x41, 0x54, 0x41, 0x4C, 0x4F, 0x47, 0x22, 0x00,
0x17, 0x08, 0x14, 0x00, 0xBA, 0x00, 0x25, 0x08, 0x1E, 0x00, 0xBA, 0x22, 0x48, 0x45, 0x4C, 0x4C,
0x4F, 0x22, 0x3B, 0x00, 0x34, 0x08, 0x28, 0x00, 0xBA, 0x22, 0x2C, 0x20, 0x57, 0x4F, 0x52, 0x4C,
0x44, 0x22, 0x00, 0x49, 0x08, 0x32, 0x00, 0x81, 0x49, 0xD0, 0x31, 0xC1, 0x34, 0x30, 0x3A, 0xBA,
0x22, 0x2A, 0x22, 0x3B, 0x3A, 0x82, 0x49, 0x00, 0x6B, 0x08, 0x3C, 0x00, 0x81, 0x49, 0xD0, 0x31,
0xC1, 0x31, 0x30, 0x3A, 0x81, 0x4A, 0xD0, 0x31, 0xC1, 0x49, 0x3A, 0xBA, 0x22, 0x20, 0x22, 0x3B,
0x3A, 0x82, 0x3A, 0xBA, 0x22, 0x2A, 0x22, 0x3A, 0x82, 0x00, 0x98, 0x08, 0x46, 0x00, 0xB2, 0x22,
0x54, 0x48, 0x49, 0x53, 0x20, 0x49, 0x53, 0x20, 0x41, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20, 0x4F,
0x46, 0x20, 0x41, 0x20, 0x4C, 0x4F, 0x4E, 0x47, 0x20, 0x4C, 0x49, 0x4E, 0x45, 0x20, 0x4F, 0x46,
0x20, 0x54, 0x45, 0x58, 0x54, 0x22, 0x00, 0xEC, 0x08, 0x50, 0x00, 0xBA, 0x22, 0x54, 0x48, 0x49,
0x53, 0x20, 0x49, 0x53, 0x20, 0x41, 0x20, 0x54, 0x45, 0x53, 0x54, 0x20, 0x4F, 0x46, 0x20, 0x41,
0x4E, 0x20, 0x45, 0x56, 0x45, 0x4E, 0x20, 0x4C, 0x4F, 0x4E, 0x47, 0x45, 0x52, 0x20, 0x4C, 0x49,
0x4E, 0x45, 0x20, 0x4F, 0x46, 0x20, 0x54, 0x45, 0x58, 0x54, 0x20, 0x54, 0x48, 0x41, 0x54, 0x20,
0x49, 0x53, 0x20, 0x45, 0x56, 0x45, 0x4E, 0x20, 0x4D, 0x4F, 0x52, 0x45, 0x20, 0x54, 0x48, 0x41,
0x4E, 0x20, 0x38, 0x30, 0x20, 0x43, 0x4F, 0x4C, 0x53, 0x22, 0x00, 0x04, 0x09, 0x5A, 0x00, 0xBA,
0x22, 0x41, 0x4C, 0x4C, 0x20, 0x44, 0x4F, 0x4E, 0x45, 0x20, 0x54, 0x45, 0x53, 0x54, 0x49, 0x4E,
0x47, 0x22, 0x00, 0x00, 0x00, 0x0A,
}
// helloListing is the text version of the basic program above. Note
// that there are trailing newlines on lines 20 and 60.
var helloListing = `10 PRINT "«ctrl-D»CATALOG"
20 PRINT
30 PRINT "HELLO";
40 PRINT ", WORLD"
50 FOR I = 1 TO 40: PRINT "*";: NEXT I
60 FOR I = 1 TO 10: FOR J = 1 TO I: PRINT " ";: NEXT : PRINT "*": NEXT
70 REM "THIS IS A TEST OF A LONG LINE OF TEXT"
80 PRINT "THIS IS A TEST OF AN EVEN LONGER LINE OF TEXT THAT IS EVEN MORE THAN 80 COLS"
90 PRINT "ALL DONE TESTING"
`
// TestParse tests the full parsing and output of a basic program from
// bytes.
func TestParse(t *testing.T) {
listing, err := Decode(helloBinary, 0x801)
if err != nil {
t.Fatal(err)
}
text := basic.ChevronControlCodes(listing.String())
if text != helloListing {
t.Fatalf("Wrong listing; want:\n%s\ngot:\n%s", helloListing, text)
}
}