| 1 |
(* Copyright (C) 2009 Free Software Foundation, Inc. *) |
| 2 |
(* This file is part of GNU Modula-2. |
| 3 |
|
| 4 |
GNU Modula-2 is free software; you can redistribute it and/or modify it under |
| 5 |
the terms of the GNU General Public License as published by the Free |
| 6 |
Software Foundation; either version 2, or (at your option) any later |
| 7 |
version. |
| 8 |
|
| 9 |
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 |
for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License along |
| 15 |
with gm2; see the file COPYING. If not, write to the Free Software |
| 16 |
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *) |
| 17 |
|
| 18 |
MODULE insert ; |
| 19 |
|
| 20 |
IMPORT Strings ; |
| 21 |
IMPORT STextIO ; |
| 22 |
FROM libc IMPORT exit, printf ; |
| 23 |
|
| 24 |
PROCEDURE Assert (b: BOOLEAN; l: CARDINAL) ; |
| 25 |
BEGIN |
| 26 |
IF NOT b |
| 27 |
THEN |
| 28 |
printf("\nassert failed at line %d\n", l); |
| 29 |
exit(1) |
| 30 |
END |
| 31 |
END Assert ; |
| 32 |
|
| 33 |
|
| 34 |
VAR |
| 35 |
a: ARRAY [0..15] OF CHAR; |
| 36 |
BEGIN |
| 37 |
STextIO.WriteString("this is a test"); STextIO.WriteLn ; |
| 38 |
STextIO.WriteString("will become"); STextIO.WriteLn ; |
| 39 |
STextIO.WriteString("this not is a te"); STextIO.WriteLn ; |
| 40 |
STextIO.WriteString(' '); STextIO.WriteLn ; |
| 41 |
Strings.Assign("this is a test", a); |
| 42 |
Strings.Insert("not ", 5, a); |
| 43 |
STextIO.WriteString(a); STextIO.WriteLn ; |
| 44 |
Assert(Strings.Equal(a, "this not is a te"), __LINE__) ; |
| 45 |
Strings.Assign("this not is a te", a); |
| 46 |
Strings.Insert("not ", 5, a); |
| 47 |
Assert(Strings.Equal(a, "this not not is "), __LINE__) ; |
| 48 |
Strings.Assign("this not is a te", a) ; |
| 49 |
Strings.Insert("1234", 14, a) ; |
| 50 |
STextIO.WriteLn; STextIO.WriteString(a); STextIO.WriteLn ; |
| 51 |
Assert(Strings.Equal(a, "this not is a 12"), __LINE__) ; |
| 52 |
Strings.Assign("this not is a te", a); |
| 53 |
Strings.Insert("1234", 0, a) ; |
| 54 |
STextIO.WriteLn; STextIO.WriteString("1234this not is "); STextIO.WriteLn ; |
| 55 |
STextIO.WriteLn; STextIO.WriteString(a); STextIO.WriteLn ; |
| 56 |
Assert(Strings.Equal(a, "1234this not is "), __LINE__) ; |
| 57 |
Strings.Assign("0123456789012345", a); |
| 58 |
Strings.Insert("abcdefghijklmnopqrstuvwxyz", 0, a) ; |
| 59 |
STextIO.WriteLn; STextIO.WriteString("abcdefghijklmnop"); STextIO.WriteLn ; |
| 60 |
STextIO.WriteLn; STextIO.WriteString(a); STextIO.WriteLn ; |
| 61 |
Assert(Strings.Equal(a, "abcdefghijklmnop"), __LINE__) ; |
| 62 |
|
| 63 |
END insert. |