93 lines
1.9 KiB
QBasic
93 lines
1.9 KiB
QBasic
' ============================================================
|
|
' Test program for named labels with GOTO and GOSUB
|
|
' ============================================================
|
|
|
|
PRINT "==== Named Label Tests ===="
|
|
|
|
' ---- Test 1: Simple GOTO with named label ----
|
|
PRINT ""
|
|
PRINT "---- Test 1: GOTO named label ----"
|
|
GOTO skipSection
|
|
PRINT "ERROR: This should be skipped"
|
|
skipSection:
|
|
PRINT "Jumped to skipSection"
|
|
|
|
' ---- Test 2: GOSUB with named label ----
|
|
PRINT ""
|
|
PRINT "---- Test 2: GOSUB named label ----"
|
|
GOSUB mySubroutine
|
|
PRINT "Returned from GOSUB"
|
|
GOTO afterSub
|
|
|
|
mySubroutine:
|
|
PRINT "Inside mySubroutine"
|
|
RETURN
|
|
|
|
afterSub:
|
|
|
|
' ---- Test 3: Labels with underscores ----
|
|
PRINT ""
|
|
PRINT "---- Test 3: Labels with underscores ----"
|
|
GOTO my_label_here
|
|
PRINT "ERROR: should not print"
|
|
my_label_here:
|
|
PRINT "Reached my_label_here"
|
|
|
|
' ---- Test 4: Mixed numeric and named labels ----
|
|
PRINT ""
|
|
PRINT "---- Test 4: Mixed numeric and named ----"
|
|
GOTO 100
|
|
PRINT "ERROR: should not print"
|
|
100 PRINT "At line 100"
|
|
GOTO namedAfter100
|
|
PRINT "ERROR: should not print"
|
|
namedAfter100:
|
|
PRINT "At namedAfter100"
|
|
|
|
' ---- Test 5: Label with statement on same line ----
|
|
PRINT ""
|
|
PRINT "---- Test 5: Label with trailing statement ----"
|
|
GOTO inlineLabel
|
|
PRINT "ERROR: should not print"
|
|
inlineLabel: PRINT "Statement on same line as label"
|
|
|
|
' ---- Test 6: GOSUB to named label, then GOTO past RETURN ----
|
|
PRINT ""
|
|
PRINT "---- Test 6: GOSUB named + flow control ----"
|
|
DIM count AS INTEGER
|
|
count = 0
|
|
loopStart:
|
|
count = count + 1
|
|
IF count <= 3 THEN
|
|
GOSUB doWork
|
|
GOTO loopStart
|
|
END IF
|
|
PRINT "Loop done, count = "; count
|
|
GOTO afterWork
|
|
|
|
doWork:
|
|
PRINT " Working, count = "; count
|
|
RETURN
|
|
|
|
afterWork:
|
|
|
|
' ---- Test 7: Multiple GOSUBs to different named labels ----
|
|
PRINT ""
|
|
PRINT "---- Test 7: Multiple named GOSUBs ----"
|
|
GOSUB subA
|
|
GOSUB subB
|
|
GOSUB subA
|
|
GOTO afterSubs
|
|
|
|
subA:
|
|
PRINT "In subA"
|
|
RETURN
|
|
|
|
subB:
|
|
PRINT "In subB"
|
|
RETURN
|
|
|
|
afterSubs:
|
|
|
|
PRINT ""
|
|
PRINT "==== ALL NAMED LABEL TESTS COMPLETE ===="
|