source: src/tests/io.c@ 7416d46a

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 7416d46a was 5f20b30, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

update io-test and fix literal-test output

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