source: src/tests/io.c @ b8a17e2

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 b8a17e2 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
RevLine 
[53ba273]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
[cd218e8]12// Last Modified On : Mon Sep 11 08:53:41 2017
13// Update Count     : 81
[53ba273]14//
15
16#include <fstream>
17
18int main() {
[5a7966b]19        char c;                                                                                         // basic types
[cd218e8]20        signed char sc;
21        unsigned char usc;
[53ba273]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;
[5a7966b]36        enum { size = 10 };
37        char s1[size], s2[size];
[53ba273]38
[58b5d03]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
[86f384b]46        sout | "opening delimiters" | endl;
[5a7966b]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
[86f384b]58                | endl | endl;
59
60        sout | "closing delimiters" | endl;
[5a7966b]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"
[86f384b]73                | endl | endl;
74
75        sout | "opening/closing delimiters" | endl;
[5a7966b]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
[86f384b]82                | "\rx"
83                | endl | endl;
84
85        sout | "override opening/closing delimiters" | endl;
[5a7966b]86        sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;
[86f384b]87        sout | endl;
[5a7966b]88
89        ifstream in;                                                                            // create / open file
[6b6597c]90        open( &in, "io.data", "r" );
[53ba273]91
[86f384b]92        sout | "input bacis types" | endl;
[cd218e8]93        &in | c | sc | usc                                                                      // character
[7bc4e6b]94                | si | usi | i | ui | li | uli | lli | ulli             // integral
95                | f | d | ld                                                                    // floating point
96                | fc | dc | ldc                                                                 // floating-point complex
[5a7966b]97                | cstr( s1 ) | cstr( s2, size );                                // C string, length unchecked and checked
[86f384b]98        sout | endl;
[53ba273]99
[86f384b]100        sout | "output basic types" | endl;
[cd218e8]101        sout | c | ' ' | sc | ' ' | usc | endl                          // character
[5a7966b]102                | si | usi | i | ui | li | uli | lli | ulli | endl // integral
103                | f | d | ld | endl                                                             // floating point
104                | fc | dc | ldc | endl;                                                 // complex
[53ba273]105        sout | endl;
[86f384b]106
107        sout | "tuples" | endl;
[53a6c2a]108        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
[86f384b]109        sout | t1 | t2 | endl;                                                          // print tuple
110        sout | endl;
111
112        sout | "toggle separator" | endl;
[5a7966b]113        sout | f | "" | d | "" | ld | endl                                      // floating point without separator
[53a6c2a]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
[53ba273]120        sout | endl;
121
[86f384b]122        sout | "change separator" | endl;
[53a6c2a]123        sout | "from \"" | sep | "\"";
[5a7966b]124        sepSet( sout, ", $" );                                                          // change separator, maximum of 15 characters
[53a6c2a]125        sout | " to \"" | sep | "\"" | endl;
[829c907]126        sout | f | d | ld | endl
[5a7966b]127                | fc | dc | ldc | endl
[86f384b]128                | s1 | s2 | endl
129                | t1 | t2 | endl;                                                               // print tuple
[d395012]130        sout | endl;
[53a6c2a]131        sout | "from \"" | sep | "\" ";
[86f384b]132        sepSet( sout, " " );                                                            // restore separator
[53a6c2a]133        sout | "to \"" | sep | "\"" | endl;
[86f384b]134        sout | f | d | ld | endl
135                | fc | dc | ldc | endl
136                | s1 | s2 | endl
137                | t1 | t2 | endl;                                                               // print tuple
[d395012]138        sout | endl;
[6b6597c]139
[53a6c2a]140        sout | "check sepOn/sepOff" | endl;
141        sout | sepOn | 1 | 2 | 3 | sepOn | endl;                        // no separator at start/end of line
[5a7966b]142        sout | 1 | sepOff | 2 | 3 | endl;                                       // locally turn off implicit separator
[53a6c2a]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
[d395012]145        sout | 1 | 2 | 3 | endl;
146        sout | endl;
[5a7966b]147
[53a6c2a]148        sout | "check enable/disable" | endl;
[5a7966b]149        sout | sepDisable | 1 | 2 | 3 | endl;                           // globally turn off implicit separation
150        sout | 1 | sepOn | 2 | 3 | endl;                                        // locally turn on implicit separator
[d395012]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;
[5a7966b]157
[53a6c2a]158//      sout | fmt( d, "%8.3f" ) || endl;
159//      sout | endl;
160
[5a7966b]161        sepSetTuple( sout, " " );                                                       // set tuple separator from ", " to " "
[53a6c2a]162        sout | t1 | t2 | " \"" | sep | "\"" | endl;
[5a7966b]163        sepSetTuple( sout, ", " );                                                      // reset tuple separator to ", "
[53a6c2a]164        sout | t1 | t2 | " \"" | sep | "\"" | endl;
[5a7966b]165        sout | t1 | t2 | endl;                                                          // print tuple
[d395012]166        sout | endl;
[829c907]167
[5a7966b]168        [int, int, const char *, double] t3 = { 3, 4, "a", 7.2 };
[cb91437]169        sout | [ 3, 4, "a", 7.2 ] | endl;
[5a7966b]170        sout | t3 | endl;
[829c907]171        sepSetTuple( sout, " " );
[5a7966b]172        sout | t3 | endl;
173        sout | sepOn | t3 | sepDisable | t3 | sepEnable | t3 | endl;
[829c907]174        sepSet( sout, "^" );
175        sepSetTuple( sout, "-" );
[5a7966b]176        sout | t3 | 3 | 4 | t3 | endl;
[53ba273]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.