Skip to content

Commit

Permalink
added a test suite, adapted from PL/0 Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
tangentstorm committed Jan 19, 2013
1 parent 7ab3d11 commit cf140fc
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/T00Output.mod
@@ -0,0 +1,14 @@
(* http://ooc.sourceforge.net/OOCref/OOCref_7.html#SEC72 *)
MODULE T00Output;
IMPORT Out;

BEGIN
Out.String( "Hello World" );
Out.Ln;
Out.Int( -1, 0 );
Out.Ln;
Out.Int( 0, 0 );
Out.Ln;
Out.Int( 1, 0 );
Out.Ln
END T00Output.
18 changes: 18 additions & 0 deletions test/T01Arithmetic.mod
@@ -0,0 +1,18 @@
MODULE T01Arithmetic;
IMPORT Out;

BEGIN
Out.Int( 2 + 3, 0 ); Out.Ln;
Out.Int( 2 - 3, 0 ); Out.Ln;
Out.Int( 2 * 3, 0 ); Out.Ln;
Out.Int( 2 DIV 3, 0 ); Out.Ln;
Out.Int( 2 MOD 3, 0 ); Out.Ln;

Out.Int( 3 + 2, 0 ); Out.Ln;
Out.Int( 3 - 2, 0 ); Out.Ln;
Out.Int( 3 * 2, 0 ); Out.Ln;
Out.Int( 3 DIV 2, 0 ); Out.Ln;
Out.Int( 3 MOD 2, 0 ); Out.Ln;

Out.Int( -0 , 0 ); Out.Ln; (* should output 0 of course, without the "-" *)
END T01Arithmetic.
7 changes: 7 additions & 0 deletions test/T02Precedence.mod
@@ -0,0 +1,7 @@
MODULE T02Precedence;
IMPORT Out;

BEGIN
Out.Int( 1 + 2 * 3, 0 ); Out.Ln;
Out.Int( (1 + 2) * 3, 0 ); Out.Ln;
END T02Precedence.
10 changes: 10 additions & 0 deletions test/T10Constants.mod
@@ -0,0 +1,10 @@
MODULE T10Constants;
IMPORT Out;

CONST x = 123; y = x * 2; abc="abc";
BEGIN
Out.String( abc ); Out.Ln;
Out.Int( x, 0 ); Out.Ln;
Out.Int( y, 0 ); Out.Ln;
Out.Int( y-x, 0 ); Out.Ln;
END T10Constants.
21 changes: 21 additions & 0 deletions test/T11Variables.mod
@@ -0,0 +1,21 @@
MODULE T11Variables;
IMPORT Out;

VAR x : INTEGER: msg : ARRAY 3 OF CHAR;
BEGIN

x := 0;
Out.Int( x ); Out.Ln;
x := 1;
Out.Int( 1 ); Out.Ln;

x := 7;
INC( x ); Out.Int( x ); Out.Ln;
DEC( x ); Out.Int( x ); Out.Ln;

msg := "abc";
Out.String( msg ); Out.Ln;
msg := "xyz";
Out.String( msg ); Out.Ln;

END T11Variables.
31 changes: 31 additions & 0 deletions test/T20IfThenElse.mod
@@ -0,0 +1,31 @@
MODULE T20IfThenElse;
IMPORT Out;

VAR p : BOOLEAN; i : integer;
BEGIN

p := TRUE;
IF p THEN Out.String( "P" ) ELSE Out.String( "~P" ) END; Out.Ln;
p := ~p;
IF p THEN Out.String( "P" ) ELSE Out.String( "~P" ) END; Out.Ln;

IF 1 # 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln;
IF 1 = 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln;
IF 1 > 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln;
IF 1 < 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln;
IF 1 >= 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln;
IF 1 <= 2 THEN Out.String( "TRUE" ) ELSE Out.String( "FALSE" ) END; Out.Ln;

i := -1;
IF i > 0 THEN Out.String( "+" ) ELSIF i < 0 THEN Out.String( "-" ) ELSE Out.String("0") END;
Out.Ln;

i := 0;
IF i > 0 THEN Out.String( "+" ) ELSIF i < 0 THEN Out.String( "-" ) ELSE Out.String("0") END;
Out.Ln;

i := 1;
IF i > 0 THEN Out.String( "+" ) ELSIF i < 0 THEN Out.String( "-" ) ELSE Out.String("0") END;
Out.Ln;

END T205IfThenElse.
26 changes: 26 additions & 0 deletions test/T21Loops.mod
@@ -0,0 +1,26 @@
MODULE T21Loops;
IMPORT Out;

VAR i : INTEGER;

BEGIN
i := 0;

REPEAT INC( i ); Out.Int( i ); Out.Ln
UNTIL i = 10;

WHILE i > -10 DO
DEC( i, 5 ); Out.Int( i ); Out.Ln
END;

WHILE i > -10 DO
Out.String("This should not Appear");
ELSE

END;

FOR i := 1 TO 3 BY 1 DO Out.Int( i ); Out.Ln END;
FOR i := 3 TO 1 BY -1 DO Out.Int( i ); Out.Ln END;
FOR i := 8 TO 2 BY -2 DO Out.Int( i ); Out.Ln END;

END T21Loops.
30 changes: 30 additions & 0 deletions test/T30Procedures.mod
@@ -0,0 +1,30 @@
MODULE T30Procedures;
IMPORT Out;

PROCEDURE WriteLn( i : INTEGER );
BEGIN
Out.Int( i );
Out.Ln;
END Write;

PROCEDURE Next( i : INTEGER ) : INTEGER;
BEGIN
RETURN i + 1
END Next;

PROCEDURE VarNext( i : INTEGER; VAR j : INTEGER );
BEGIN
END;

VAR x : INTEGER;
BEGIN

x := 0;
WriteLn( x ); (* 0 *)
x := Next( x );
WriteLn( x ); (* 1 *)
WriteLn( Next( x )); (* 2 *)
VarNext( x, x );
WriteLn( x ); (* 2 *)

END T30Procedures.
18 changes: 18 additions & 0 deletions test/T31Nested.mod
@@ -0,0 +1,18 @@
PROCEDURE T31Nested;
IMPORT Out;

PROCEDURE Nested;
PROCEDURE N1;
PROCEDURE N2
PROCEDURE N3
BEGIN Out.String( "[ N3 ]" )
END N3;
BEGIN Out.String( "[ N2 " ); N3; Out.String( "]" )
END N2;
BEGIN Out.String( "[ N1 " ); N2; Out.String( "]" )
END N1;
BEGIN Out.String( "[ Nested " ); N1; Out.String( "]" ); Out.Ln
END Nested;

BEGIN Nested
END T31Nested.
32 changes: 32 additions & 0 deletions test/T32Recursion.mod
@@ -0,0 +1,32 @@
MODULE T32Recursion;


PROCEDURE Binary( number, digits : INTEGER );
VAR place : INTEGER;

PROCEDURE Helper;
VAR bit : INTEGER;
BEGIN
IF ODD( number ) THEN bit := 1 ELSE bit := 0 END;
number := number DIV 2;
(* since we want to print the bits from highest to lowest,
but we're starting with the lowest, we need to put the
the recursive call in the middle. *)
IF place > 0 THEN
cursor := cursor - 1;
Helper;
END;
(* the above code recursively printed all the bits to our left,
so now we can print our bit and return: *)
Out.Int( bit )
END Helper;

BEGIN
place := digits;
helper;
Out.Ln;
END Binary;

BEGIN
Binary( 5, 4 ); (* expect: 0101 *)
END T32Recursion.

0 comments on commit cf140fc

Please sign in to comment.