source: src/tests/io.c @ c386bc1

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since c386bc1 was cd218e8, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

update tests after changing names of basic types, extending the IO test, and adding a literal test

  • Property mode set to 100644
File size: 5.3 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// io.c --
8//
9// Author           : Peter A. Buhr
10// Created On       : Wed Mar  2 16:56:02 2016
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon Sep 11 08:53:41 2017
13// Update Count     : 81
14//
15
16#include <fstream>
17
18int main() {
19        char c;                                                                                         // basic types
20        signed char sc;
21        unsigned char usc;
22        short int si;
23        unsigned short int usi;
24        int i;
25        unsigned int ui;
26        long int li;
27        unsigned long int uli;
28        long long int lli;
29        unsigned long long int ulli;
30        float f;
31        double d;
32        long double ld;
33        float _Complex fc;
34        double _Complex dc;
35        long double _Complex ldc;
36        enum { size = 10 };
37        char s1[size], s2[size];
38
39        int x = 3, y = 5, z = 7;
40        sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
41        sout | 1 | 2 | 3 | endl;
42        sout | '1' | '2' | '3' | endl;
43        sout | 1 | "" | 2 | "" | 3 | endl;
44        sout | endl;
45
46        sout | "opening delimiters" | endl;
47        sout
48                | "x (" | 1
49                | "x [" | 2
50                | "x {" | 3
51                | "x =" | 4
52                | "x $" | 5
53                | "x £" | 6
54                | "x ¥" | 7
55                | "x ¡" | 8
56                | "x ¿" | 9
57                | "x «" | 10
58                | endl | endl;
59
60        sout | "closing delimiters" | endl;
61        sout
62                | 1 | ", x"
63                | 2 | ". x"
64                | 3 | "; x"
65                | 4 | "! x"
66                | 5 | "? x"
67                | 6 | "% x"
68                | 7 | "¢ x"
69                | 8 | "» x"
70                | 9 | ") x"
71                | 10 | "] x"
72                | 11 | "} x"
73                | endl | endl;
74
75        sout | "opening/closing delimiters" | endl;
76        sout
77                | "x`" | 1 | "`x'" | 2
78                | "'x\"" | 3 | "\"x:" | 4
79                | ":x " | 5 | " x\t" | 6
80                | "\tx\f" | 7 | "\fx\v" | 8
81                | "\vx\n" | 9 | "\nx\r" | 10
82                | "\rx"
83                | endl | endl;
84
85        sout | "override opening/closing delimiters" | endl;
86        sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;
87        sout | endl;
88
89        ifstream in;                                                                            // create / open file
90        open( &in, "io.data", "r" );
91
92        sout | "input bacis types" | endl;
93        &in | c | sc | usc                                                                      // character
94                | si | usi | i | ui | li | uli | lli | ulli             // integral
95                | f | d | ld                                                                    // floating point
96                | fc | dc | ldc                                                                 // floating-point complex
97                | cstr( s1 ) | cstr( s2, size );                                // C string, length unchecked and checked
98        sout | endl;
99
100        sout | "output basic types" | endl;
101        sout | c | ' ' | sc | ' ' | usc | endl                          // character
102                | si | usi | i | ui | li | uli | lli | ulli | endl // integral
103                | f | d | ld | endl                                                             // floating point
104                | fc | dc | ldc | endl;                                                 // complex
105        sout | endl;
106
107        sout | "tuples" | endl;
108        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
109        sout | t1 | t2 | endl;                                                          // print tuple
110        sout | endl;
111
112        sout | "toggle separator" | endl;
113        sout | f | "" | d | "" | ld | endl                                      // floating point without separator
114                | sepDisable | fc | dc | ldc | endl                             // complex without separator
115                | fc | sepOn | dc | ldc | endl                                  // local separator add
116                | sepEnable | fc | dc | ldc | endl                              // complex with separator
117                | fc | sepOff | dc | ldc | endl                                 // local separator removal
118                | s1 | sepOff | s2 | endl                                               // local separator removal
119                | s1 | "" | s2 | endl;                                                  // local separator removal
120        sout | endl;
121
122        sout | "change separator" | endl;
123        sout | "from \"" | sep | "\"";
124        sepSet( sout, ", $" );                                                          // change separator, maximum of 15 characters
125        sout | " to \"" | sep | "\"" | endl;
126        sout | f | d | ld | endl
127                | fc | dc | ldc | endl
128                | s1 | s2 | endl
129                | t1 | t2 | endl;                                                               // print tuple
130        sout | endl;
131        sout | "from \"" | sep | "\" ";
132        sepSet( sout, " " );                                                            // restore separator
133        sout | "to \"" | sep | "\"" | endl;
134        sout | f | d | ld | endl
135                | fc | dc | ldc | endl
136                | s1 | s2 | endl
137                | t1 | t2 | endl;                                                               // print tuple
138        sout | endl;
139
140        sout | "check sepOn/sepOff" | endl;
141        sout | sepOn | 1 | 2 | 3 | sepOn | endl;                        // no separator at start/end of line
142        sout | 1 | sepOff | 2 | 3 | endl;                                       // locally turn off implicit separator
143        sout | sepOn | sepOn | 1 | 2 | 3 | sepOn | sepOff | sepOn | '\n'; // no separator at start/end of line
144        sout | 1 | 2 | 3 | "\n\n" | sepOn;                                      // no separator at start of next line
145        sout | 1 | 2 | 3 | endl;
146        sout | endl;
147
148        sout | "check enable/disable" | endl;
149        sout | sepDisable | 1 | 2 | 3 | endl;                           // globally turn off implicit separation
150        sout | 1 | sepOn | 2 | 3 | endl;                                        // locally turn on implicit separator
151        sout | sepEnable | 1 | 2 | 3 | endl | sepDisable;       // globally turn on/off implicit separation
152        sout | 1 | 2 | 3 | endl | sepEnable;                            // globally turn on implicit separation
153        sout | 1 | 2 | 3 | sepOn | sepDisable | endl;           // ignore seperate at end of line
154        sout | 1 | 2 | 3 | sepOn | sepEnable | endl;            // separator at end of line
155        sout | 1 | 2 | 3 | endl;
156        sout | endl;
157
158//      sout | fmt( d, "%8.3f" ) || endl;
159//      sout | endl;
160
161        sepSetTuple( sout, " " );                                                       // set tuple separator from ", " to " "
162        sout | t1 | t2 | " \"" | sep | "\"" | endl;
163        sepSetTuple( sout, ", " );                                                      // reset tuple separator to ", "
164        sout | t1 | t2 | " \"" | sep | "\"" | endl;
165        sout | t1 | t2 | endl;                                                          // print tuple
166        sout | endl;
167
168        [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 };
169        sout | [ 3, 4, "a", 7.2 ] | endl;
170        sout | t3 | endl;
171        sepSetTuple( sout, " " );
172        sout | t3 | endl;
173        sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl;
174        sepSet( sout, "^" );
175        sepSetTuple( sout, "-" );
176        sout | t3 | 3 | 4 | t3 | endl;
177}
178
179// Local Variables: //
180// tab-width: 4 //
181// compile-command: "cfa io.c" //
182// End: //
Note: See TracBrowser for help on using the repository browser.