TestRope6.mesa
Copyright Ó 1989, 1991 by Xerox Corporation. All rights reserved.
DIRECTORY
Rope;
TestRope6: CEDAR PROGRAM
IMPORTS Rope = {
r1, r2, r3: Rope.ROPE ¬ NIL;
PutChar: PROC [ch: CHAR] = TRUSTED MACHINE CODE {
"XR�ugPutChar"
};
PutInt: PROC [i: INT] = {
stack: ARRAY [0..10] OF CHAR;
nChars: INT ¬ 0;
negative: BOOL ¬ FALSE;
IF i<0 THEN {i¬-i; negative¬TRUE};
DO
digit: NAT ¬ i MOD 10;
stack[nChars] ¬ VAL['0.ORD + digit];
nChars ¬ nChars + 1;
IF i < 10 THEN EXIT;
i ¬ i / 10;
ENDLOOP;
IF negative THEN {
stack[nChars] ¬ '-;
nChars ¬ nChars + 1;
};
PutChar[' ];
FOR n: NAT DECREASING IN [0 .. nChars) DO
PutChar[stack[n]];
ENDLOOP;
};
PutRope: PROC [s: Rope.ROPE] = TRUSTED {
length: INT; c: CHAR;
length ¬ Rope.Length[s];
PutChar['[];
PutInt[length];
PutChar['*];
FOR i: INT IN [0..length) DO
c ¬ Rope.Fetch[s, i];
PutChar[c];
ENDLOOP;
PutChar[']];
};
PutRope["--000--"];
r1 ¬ Rope.Concat["ab", "12"];
PutRope[r1];
PutRope["--111--"];
r1 ¬ Rope.Concat["abcd", "1234"];
PutRope[r1];
PutRope["--222--"];
r2 ¬ Rope.Cat["ab", "cd", "12", "34"];
PutRope[r2];
PutRope["--333--"];
r3 ¬ "abcd876867876";
PutRope[r3];
PutRope["--444--"];
IF Rope.Equal[r1, r2]
THEN PutRope["equal ok"]
ELSE PutRope["equal wrong"];
PutRope["--555--"];
IF Rope.Equal[r1, r3]
THEN PutRope["not equal wrong"]
ELSE PutRope["not equal ok"];
PutRope["--666--"];
FOR i: INT IN [0..200) DO
r1 ¬ Rope.Concat["ab", r1];
r1 ¬ Rope.Concat[r1, "12"];
ENDLOOP;
r1 ¬ Rope.Substr[r1, 390, 30];
PutRope[r1];
PutRope["--777--"];
}.