File: IOTestImpl.mesa
Last edited by MBrown on October 21, 1983 11:51 pm
DIRECTORY
Convert,
EditedStream,
FS,
IO,
IOClasses,
RefText,
Rope,
ViewerIO;
IOTestImpl: PROGRAM
IMPORTS
Convert,
EditedStream,
FS,
IO,
IOClasses,
RefText,
Rope,
ViewerIO
= BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
Value: TYPE = IO.Value;
TokenKind: TYPE = IO.TokenKind;
TokenError: TYPE = IO.TokenError;
Utilities
AssertionFailed: SIGNAL = CODE;
TestFailed: ERROR = CODE;
Copy: PROC [in, out: STREAM] = {
DO
out.PutChar[in.GetChar[! IO.EndOfStream => EXIT]];
ENDLOOP;
};
Assert: PROC [condition: BOOL] = {
IF condition THEN RETURN;
SIGNAL AssertionFailed; -- go to debugger
ERROR TestFailed; -- return to test loop
};
AssertEqualRopes: PROC [r1, r2: ROPE] = {
Assert[Rope.Equal[r1, r2]];
};
AssertRopeEqualInputStream: PROC [r: ROPE, s: STREAM] = {
l: INT = r.Length[];
FOR i: INT ← 0, i+1 UNTIL i = l DO
Assert[NOT s.EndOf[]];
Assert[s.GetChar[] = r.Fetch[i]];
ENDLOOP;
THROUGH [0 .. 10] DO
Assert[s.EndOf[]];
[] ← s.GetChar[ ! IO.EndOfStream => LOOP];
Assert[FALSE];
ENDLOOP;
};
AssertEqualRopeLists: PROC [l1, l2: LIST OF ROPE] = {
DO
IF l1 = NIL THEN { Assert[l2 = NIL]; RETURN };
Assert[Rope.Equal[l1.first, l2.first]];
l1 ← l1.rest; l2 ← l2.rest;
ENDLOOP
};
TestLoop
TestLoop: PROC [] = {
TestSimpleStreams[];
TestEditedStreams[];
TestIOClasses[];
TestPrint[];
TestScan[];
TestConvert[];
};
TestSimpleStreams
TestSimpleStreams: PROC [] = {
TestNullStreams[ ! TestFailed => CONTINUE];
TestRIS[ ! TestFailed => CONTINUE];
TestROS[ ! TestFailed => CONTINUE];
TestTIS[ ! TestFailed => CONTINUE];
TestTOS[ ! TestFailed => CONTINUE];
};
TestNullStreams: PROC [] = {
s: STREAM;
chars: PACKED ARRAY [0 .. 10) OF CHAR;
charsPtr: LONG POINTER TO PACKED ARRAY [0 .. 10) OF CHAR = @chars;
out.PutRope["TestNullStreams started\n"];
s ← IO.noWhereStream;
Assert[s.GetInfo[].variety = $output];
Assert[s.GetInfo[].class = $Null];
s.Close[];
s.Reset[];
s.PutChar['a];
s.PutBlock["bcd"];
s.UnsafePutBlock[block: [LOOPHOLE[charsPtr], 0, 10]];
s.Flush[];
s.EraseChar['a];
s ← IO.noInputStream;
Assert[s.GetInfo[].variety = $input];
Assert[s.GetInfo[].class = $Null];
s.Close[];
s.Reset[];
Assert[s.EndOf[]];
Assert[s.CharsAvail[] > 0];
{ [] ← s.GetChar[ ! IO.EndOfStream => GOTO ok];
Assert[FALSE];
EXITS ok => NULL
};
{ s.Backup['a ! IO.Error => IF ec = $IllegalBackup THEN GOTO ok ELSE CONTINUE];
Assert[FALSE];
EXITS ok => NULL
};
Assert[s.GetBlock[RefText.New[10]] = 0];
Assert[s.UnsafeGetBlock[block: [LOOPHOLE[charsPtr], 0, 10]] = 0];
out.PutRope["TestNullStreams ended\n"];
};
TestRIS: PROC [] = {
s: STREAM;
r: ROPE = "This is a rope";
out.PutRope["TestRIS started\n"];
s ← IO.RIS[r];
Assert[s.GetInfo[].variety = $input];
Assert[s.GetInfo[].class = $ROPE];
s.Backup[s.GetChar[]];
Assert[s.GetIndex[] = 0];
Assert[s.GetLength[] = r.Length[]];
s.Reset[];
Assert[s.EndOf[]];
s.Close[];
s ← IO.RIS[r];
AssertRopeEqualInputStream[r, s];
s.Close[];
s ← IO.RIS[r, s];
AssertRopeEqualInputStream[r, s];
s.Close[];
out.PutRope["TestRIS ended\n"];
};
TestTIS: PROC [] = {
s: STREAM;
t: REF TEXT = "This is a ref text";
r: ROPE = "This is a ref text";
out.PutRope["TestTIS started\n"];
s ← IO.TIS[t];
Assert[s.GetInfo[].variety = $input];
Assert[s.GetInfo[].class = $TEXT];
s.Backup[s.GetChar[]];
Assert[s.GetIndex[] = 0];
Assert[s.GetLength[] = t.length];
s.Reset[];
Assert[s.EndOf[]];
s.Close[];
s ← IO.TIS[t];
AssertRopeEqualInputStream[r, s];
s.Close[];
s ← IO.TIS[t, s];
AssertRopeEqualInputStream[r, s];
s.Close[];
out.PutRope["TestTIS ended\n"];
};
TestROS: PROC [] = {
s: STREAM;
r0: ROPE = "This is a rope\n";
r1: ROPE = "This is another rope";
out.PutRope["TestROS started\n"];
s ← IO.ROS[];
Assert[s.GetInfo[].variety = $output];
Assert[s.GetInfo[].class = $ROPE];
s.PutRope[r0];
s.PutChar['a];
s.EraseChar['a];
s.Flush[];
AssertEqualRopes[r0, s.RopeFromROS[]];
s ← IO.ROS[s];
s.PutRope[r0];
AssertEqualRopes[r0, s.RopeFromROS[close: FALSE]];
s.PutRope[r1];
AssertEqualRopes[Rope.Cat[r0, r1], s.RopeFromROS[]];
out.PutRope["TestROS ended\n"];
};
TestTOS: PROC [] = {
s: STREAM;
r0: ROPE = "This is a rope\n";
r1: ROPE = "This is another rope";
out.PutRope["TestTOS started\n"];
s ← IO.TOS[];
Assert[s.GetInfo[].variety = $output];
Assert[s.GetInfo[].class = $TEXT];
s.PutRope[r0];
s.PutChar['a];
s.EraseChar['a];
s.Flush[];
AssertEqualRopes[r0, RefText.TrustTextAsRope[s.TextFromTOS[]]];
s ← IO.TOS[NIL, s];
s.PutRope[r0];
AssertEqualRopes[r0, RefText.TrustTextAsRope[s.TextFromTOS[]]];
s.PutRope[r1];
AssertEqualRopes[Rope.Cat[r0, r1], RefText.TrustTextAsRope[s.TextFromTOS[]]];
out.PutRope["TestTOS ended\n"];
};
TestEditedStreams
TestEditedStreams: PROC [] = {
out.PutRope["TestEditedStreams started\n"];
TestOneEditedStream[
inChars: "\n",
expectedEchoChars: "\n",
expectedDeliveredChars: "\n",
deliverWhen: EditedStream.IsACR];
TestOneEditedStream[
inChars: "This is a test\nIt is only a testx\001 word\027\001\nline of words\021\n",
expectedEchoChars: "This is a test\nIt is only a test\n\n",
expectedDeliveredChars: "This is a test\nIt is only a test\n\n",
deliverWhen: EditedStream.IsACR];
TestOneEditedStream[
inChars: "This is a line\n\033\027\001nother line\n",
expectedEchoChars: "This is a line\nThis is another line\n",
expectedDeliveredChars: "This is a line\nThis is another line\n",
deliverWhen: EditedStream.IsACR];
TestOneEditedStream[
inChars: "This is a line\nESC\033 is a noop here\n",
expectedEchoChars: "This is a line\nESC is a noop here\n",
expectedDeliveredChars: "This is a line\nESC is a noop here\n",
deliverWhen: EditedStream.IsACR];
out.PutRope["TestEditedStreams ended\n"];
};
TestOneEditedStream: PROC [inChars, expectedEchoChars, expectedDeliveredChars: ROPE,
deliverWhen: EditedStream.DeliverWhenProc] = {
in: STREAM = IO.RIS[inChars];
echo: STREAM = IO.ROS[];
saveDelivered: STREAM = IO.ROS[];
editedStream: STREAM =
EditedStream.Create[in: in, echoTo: echo, deliverWhen: deliverWhen];
Copy[in: editedStream, out: saveDelivered];
AssertEqualRopes[expectedEchoChars, echo.RopeFromROS[]];
AssertEqualRopes[expectedDeliveredChars, saveDelivered.RopeFromROS[]];
};
TestIOClasses
TestIOClasses: PROC [] = {
out.PutRope["TestIOClasses started\n"];
TestOneFilterCommentStream[
inChars: "Foo: PROGRAM --\n=----{-- --}.",
expectedDeliveredChars: "Foo: PROGRAM \n= { }."];
TestDribbleOutputStream[];
out.PutRope["TestIOClasses ended\n"];
};
TestOneFilterCommentStream: PROC [inChars, expectedDeliveredChars: ROPE] = {
in: STREAM = IO.RIS[inChars];
saveDelivered: STREAM = IO.ROS[];
filteredStream: STREAM =
IOClasses.CreateCommentFilterStream[input: in];
Copy[in: filteredStream, out: saveDelivered];
AssertEqualRopes[expectedDeliveredChars, saveDelivered.RopeFromROS[]];
};
TestDribbleOutputStream: PROC [] = TRUSTED {
chars: PACKED ARRAY [0 .. 4) OF CHAR ← ['T, 'h, 'i, 's];
charsPtr: LONG POINTER TO PACKED ARRAY [0 .. 4) OF CHAR = @chars;
out1: STREAM = IO.ROS[];
out2: STREAM = IO.ROS[];
dribble: STREAM =
IOClasses.CreateDribbleOutputStream[out1, out2];
dribble.PutChar['T];
dribble.PutBlock[block: "his is a test\n"];
dribble.UnsafePutBlock[block: [LOOPHOLE[charsPtr], 0, 4]];
dribble.Flush[];
dribble.PutRope[" is only a test\n\n"];
dribble.EraseChar['\n];
AssertEqualRopes["This is a test\nThis is only a test\n", out1.RopeFromROS[close: FALSE]];
AssertEqualRopes["This is a test\nThis is only a test\n", out2.RopeFromROS[close: FALSE]];
dribble.Reset[];
dribble.Close[];
};
TestPrint
TestPrint: PROC [] = {
TestPut[ ! TestFailed => CONTINUE];
TestPutF[ ! TestFailed => CONTINUE];
};
TestPut: PROC [] = {
s: STREAM;
out.PutRope["TestPut started\n"];
s ← IO.ROS[];
s.Put[IO.int[0], IO.card[0], IO.char['0]];
s.Put[IO.rope["0"], IO.text["0"]];
s.Put[IO.atom[NIL], IO.atom[$NIL]];
s.Put[IO.bool[TRUE], IO.bool[FALSE]];
s.PutL[LIST[IO.real[1234.43E-1], IO.char[' ], IO.card[123456543]]];
AssertEqualRopes[s.RopeFromROS[], "00000<NIL>NILTRUEFALSE123.443 123456543"];
out.PutRope["TestPut ended\n"];
};
TestPutF: PROC = {
TestFormat: PROC [result, format: ROPENIL, v: Value] = {
ENABLE TestFailed => CONTINUE;
stream: STREAM = IO.ROS[];
stream.PutF[format, v];
AssertEqualRopes[stream.RopeFromROS[], result];
};
out.PutRope["TestPutF started\n"];
TestFormat["|atom|", "|%g|", IO.atom[$atom]];
TestFormat["| atom|", "|%7g|", IO.atom[$atom]];
TestFormat["|atom |", "|%-7g|", IO.atom[$atom]];
TestFormat["|123|", "|%d|", IO.card[123]];
TestFormat["|123|", "|%g|", IO.card[123]];
TestFormat["| 123|", "|%5g|", IO.card[123]];
TestFormat["| 123|", "|%5d|", IO.card[123]];
TestFormat["|00123|", "|%05d|", IO.card[123]];
TestFormat["|123 |", "|%-5d|", IO.card[123]];
TestFormat["|1234567|", "|%5d|", IO.card[1234567]];
TestFormat["| 10B|", "|%4b|", IO.card[8]];
TestFormat["| 1FH|", "|%4x|", IO.card[31]];
TestFormat["|1.234532e+4|", "|%4.5e|", IO.real[12345.321]];
TestFormat["| 12:00:01|", "|%9r|", IO.int[43201]];
out.PutRope["TestPutF ended\n"];
};
TestScan
TestScan: PROC [] = {
TestGetToken[ ! TestFailed => CONTINUE];
TestGetLine[ ! TestFailed => CONTINUE];
TestSkipOver[ ! TestFailed => CONTINUE];
TestGetCedarToken[ ! TestFailed => CONTINUE];
CheckFileForErrors["IOTestImpl.mesa" ! TestFailed => CONTINUE];
};
TestGetToken: PROC [] = {
GetTokenize: PROC [s: STREAM, break: IO.BreakProc] RETURNS [LIST OF ROPE] = {
l: LIST OF ROPECONS[NIL, NIL];
lTail: LIST OF ROPE ← l;
DO
lTail.rest ← CONS[first: s.GetTokenRope[break ! IO.EndOfStream => EXIT].token, rest: NIL];
lTail ← lTail.rest;
ENDLOOP;
RETURN [l.rest]
};
OneGetTokenTest: PROC [r: ROPE, l: LIST OF ROPE, break: IO.BreakProc ← IO.TokenProc] = {
AssertEqualRopeLists[GetTokenize[IO.RIS[r], break], l];
};
out.PutRope["TestGetToken started\n"];
OneGetTokenTest["123abc 456def/ +- ", LIST["123abc", "456def", "/", "+", "-"]];
OneGetTokenTest["123abc 456def/ +-", LIST["123abc", "456def", "/", "+", "-"]];
out.PutRope["TestGetToken ended\n"];
};
TestGetLine: PROC [] = {
GetLineize: PROC [s: STREAM] RETURNS [LIST OF ROPE] = {
l: LIST OF ROPECONS[NIL, NIL];
lTail: LIST OF ROPE ← l;
DO
lTail.rest ← CONS[first: s.GetLineRope[ ! IO.EndOfStream => EXIT], rest: NIL];
lTail ← lTail.rest;
ENDLOOP;
RETURN [l.rest]
};
OneGetLineTest: PROC [r: ROPE, l: LIST OF ROPE] = {
AssertEqualRopeLists[GetLineize[IO.RIS[r]], l];
};
out.PutRope["TestGetLine started\n"];
OneGetLineTest["123abc\n456def\n\n", LIST["123abc", "456def", ""]];
OneGetLineTest["123abc\n456def\n\n ", LIST["123abc", "456def", "", " "]];
out.PutRope["TestGetLine ended\n"];
};
TestSkipOver: PROC [] = {
};
TestGetCedarToken: PROC [] = {
GetCedarTokenize: PROC [s: STREAM, flushComments: BOOL]
RETURNS [LIST OF TokenKind, LIST OF ROPE] = {
t: LIST OF TokenKind ← CONS[tokenEOF, NIL]; tTail: LIST OF TokenKind ← t;
l: LIST OF ROPECONS[NIL, NIL]; lTail: LIST OF ROPE ← l;
tokenKind: TokenKind; token: ROPE;
DO
[tokenKind: tokenKind, token: token] ←
s.GetCedarTokenRope[flushComments ! IO.EndOfStream => EXIT];
tTail.rest ← CONS[tokenKind, NIL]; tTail ← tTail.rest;
lTail.rest ← CONS[token, NIL]; lTail ← lTail.rest;
ENDLOOP;
RETURN [t.rest, l.rest]
};
OneGetCedarTokenTest: PROC [
r: ROPE, t: LIST OF TokenKind, l: LIST OF ROPE, flushComments: BOOL] = {
t1: LIST OF TokenKind; l1: LIST OF ROPE;
[t1, l1] ← GetCedarTokenize[IO.RIS[r], flushComments];
AssertEqualTokenKindLists[t, t1];
AssertEqualRopeLists[l, l1];
};
AssertEqualTokenKindLists: PROC [l1, l2: LIST OF TokenKind] = {
DO
IF l1 = NIL THEN { Assert[l2 = NIL]; RETURN };
Assert[l1.first = l2.first];
l1 ← l1.rest; l2 ← l2.rest;
ENDLOOP
};
out.PutRope["TestGetCedarToken started\n"];
OneGetCedarTokenTest[
"ab+cd--ef\n--gh-- ",
LIST[$tokenID, $tokenSINGLE, $tokenID],
LIST["ab", "+", "cd"],
TRUE];
OneGetCedarTokenTest[
"ab+cd--ef\n--gh--",
LIST[$tokenID, $tokenSINGLE, $tokenID, $tokenCOMMENT, tokenCOMMENT],
LIST["ab", "+", "cd", "--ef\n", "--gh--"],
FALSE];
out.PutRope["TestGetCedarToken ended\n"];
};
CheckFileForErrors: PROC [file: ROPE] = {
stream: IO.STREAM; scratch: REF TEXT;
token: REF TEXT; tokenKind: TokenKind;
out.PutRope["CheckFileForErrors started..."];
stream ← FS.StreamOpen[file ! FS.Error => {
out.PutRope[error.explanation]; out.PutChar['\n]; RETRY }];
out.PutRope["Stream open\n"];
scratch ← RefText.ObtainScratch[100];
DO
[tokenKind: tokenKind, token: token] ← stream.GetCedarToken[scratch];
Assert[tokenKind # tokenERROR];
IF tokenKind = tokenEOF THEN EXIT;
IF token # scratch THEN {
out.PutRope["Token more than 100 bytes long\n"];
out.PutText[token];
};
ENDLOOP;
RefText.ReleaseScratch[scratch];
stream.Close[];
out.PutRope["CheckFileForErrors ended\n"];
};
TestConvert
TestConvert: PROC [] = {
TestConversions[ ! TestFailed => CONTINUE];
TestParses[ ! TestFailed => CONTINUE];
};
TestConversions: PROC = {
out.PutRope["TestConversions started\n"];
TestIntFromRope["0", 0];
TestIntFromRope["000", 000];
TestIntFromRope["12343", 12343];
TestIntFromRope["8D", 8D];
TestIntFromRope["8D2", 8D2];
TestIntFromRope["+8D2", +8D2];
TestIntFromRope["-8D2", -8D2];
TestIntFromRope[" -8D2 ", -8D2];
TestIntFromRope["2147483647", INT.LAST];
TestIntFromRope["-2147483648", INT.FIRST];
TestIntFromRope["2D09", 2D09];
TestIntFromRope["377B", 377B];
TestIntFromRope["-377B", -377B];
TestIntFromRope["-377B2", -377B2];
TestIntFromRope["17777777777B", 17777777777B];
TestIntFromRope["1777777777B1", 1777777777B1];
TestIntFromRope["1B10", 1B10];
TestIntFromRope["0FFH", 0FFH];
TestIntFromRope["-0FFH", -0FFH];
TestIntFromRope["-0100H2", -0100H2]; -- -0FFH2 overflows (in compiler)
TestIntFromRope["7FFFFFFFH", 7FFFFFFFH];
TestIntFromRope["7FFFFFFH1", 7FFFFFFH1];
TestIntFromRope["7H7", 7H7];
TestIntFromRope["", 0, TRUE];
TestIntFromRope[" ", 0, TRUE];
TestIntFromRope["/", 0, TRUE];
TestIntFromRope["-8D-2", 0, TRUE];
TestIntFromRope["-8D2D2", 0, TRUE];
TestIntFromRope["2D10", 0, TRUE];
TestIntFromRope["2147483648", 0, TRUE];
TestIntFromRope["-2147483649", 0, TRUE];
TestIntFromRope["-8B-2", 0, TRUE];
TestIntFromRope["-8B2B2", 0, TRUE];
TestIntFromRope["2B10", 0, TRUE];
TestIntFromRope["40000000000B", 0, TRUE];
TestIntFromRope["4B10", 0, TRUE];
TestIntFromRope["-8H-2", 0, TRUE];
TestIntFromRope["100000000H", 0, TRUE];
TestIntFromRope["1H8", 0, TRUE];
TestRealFromRope["99999999999999999999.0", 1.0E+20];
TestRealFromRope["0.99999999999999999999", 1.0];
TestRealFromRope["99999999999999999999.99999999999999999999", 1.0E+20];
TestRealFromRope[".0", .0];
TestRealFromRope["1E0", 1.0];
TestRealFromRope["1E+0", 1.0];
TestRealFromRope["1E-0", 1.0];
TestRealFromRope["1.", 1.0, TRUE];
TestRealFromRope[".E", 1.0, TRUE];
TestRealFromRope["1E", 1.0, TRUE];
TestRealFromRope["1.E0", 1.0, TRUE];
out.PutRope["TestConversions ended\n"];
};
TestIntFromRope: PROC [r: ROPE, i: INT, fail: BOOLFALSE] = {
ENABLE TestFailed => CONTINUE;
ri: INT ← Convert.IntFromRope[r ! Convert.Error => { Assert[fail]; GOTO return }];
Assert[NOT fail AND (ri = i)];
EXITS return => NULL
};
TestRealFromRope: PROC [r: ROPE, e: REAL, fail: BOOLFALSE] = {
ENABLE TestFailed => CONTINUE;
rr: REAL ← Convert.RealFromRope[r ! Convert.Error => { Assert[fail]; GOTO return }];
Assert[NOT fail AND (rr = e)];
EXITS return => NULL
};
TestParses: PROC = {
out.PutRope["TestParses started\n"];
TestParse["\"error extended char in rope \\", IO.rope[NIL], TRUE];
TestParse["\"error extended char in rope \\x", IO.rope[NIL], TRUE];
TestParse["\"error extended char in rope \\1x", IO.rope[NIL], TRUE];
TestParse["\"error extended char in rope \\12x", IO.rope[NIL], TRUE];
TestParse["\"error extended char in rope \\12c", IO.rope[NIL], TRUE];
TestParse["\"error extended char in rope \\777", IO.rope[NIL], TRUE];
TestParse["\"error extended char in rope \\999", IO.rope[NIL], TRUE];
TestParse["\"ok extended char in rope \\n\"", IO.rope["ok extended char in rope \n"]];
TestParse["\"ok extended char in rope \\277\"", IO.rope["ok extended char in rope \277"]];
TestParse["'\\", IO.char[0C], TRUE];
TestParse["'\\x", IO.char[0C], TRUE];
TestParse["'\\1", IO.char[0C], TRUE];
TestParse["'\\12", IO.char[0C], TRUE];
TestParse["'\\12c", IO.char[0C], TRUE];
TestParse["'\\777", IO.char[0C], TRUE];
TestParse["'\\999", IO.char[0C], TRUE];
TestParse["'\\n", IO.char['\n]];
TestParse["'\\277", IO.char['\277]];
TestParse["\"funny rope literal \\015 \\n\"\" .\"", IO.rope["funny rope literal \015 \n\" ."]];
TestParse["\"unterminated rope literal ...", IO.rope[NIL], TRUE];
TestParse["$atom", IO.atom[$atom]];
TestParse["$", IO.atom[$NIL], TRUE];
TestParse["$1234", IO.atom[$NIL], TRUE, TRUE];
TestParse["1234.43E-1", IO.real[1234.43E-1]];
TestParse[".12343", IO.real[.12343]];
TestParse["5E5", IO.real[5E5]];
TestParse["5E+5", IO.real[5E+5]];
TestParse["5E-5", IO.real[5E-5]];
TestParse["015C", IO.char[015C]];
TestParse["'c", IO.char['c]];
TestParse["'\\t", IO.char['\t]];
TestParse["'\\015", IO.char['\015]];
TestParse["12343", IO.card[12343]];
TestParse["0A0H", IO.card[0A0H]];
TestParse["10B", IO.card[10B]];
TestParse["8B", IO.card[0], TRUE];
TestParse["8D2", IO.card[8D2]];
TestParse["08D02", IO.card[08D02]];
TestParse["TRUE", IO.bool[TRUE]];
TestParse["N", IO.bool[FALSE]];
out.PutRope["TestParses ended\n"];
};
TestParse: PROC [rope: Rope.ROPE, value: Value,
error: BOOLEANFALSE, streamNonempty: BOOLFALSE] = {
ENABLE TestFailed => CONTINUE;
AssertL: PROC [condition: BOOL] = {
IF condition OR error THEN RETURN;
SIGNAL AssertionFailed; -- go to debugger
ERROR TestFailed; -- return to test loop
};
stream: STREAMIO.RIS[rope];
tokenRope: ROPE;
scratch: REF TEXT = RefText.ObtainScratch[100];
token: REF TEXT;
errorMsg: TokenError;
tokenKind: TokenKind;
{ -- EXITS TestEOF
ENABLE Convert.Error => { AssertL[FALSE]; GOTO TestEOF };
[tokenKind, token, , errorMsg] ← stream.GetCedarToken[scratch];
tokenRope ← RefText.TrustTextAsRope[token];
SELECT tokenKind FROM
tokenID => WITH value SELECT FROM
rope: Value.rope => AssertL[tokenRope.Equal[rope.value]];
bool: Value.boolean => { b: BOOL =
Convert.BoolFromRope[tokenRope]; AssertL[b = bool.value] };
ENDCASE => AssertL[FALSE];
tokenDECIMAL => WITH value SELECT FROM
card: Value.cardinal => { c: LONG CARDINAL =
Convert.CardFromDecimalLiteral[tokenRope]; AssertL[c = card.value] };
ENDCASE => AssertL[FALSE];
tokenOCTAL => WITH value SELECT FROM
card: Value.cardinal => { c: LONG CARDINAL =
Convert.CardFromOctalLiteral[tokenRope]; AssertL[c = card.value] };
ENDCASE => AssertL[FALSE];
tokenHEX => WITH value SELECT FROM
card: Value.cardinal => { c: LONG CARDINAL =
Convert.CardFromHexLiteral[tokenRope]; AssertL[c = card.value] };
ENDCASE => AssertL[FALSE];
tokenREAL => WITH value SELECT FROM
real: Value.real => { r: REAL =
Convert.RealFromRope[tokenRope]; AssertL[r = real.value] };
ENDCASE => AssertL[FALSE];
tokenCHAR => WITH value SELECT FROM
char: Value.character => { c: CHAR =
Convert.CharFromLiteral[tokenRope]; AssertL[c = char.value] };
ENDCASE => AssertL[FALSE];
tokenROPE => WITH value SELECT FROM -- tokenRope => a rope literal
rope: Value.rope => { r: ROPE =
Convert.RopeFromLiteral[tokenRope]; AssertL[r.Equal[rope.value]] };
ENDCASE => AssertL[FALSE];
tokenATOM => WITH value SELECT FROM
atom: Value.atom => { a: ATOM =
Convert.AtomFromRope[tokenRope]; AssertL[a = atom.value] };
ENDCASE => AssertL[FALSE];
ENDCASE => AssertL[FALSE];
GOTO TestEOF;
EXITS TestEOF => {
[tokenKind, token, , errorMsg] ← stream.GetCedarToken[scratch];
SELECT tokenKind FROM
tokenEOF => Assert[NOT streamNonempty];
ENDCASE => Assert[streamNonempty];
RefText.ReleaseScratch[scratch]
};
}};
Start Code
in, out: STREAM;
[in: in, out: out] ← ViewerIO.CreateViewerStreams["IO test"];
out.PutRope["\nIOTestImpl started\n"];
{ ENABLE RuntimeError.BoundsFault =>
{ out.PutRope["BoundsFault\n"]; CONTINUE };
x: INT ← 37777777777B;
};
TestLoop[];
out.PutRope["\nIOTestImpl ended\n"];
in.Close[];
out.Close[];
END.