Debian Codegraph @

gcc/testsuite/gm2/pimlib/run/pass/format.mod

raw
1 (* Copyright (C) 2019 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 3, 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,
17 Boston, MA 02110-1301, USA. *)
18
19 MODULE format ; (*!m2pim+gm2*)
20
21 FROM DynamicStrings IMPORT String, ConCat, InitString, EqualArray, KillString, string ;
22 FROM FormatStrings IMPORT Sprintf0, Sprintf1, Sprintf2 ;
23 FROM libc IMPORT exit, printf ;
24 FROM SYSTEM IMPORT ADDRESS, ADR ;
25
26
27 (*
28 checkDelete -
29 *)
30
31 PROCEDURE checkDelete (s: String; a: ARRAY OF CHAR) ;
32 VAR
33 s1 : String ;
34 c1, c2: ADDRESS ;
35 BEGIN
36 c2 := string (s) ;
37 s1 := InitString (a) ;
38 c1 := string (s1) ;
39 IF EqualArray (s, a)
40 THEN
41 printf ("string test passed, '%s' correcly seen '%s'\n", c1, c2)
42 ELSE
43 printf ("string test failed, expecting '%s' and seen '%s'\n", c1, c2) ;
44 r := 1 ;
45 END ;
46 s1 := KillString (s1) ;
47 s := KillString (s) ;
48 END checkDelete ;
49
50
51 (*
52 test -
53 *)
54
55 PROCEDURE test ;
56 VAR
57 s : String ;
58 i, j: INTEGER ;
59 ch : CHAR ;
60 BEGIN
61 s := Sprintf0 (InitString ("abc")) ;
62 checkDelete (s, "abc") ;
63 s := Sprintf0 (InitString ("%%")) ;
64 checkDelete (s, "%") ;
65 s := Sprintf0 (InitString ("%%%%")) ;
66 checkDelete (s, "%%") ;
67 s := Sprintf0 (InitString ("%z")) ;
68 checkDelete (s, "z") ;
69 i := 1 ;
70 s := Sprintf1 (InitString ("%d"), i) ;
71 checkDelete (s, "1") ;
72 i := 12 ;
73 s := Sprintf1 (InitString ("%d"), i) ;
74 checkDelete (s, "12") ;
75 i := 123 ;
76 s := Sprintf1 (InitString ("%d"), i) ;
77 checkDelete (s, "123") ;
78 i := 1 ;
79 j := 2 ;
80 s := Sprintf2 (InitString ("%d %d"), i, j) ;
81 checkDelete (s, "1 2") ;
82 s := Sprintf2 (InitString ("%% %d %d"), i, j) ;
83 checkDelete (s, "% 1 2") ;
84 ch := 'a' ;
85 s := Sprintf1 (InitString ("%c"), ch) ;
86 checkDelete (s, "a") ;
87 s := Sprintf2 (InitString ("%c%c"), ch, ch) ;
88 checkDelete (s, "aa")
89 END test ;
90
91
92 VAR
93 r: INTEGER ;
94 BEGIN
95 r := 0 ;
96 test ;
97 exit (r)
98 END format.