| 1 |
(* Copyright (C) 2008 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 testconvert ; |
| 19 |
|
| 20 |
FROM SYSTEM IMPORT ADR ; |
| 21 |
FROM StringConvert IMPORT LongrealToString ; |
| 22 |
FROM DynamicStrings IMPORT String, EqualArray, string ; |
| 23 |
FROM libc IMPORT exit, printf ; |
| 24 |
|
| 25 |
PROCEDURE Assert (b: BOOLEAN; f: ARRAY OF CHAR; l: CARDINAL; |
| 26 |
message: ARRAY OF CHAR) ; |
| 27 |
BEGIN |
| 28 |
IF NOT b |
| 29 |
THEN |
| 30 |
printf("%s:%d: assert failed: %s\n", ADR(f), l, ADR(message)) ; |
| 31 |
exit(1) |
| 32 |
END |
| 33 |
END Assert ; |
| 34 |
|
| 35 |
|
| 36 |
VAR |
| 37 |
s: String ; |
| 38 |
BEGIN |
| 39 |
s := LongrealToString(-123.0, 8, 3) ; |
| 40 |
printf("returned value '%s'\n", string(s)) ; |
| 41 |
Assert(EqualArray(LongrealToString(-123.0, 8, 3), '-123.000'), __FILE__, __LINE__, '-123.000') ; |
| 42 |
s := LongrealToString(1.0, 4, 2) ; |
| 43 |
printf("returned value '%s'\n", string(s)) ; |
| 44 |
Assert(EqualArray(LongrealToString(1.0, 4, 2), '1.00'), __FILE__, __LINE__, '1.00') ; |
| 45 |
s := LongrealToString(1.0, 4, 3) ; |
| 46 |
printf("returned value '%s'\n", string(s)) ; |
| 47 |
Assert(EqualArray(LongrealToString(1.0, 4, 3), '1.00'), __FILE__, __LINE__, '1.00') ; |
| 48 |
s := LongrealToString(1.0, 6, 3) ; |
| 49 |
printf("returned value '%s'\n", string(s)) ; |
| 50 |
Assert(EqualArray(LongrealToString(1.0, 6, 3), ' 1.000'), __FILE__, __LINE__, ' 1.000') ; |
| 51 |
s := LongrealToString(123.0, 8, 3) ; |
| 52 |
printf("returned value '%s'\n", string(s)) ; |
| 53 |
Assert(EqualArray(LongrealToString(123.0, 8, 3), ' 123.000'), __FILE__, __LINE__, ' 123.000') ; |
| 54 |
s := LongrealToString(-123.0, 6, 3) ; |
| 55 |
printf("returned value '%s'\n", string(s)) ; |
| 56 |
Assert(EqualArray(LongrealToString(-123.0, 6, 3), '-123.0'), __FILE__, __LINE__, '-123.0') ; |
| 57 |
END testconvert. |