cast 0.0.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,26 @@
1
- ###
2
- ### ##################################################################
3
- ###
4
- ### Parser routine tests. One test for each grammar rule.
5
- ###
6
- ### ##################################################################
7
- ###
1
+ ######################################################################
2
+ #
3
+ # Parser routine tests. One test for each grammar rule.
4
+ #
5
+ ######################################################################
8
6
 
9
- require 'common.rb'
7
+ require 'test_helper'
10
8
 
11
- class ParserTest < Test::Unit::TestCase
12
- include CheckAst
13
- def check s
14
- check_ast(s){|inp| C::Parser.new.parse(inp)}
9
+ class ParserTest < Minitest::Test
10
+ def check(s)
11
+ check_ast(s){|inp| @parser.parse(inp)}
12
+ end
13
+
14
+ def setup
15
+ @parser = C::Parser.new
16
+ end
17
+
18
+ def test_features
19
+ assert !@parser.block_expressions_enabled?
20
+ @parser.enable_block_expressions
21
+ assert @parser.block_expressions_enabled?
22
+ @parser.block_expressions_enabled = false
23
+ assert !@parser.block_expressions_enabled?
15
24
  end
16
25
 
17
26
  def test_comments
@@ -86,8 +95,8 @@ TranslationUnit
86
95
  - Declarator
87
96
  name: "i"
88
97
  EOS
89
- assert_raise(ParseError){C::Parser.new.parse("")}
90
- assert_raise(ParseError){C::Parser.new.parse(";")}
98
+ assert_raises(C::ParseError){C::Parser.new.parse("")}
99
+ assert_raises(C::ParseError){C::Parser.new.parse(";")}
91
100
  end
92
101
 
93
102
  def test_external_declaration
@@ -141,32 +150,32 @@ TranslationUnit
141
150
  name: "argv"
142
151
  name: "main"
143
152
  EOS
144
- ## non-function type
145
- assert_raise(ParseError){C::Parser.new.parse("int f {}")}
153
+ # non-function type
154
+ assert_raises(C::ParseError){C::Parser.new.parse("int f {}")}
146
155
 
147
- ## both prototype and declist
148
- assert_raise(ParseError){C::Parser.new.parse("void f(int argc, int argv) int argc, argv; {}")}
149
- assert_raise(ParseError){C::Parser.new.parse("void f(int argc, argv) int argv; {}")}
156
+ # both prototype and declist
157
+ assert_raises(C::ParseError){C::Parser.new.parse("void f(int argc, int argv) int argc, argv; {}")}
158
+ assert_raises(C::ParseError){C::Parser.new.parse("void f(int argc, argv) int argv; {}")}
150
159
 
151
- ## bad param name
152
- assert_raise(ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc; {}")}
153
- assert_raise(ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc, argv; {}")}
160
+ # bad param name
161
+ assert_raises(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc; {}")}
162
+ assert_raises(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc, argv; {}")}
154
163
 
155
- ## type missing
156
- assert_raise(ParseError){C::Parser.new.parse("void f(argc, argv) int argc; {}")}
164
+ # type missing
165
+ assert_raises(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argc; {}")}
157
166
 
158
- ## bad storage
159
- assert_raise(ParseError){C::Parser.new.parse("typedef void f(argc, argv) int argc; {}")}
160
- assert_raise(ParseError){C::Parser.new.parse("auto void f(argc, argv) int argc; {}")}
161
- assert_raise(ParseError){C::Parser.new.parse("register void f(argc, argv) int argc; {}")}
167
+ # bad storage
168
+ assert_raises(C::ParseError){C::Parser.new.parse("typedef void f(argc, argv) int argc; {}")}
169
+ assert_raises(C::ParseError){C::Parser.new.parse("auto void f(argc, argv) int argc; {}")}
170
+ assert_raises(C::ParseError){C::Parser.new.parse("register void f(argc, argv) int argc; {}")}
162
171
 
163
- ## duplicate storages
164
- assert_raise(ParseError){C::Parser.new.parse("static auto int i;")}
165
- assert_raise(ParseError){C::Parser.new.parse("static extern int i;")}
166
- assert_raise(ParseError){C::Parser.new.parse("typedef register int i;")}
172
+ # duplicate storages
173
+ assert_raises(C::ParseError){C::Parser.new.parse("static auto int i;")}
174
+ assert_raises(C::ParseError){C::Parser.new.parse("static extern int i;")}
175
+ assert_raises(C::ParseError){C::Parser.new.parse("typedef register int i;")}
167
176
 
168
- ## `inline' can be repeated
169
- assert_nothing_raised{C::Parser.new.parse("inline inline int i() {}")}
177
+ # `inline' can be repeated
178
+ C::Parser.new.parse("inline inline int i() {}") # no error
170
179
  end
171
180
 
172
181
  def test_declaration_list
@@ -836,13 +845,13 @@ TranslationUnit
836
845
  - Declarator
837
846
  name: "j"
838
847
  EOS
839
- ## duplicate storages
840
- assert_raise(ParseError){C::Parser.new.parse("static auto int ;")}
841
- assert_raise(ParseError){C::Parser.new.parse("static extern int i ;")}
842
- assert_raise(ParseError){C::Parser.new.parse("typedef register int i, j;")}
848
+ # duplicate storages
849
+ assert_raises(C::ParseError){C::Parser.new.parse("static auto int ;")}
850
+ assert_raises(C::ParseError){C::Parser.new.parse("static extern int i ;")}
851
+ assert_raises(C::ParseError){C::Parser.new.parse("typedef register int i, j;")}
843
852
 
844
- ## `inline' can be repeated
845
- assert_nothing_raised{C::Parser.new.parse("inline inline int f();")}
853
+ # `inline' can be repeated
854
+ C::Parser.new.parse("inline inline int f();") # no error
846
855
  end
847
856
 
848
857
  def test_declaration_specifiers
@@ -1153,16 +1162,16 @@ TranslationUnit
1153
1162
  type: CustomType
1154
1163
  name: "I"
1155
1164
  EOS
1156
- ## some illegal combos
1157
- assert_raise(ParseError){C::Parser.new.parse("int float;")}
1158
- assert_raise(ParseError){C::Parser.new.parse("struct s {} int;")}
1159
- assert_raise(ParseError){C::Parser.new.parse("_Complex;")}
1160
- assert_raise(ParseError){C::Parser.new.parse("_Complex _Imaginary float;")}
1161
- assert_raise(ParseError){C::Parser.new.parse("short long;")}
1162
- assert_raise(ParseError){C::Parser.new.parse("signed unsigned char;")}
1163
- assert_raise(ParseError){C::Parser.new.parse("int int;")}
1164
- assert_raise(ParseError){C::Parser.new.parse("long char;")}
1165
- assert_raise(ParseError){C::Parser.new.parse("long long long;")}
1165
+ # some illegal combos
1166
+ assert_raises(C::ParseError){C::Parser.new.parse("int float;")}
1167
+ assert_raises(C::ParseError){C::Parser.new.parse("struct s {} int;")}
1168
+ assert_raises(C::ParseError){C::Parser.new.parse("_Complex;")}
1169
+ assert_raises(C::ParseError){C::Parser.new.parse("_Complex _Imaginary float;")}
1170
+ assert_raises(C::ParseError){C::Parser.new.parse("short long;")}
1171
+ assert_raises(C::ParseError){C::Parser.new.parse("signed unsigned char;")}
1172
+ assert_raises(C::ParseError){C::Parser.new.parse("int int;")}
1173
+ assert_raises(C::ParseError){C::Parser.new.parse("long char;")}
1174
+ assert_raises(C::ParseError){C::Parser.new.parse("long long long;")}
1166
1175
  end
1167
1176
 
1168
1177
  def test_struct_or_union_specifier
@@ -1303,8 +1312,8 @@ TranslationUnit
1303
1312
  expr: Sizeof
1304
1313
  expr: Int (const)
1305
1314
  EOS
1306
- ## quals can be repeated
1307
- assert_nothing_raised{C::Parser.new.parse("void f() {sizeof(const const int);}")}
1315
+ # quals can be repeated
1316
+ C::Parser.new.parse("void f() {sizeof(const const int);}") # no error
1308
1317
  end
1309
1318
 
1310
1319
  def test_struct_declarator_list
@@ -1564,7 +1573,7 @@ EOS
1564
1573
  end
1565
1574
 
1566
1575
  def test_direct_declarator
1567
- ## TODO
1576
+ # TODO
1568
1577
  end
1569
1578
 
1570
1579
  def test_pointer
@@ -1820,7 +1829,7 @@ EOS
1820
1829
  end
1821
1830
 
1822
1831
  def test_direct_abstract_declarator
1823
- ## TODO
1832
+ # TODO
1824
1833
  end
1825
1834
 
1826
1835
  def test_typedef_name
@@ -2072,6 +2081,34 @@ TranslationUnit
2072
2081
  EOS
2073
2082
  end
2074
2083
 
2084
+ def test_primary_expression_block_expression
2085
+ src = <<EOS
2086
+ void f() {
2087
+ ({;});
2088
+ }
2089
+ EOS
2090
+ assert_raises(C::ParseError){@parser.parse(src)}
2091
+
2092
+ @parser.enable_block_expressions
2093
+ check <<EOS
2094
+ #{src}
2095
+ ----
2096
+ TranslationUnit
2097
+ entities:
2098
+ - FunctionDef
2099
+ type: Function
2100
+ type: Void
2101
+ name: "f"
2102
+ def: Block
2103
+ stmts:
2104
+ - ExpressionStatement
2105
+ expr: BlockExpression
2106
+ block: Block
2107
+ stmts:
2108
+ - ExpressionStatement
2109
+ EOS
2110
+ end
2111
+
2075
2112
  def test_postfix_expression
2076
2113
  check <<EOS
2077
2114
  void f() {
@@ -2152,11 +2189,12 @@ TranslationUnit
2152
2189
  EOS
2153
2190
  end
2154
2191
 
2155
- def test_argument_comma
2192
+ def test_argument_expression_list
2156
2193
  check <<EOS
2157
2194
  void f() {
2158
2195
  x(1);
2159
- x(1, 2);
2196
+ x(int);
2197
+ x(1, int);
2160
2198
  }
2161
2199
  ----
2162
2200
  TranslationUnit
@@ -2174,6 +2212,12 @@ TranslationUnit
2174
2212
  args:
2175
2213
  - IntLiteral
2176
2214
  val: 1
2215
+ - ExpressionStatement
2216
+ expr: Call
2217
+ expr: Variable
2218
+ name: "x"
2219
+ args:
2220
+ - Int
2177
2221
  - ExpressionStatement
2178
2222
  expr: Call
2179
2223
  expr: Variable
@@ -2181,8 +2225,51 @@ TranslationUnit
2181
2225
  args:
2182
2226
  - IntLiteral
2183
2227
  val: 1
2184
- - IntLiteral
2185
- val: 2
2228
+ - Int
2229
+ EOS
2230
+ end
2231
+
2232
+ def test_argument_expression
2233
+ check <<EOS
2234
+ void f() {
2235
+ x(a = 1);
2236
+ x(int*);
2237
+ x(const struct s[]);
2238
+ }
2239
+ ----
2240
+ TranslationUnit
2241
+ entities:
2242
+ - FunctionDef
2243
+ type: Function
2244
+ type: Void
2245
+ name: "f"
2246
+ def: Block
2247
+ stmts:
2248
+ - ExpressionStatement
2249
+ expr: Call
2250
+ expr: Variable
2251
+ name: "x"
2252
+ args:
2253
+ - Assign
2254
+ lval: Variable
2255
+ name: "a"
2256
+ rval: IntLiteral
2257
+ val: 1
2258
+ - ExpressionStatement
2259
+ expr: Call
2260
+ expr: Variable
2261
+ name: "x"
2262
+ args:
2263
+ - Pointer
2264
+ type: Int
2265
+ - ExpressionStatement
2266
+ expr: Call
2267
+ expr: Variable
2268
+ name: "x"
2269
+ args:
2270
+ - Array
2271
+ type: Struct (const)
2272
+ name: "s"
2186
2273
  EOS
2187
2274
  end
2188
2275
 
@@ -0,0 +1,85 @@
1
+ ######################################################################
2
+ #
3
+ # Tests for the preprocessor.
4
+ #
5
+ ######################################################################
6
+
7
+ require 'test_helper'
8
+
9
+ # publicize the private methods so we can test them easily
10
+ class C::Preprocessor
11
+ public :full_command
12
+ end
13
+ class PreprocessorTest < Minitest::Test
14
+ attr_accessor :cpp
15
+ def setup
16
+ @cpp = C::Preprocessor.new(quiet: true)
17
+ @cpp.include_path << 'dir1' << 'dir 2'
18
+ @cpp.macros['V'] = nil
19
+ @cpp.macros['I'] = 5
20
+ @cpp.macros['S'] = '"blah"'
21
+ @cpp.macros['SWAP(a,b)'] = 'a ^= b ^= a ^= b'
22
+ FileUtils.rm_rf(TEST_DIR)
23
+ FileUtils.mkdir_p(TEST_DIR)
24
+ end
25
+ def teardown
26
+ FileUtils.rm_rf(TEST_DIR)
27
+ end
28
+ def test_full_command
29
+ original_command = C::Preprocessor.command
30
+ C::Preprocessor.command = 'COMMAND'
31
+ assert_equal([
32
+ 'COMMAND',
33
+ '-Idir1', '-Idir 2',
34
+ '-DI=5', '-DS="blah"', '-DSWAP(a,b)=a ^= b ^= a ^= b', '-DV',
35
+ 'a file.c',
36
+ ], cpp.full_command('a file.c').shellsplit)
37
+ ensure
38
+ C::Preprocessor.command = original_command
39
+ end
40
+ def test_preprocess
41
+ output = cpp.preprocess("I S SWAP(x, y)")
42
+ assert_match(/5/, output)
43
+ assert_match(/"blah"/, output)
44
+ assert_match(/x \^= y \^= x \^= y/, output)
45
+ end
46
+ def test_preprocess_include
47
+ one_h = "#{TEST_DIR}/one.h"
48
+ two_h = "#{TEST_DIR}/foo/two.h"
49
+ File.open(one_h, 'w'){|f| f.puts "int one = 1;"}
50
+ FileUtils.mkdir(File.dirname(two_h))
51
+ File.open(two_h, 'w'){|f| f.puts "int two = 2;"}
52
+ output = nil
53
+ FileUtils.cd(TEST_DIR) do
54
+ output = cpp.preprocess(<<EOS)
55
+ #include "one.h"
56
+ #include "foo/two.h"
57
+ int three = 3;
58
+ EOS
59
+ end
60
+ assert_match(/int one = 1;/, output)
61
+ assert_match(/int two = 2;/, output)
62
+ assert_match(/int three = 3;/, output)
63
+ end
64
+ def test_preprocess_file
65
+ one_h = "#{TEST_DIR}/one.h"
66
+ two_h = "#{TEST_DIR}/foo/two.h"
67
+ main_c = "#{TEST_DIR}/main.c"
68
+ File.open(one_h, 'w'){|f| f.puts "int one = 1;"}
69
+ FileUtils.mkdir(File.dirname(two_h))
70
+ File.open(two_h, 'w'){|f| f.puts "int two = 2;"}
71
+ File.open(main_c, 'w'){|f| f.puts <<EOS}
72
+ #include "one.h"
73
+ #include "foo/two.h"
74
+ int three = 3;
75
+ EOS
76
+ output = cpp.preprocess_file(main_c)
77
+ assert_match(/int one = 1;/, output)
78
+ assert_match(/int two = 2;/, output)
79
+ assert_match(/int three = 3;/, output)
80
+ end
81
+ def test_proprocess_warning
82
+ output = cpp.preprocess("#warning warning!")
83
+ refute_match /warning!/, output
84
+ end
85
+ end
@@ -0,0 +1,2116 @@
1
+ ######################################################################
2
+ #
3
+ # Tests for the #render method of each Node.
4
+ #
5
+ ######################################################################
6
+
7
+ require 'test_helper'
8
+
9
+ class RenderTest < Minitest::Test
10
+ def setup
11
+ @parser = C::Parser.new
12
+ @parser.type_names << 'T'
13
+ end
14
+
15
+ #
16
+ # Parse the given string and check that it renders to the same
17
+ # string.
18
+ #
19
+ def check(klass, expected)
20
+ expected = expected.chomp.gsub(/^ *\|/, '')
21
+ node = klass.parse(expected, @parser)
22
+ assert_equal(expected, node.to_s)
23
+ end
24
+
25
+ # ------------------------------------------------------------------
26
+ # TranslationUnit
27
+ # ------------------------------------------------------------------
28
+
29
+ def test_translation_unit
30
+ check(C::TranslationUnit, <<-EOS)
31
+ |int i;
32
+ |
33
+ |int j;
34
+ |
35
+ |int f() {
36
+ |}
37
+ |
38
+ |int g() {
39
+ |}
40
+ EOS
41
+ end
42
+
43
+ # ------------------------------------------------------------------
44
+ # Declaration
45
+ # ------------------------------------------------------------------
46
+
47
+ def test_declaration
48
+ check(C::Declaration, <<-EOS)
49
+ |void f();
50
+ EOS
51
+ end
52
+ def test_declaration_with_specifier
53
+ check(C::Declaration, <<-EOS)
54
+ |inline void f();
55
+ EOS
56
+ end
57
+ def test_declaration_with_storage
58
+ check(C::Declaration, <<-EOS)
59
+ |static void f();
60
+ EOS
61
+ end
62
+ def test_declaration_static_with_all
63
+ check(C::Declaration, <<-EOS)
64
+ |inline static void f();
65
+ EOS
66
+ end
67
+
68
+ # ------------------------------------------------------------------
69
+ # Declarator
70
+ # ------------------------------------------------------------------
71
+
72
+ def test_declarator
73
+ check(C::Declarator, <<-EOS)
74
+ |i
75
+ EOS
76
+ end
77
+ def test_declarator_with_indirect_type
78
+ check(C::Declarator, <<-EOS)
79
+ |*i
80
+ EOS
81
+ end
82
+ def test_declarator_with_init
83
+ check(C::Declarator, <<-EOS)
84
+ |i = 1
85
+ EOS
86
+ end
87
+ def test_declarator_with_num_bits
88
+ check(C::Declarator, <<-EOS)
89
+ |i : 1
90
+ EOS
91
+ end
92
+
93
+ # ------------------------------------------------------------------
94
+ # FunctionDef
95
+ # ------------------------------------------------------------------
96
+
97
+ def test_function_def
98
+ check(C::FunctionDef, <<-EOS)
99
+ |void f() {
100
+ |}
101
+ EOS
102
+ end
103
+ def test_function_def_with_storage
104
+ check(C::FunctionDef, <<-EOS)
105
+ |static void f() {
106
+ |}
107
+ EOS
108
+ end
109
+ def test_function_def_with_inline
110
+ check(C::FunctionDef, <<-EOS)
111
+ |inline void f() {
112
+ |}
113
+ EOS
114
+ end
115
+ def test_function_def_with_no_prototype
116
+ check(C::FunctionDef, <<-EOS)
117
+ |static inline void f(i)
118
+ | int i;
119
+ |{
120
+ |}
121
+ EOS
122
+ end
123
+ def test_function_def_with_indirect_return_type
124
+ check(C::FunctionDef, <<-EOS)
125
+ |static inline void *f(int *i) {
126
+ |}
127
+ EOS
128
+ end
129
+ def test_function_def_with_all
130
+ check(C::FunctionDef, <<-EOS)
131
+ |static inline void *f(i)
132
+ | int *i;
133
+ |{
134
+ |}
135
+ EOS
136
+ end
137
+
138
+ # ------------------------------------------------------------------
139
+ # Parameter
140
+ # ------------------------------------------------------------------
141
+
142
+ def test_parameter
143
+ check(C::Parameter, <<-EOS)
144
+ |int i
145
+ EOS
146
+ end
147
+ def test_parameter_with_indirect_type
148
+ check(C::Parameter, <<-EOS)
149
+ |int i
150
+ EOS
151
+ end
152
+ def test_parameter_with_no_type
153
+ check(C::Parameter, <<-EOS)
154
+ |i
155
+ EOS
156
+ end
157
+ def test_parameter_with_no_name
158
+ check(C::Parameter, <<-EOS)
159
+ |int
160
+ EOS
161
+ end
162
+ def test_parameter_with_storage
163
+ check(C::Parameter, <<-EOS)
164
+ |register int
165
+ EOS
166
+ end
167
+
168
+ # ------------------------------------------------------------------
169
+ # Enumerator
170
+ # ------------------------------------------------------------------
171
+
172
+ def test_enumerator
173
+ check(C::Enumerator, <<-EOS)
174
+ |i
175
+ EOS
176
+ end
177
+ def test_enumerator_with_val
178
+ check(C::Enumerator, <<-EOS)
179
+ |i = 1
180
+ EOS
181
+ end
182
+
183
+ # ------------------------------------------------------------------
184
+ # Member
185
+ # ------------------------------------------------------------------
186
+
187
+ def test_member_init_member
188
+ check(C::MemberInit, <<-EOS)
189
+ |.foo = 1
190
+ EOS
191
+ end
192
+ def test_member_init_index
193
+ check(C::MemberInit, <<-EOS)
194
+ |[0] = 1
195
+ EOS
196
+ end
197
+ def test_member_init_multi
198
+ check(C::MemberInit, <<-EOS)
199
+ |.foo [0] = 1
200
+ EOS
201
+ end
202
+ def test_member
203
+ check(C::Member, <<-EOS)
204
+ |foo
205
+ EOS
206
+ end
207
+
208
+ # ------------------------------------------------------------------
209
+ # Block
210
+ # ------------------------------------------------------------------
211
+
212
+ # TODO: don't indent unlabelled statements, and have a block
213
+ # unindent labelled statements
214
+ def test_block_empty
215
+ check(C::Block, <<-EOS)
216
+ | {
217
+ | }
218
+ EOS
219
+ end
220
+ def test_block_with_statements
221
+ check(C::Block, <<-EOS)
222
+ | {
223
+ | ;
224
+ | }
225
+ EOS
226
+ end
227
+ def test_block_with_declarations
228
+ check(C::Block, <<-EOS)
229
+ | {
230
+ | int i;
231
+ | }
232
+ EOS
233
+ end
234
+ def test_block_with_labelled_statements
235
+ check(C::Block, <<-EOS)
236
+ | {
237
+ | one:
238
+ | ;
239
+ | }
240
+ EOS
241
+ end
242
+ def test_block_with_labelled_blocks
243
+ check(C::Block, <<-EOS)
244
+ | {
245
+ | one:
246
+ | {
247
+ | }
248
+ | }
249
+ EOS
250
+ end
251
+ def test_block_labelled
252
+ check(C::Block, <<-EOS)
253
+ |one:
254
+ |two:
255
+ | {
256
+ | }
257
+ EOS
258
+ end
259
+
260
+ # ------------------------------------------------------------------
261
+ # If
262
+ # ------------------------------------------------------------------
263
+
264
+ def test_if_then_with_statements
265
+ check(C::If, <<-EOS)
266
+ | if (cond)
267
+ | ;
268
+ EOS
269
+ end
270
+ def test_if_then_else_with_statements
271
+ check(C::If, <<-EOS)
272
+ | if (cond)
273
+ | ;
274
+ | else
275
+ | ;
276
+ EOS
277
+ end
278
+ def test_if_then_elsif_then_with_statements
279
+ # TODO: handle else-if towers
280
+ check(C::If, <<-EOS)
281
+ | if (cond)
282
+ | ;
283
+ | else
284
+ | if (cond)
285
+ | ;
286
+ | else
287
+ | ;
288
+ EOS
289
+ end
290
+ def test_if_with_labelled_statements
291
+ check(C::If, <<-EOS)
292
+ | if (cond)
293
+ | one:
294
+ | ;
295
+ | else
296
+ | if (cond)
297
+ | two:
298
+ | ;
299
+ | else
300
+ | three:
301
+ | ;
302
+ EOS
303
+ end
304
+ def test_if_then_with_blocks
305
+ check(C::If, <<-EOS)
306
+ | if (cond) {
307
+ | }
308
+ EOS
309
+ end
310
+ def test_if_then_else_with_blocks
311
+ check(C::If, <<-EOS)
312
+ | if (cond) {
313
+ | } else {
314
+ | }
315
+ EOS
316
+ end
317
+ def test_if_then_elsif_then_with_blocks
318
+ # TODO: handle else-if towers
319
+ check(C::If, <<-EOS)
320
+ | if (cond) {
321
+ | } else
322
+ | if (cond) {
323
+ | } else {
324
+ | }
325
+ EOS
326
+ end
327
+ def test_if_with_labelled_blocks
328
+ check(C::If, <<-EOS)
329
+ | if (cond)
330
+ | one:
331
+ | {
332
+ | }
333
+ | else
334
+ | if (cond)
335
+ | two:
336
+ | {
337
+ | }
338
+ | else
339
+ | three:
340
+ | {
341
+ | }
342
+ EOS
343
+ end
344
+ def test_if_labelled
345
+ check(C::If, <<-EOS)
346
+ |one:
347
+ |two:
348
+ | if (cond)
349
+ | ;
350
+ EOS
351
+ end
352
+
353
+ # ------------------------------------------------------------------
354
+ # Switch
355
+ # ------------------------------------------------------------------
356
+
357
+ def test_switch_with_statement
358
+ check(C::Switch, <<-EOS)
359
+ | switch (cond)
360
+ | ;
361
+ EOS
362
+ end
363
+ def test_switch_with_block
364
+ check(C::Switch, <<-EOS)
365
+ | switch (cond) {
366
+ | }
367
+ EOS
368
+ end
369
+ def test_switch_with_labelled_statement
370
+ check(C::Switch, <<-EOS)
371
+ | switch (cond)
372
+ | one:
373
+ | ;
374
+ EOS
375
+ end
376
+ def test_switch_with_labelled_block
377
+ check(C::Switch, <<-EOS)
378
+ | switch (cond)
379
+ | one:
380
+ | {
381
+ | }
382
+ EOS
383
+ end
384
+ def test_switch_labelled
385
+ check(C::Switch, <<-EOS)
386
+ |one:
387
+ |two:
388
+ | switch (cond) {
389
+ | }
390
+ EOS
391
+ end
392
+
393
+ # ------------------------------------------------------------------
394
+ # While
395
+ # ------------------------------------------------------------------
396
+
397
+ def test_while_with_statement
398
+ check(C::While, <<-EOS)
399
+ | while (cond)
400
+ | ;
401
+ EOS
402
+ end
403
+ def test_while_with_block
404
+ check(C::While, <<-EOS)
405
+ | while (cond) {
406
+ | }
407
+ EOS
408
+ end
409
+ def test_while_with_labelled_statement
410
+ check(C::While, <<-EOS)
411
+ | while (cond)
412
+ | one:
413
+ | ;
414
+ EOS
415
+ end
416
+ def test_while_with_labelled_block
417
+ check(C::While, <<-EOS)
418
+ | while (cond)
419
+ | one:
420
+ | {
421
+ | }
422
+ EOS
423
+ end
424
+ def test_while_labelled
425
+ check(C::While, <<-EOS)
426
+ |one:
427
+ | while (cond)
428
+ | ;
429
+ EOS
430
+ end
431
+ def test_do_while_with_statement
432
+ check(C::While, <<-EOS)
433
+ | do
434
+ | ;
435
+ | while (cond);
436
+ EOS
437
+ end
438
+ def test_do_while_with_block
439
+ check(C::While, <<-EOS)
440
+ | do {
441
+ | } while (cond);
442
+ EOS
443
+ end
444
+ def test_do_while_with_labelled_statement
445
+ check(C::While, <<-EOS)
446
+ | do
447
+ | one:
448
+ | ;
449
+ | while (cond);
450
+ EOS
451
+ end
452
+ def test_do_while_with_labelled_block
453
+ check(C::While, <<-EOS)
454
+ | do
455
+ | one:
456
+ | {
457
+ | }
458
+ | while (cond);
459
+ EOS
460
+ end
461
+ def test_do_while_labelled
462
+ check(C::While, <<-EOS)
463
+ |one:
464
+ | do
465
+ | ;
466
+ | while (cond);
467
+ EOS
468
+ end
469
+
470
+ # ------------------------------------------------------------------
471
+ # For
472
+ # ------------------------------------------------------------------
473
+
474
+ def test_for_with_no_header_elements
475
+ check(C::For, <<-EOS)
476
+ | for (;;)
477
+ | ;
478
+ EOS
479
+ end
480
+ def test_for_with_init_expression
481
+ check(C::For, <<-EOS)
482
+ | for (i = 0;;)
483
+ | ;
484
+ EOS
485
+ end
486
+ def test_for_with_init_declaration
487
+ check(C::For, <<-EOS)
488
+ | for (int i = 0;;)
489
+ | ;
490
+ EOS
491
+ end
492
+ def test_for_with_cond
493
+ check(C::For, <<-EOS)
494
+ | for (; i < 10;)
495
+ | ;
496
+ EOS
497
+ end
498
+ def test_for_with_iter
499
+ check(C::For, <<-EOS)
500
+ | for (;; ++i)
501
+ | ;
502
+ EOS
503
+ end
504
+ def test_for_with_all_header_elements
505
+ check(C::For, <<-EOS)
506
+ | for (i = 0; i < 10; ++i)
507
+ | ;
508
+ EOS
509
+ end
510
+ def test_for_with_block
511
+ check(C::For, <<-EOS)
512
+ | for (;;) {
513
+ | }
514
+ EOS
515
+ end
516
+ def test_for_with_labelled_statement
517
+ check(C::For, <<-EOS)
518
+ | for (;;)
519
+ | one:
520
+ | ;
521
+ EOS
522
+ end
523
+ def test_for_with_labelled_block
524
+ check(C::For, <<-EOS)
525
+ | for (;;)
526
+ | one:
527
+ | {
528
+ | }
529
+ EOS
530
+ end
531
+ def test_for_labelled
532
+ check(C::For, <<-EOS)
533
+ |one:
534
+ | for (;;)
535
+ | ;
536
+ EOS
537
+ end
538
+
539
+ # ------------------------------------------------------------------
540
+ # Goto
541
+ # ------------------------------------------------------------------
542
+
543
+ def test_goto
544
+ check(C::Goto, <<-EOS)
545
+ | goto one;
546
+ EOS
547
+ end
548
+ def test_goto_labelled
549
+ check(C::Goto, <<-EOS)
550
+ |one:
551
+ | goto two;
552
+ EOS
553
+ end
554
+
555
+ # ------------------------------------------------------------------
556
+ # Continue
557
+ # ------------------------------------------------------------------
558
+
559
+ def test_continue
560
+ check(C::Continue, <<-EOS)
561
+ | continue;
562
+ EOS
563
+ end
564
+ def test_continue_labelled
565
+ check(C::Continue, <<-EOS)
566
+ |one:
567
+ | continue;
568
+ EOS
569
+ end
570
+
571
+ # ------------------------------------------------------------------
572
+ # Break
573
+ # ------------------------------------------------------------------
574
+
575
+ def test_break
576
+ check(C::Break, <<-EOS)
577
+ | break;
578
+ EOS
579
+ end
580
+ def test_break_labelled
581
+ check(C::Break, <<-EOS)
582
+ |one:
583
+ | break;
584
+ EOS
585
+ end
586
+
587
+ # ------------------------------------------------------------------
588
+ # Return
589
+ # ------------------------------------------------------------------
590
+
591
+ def test_return_with_expression
592
+ check(C::Return, <<-EOS)
593
+ | return 0;
594
+ EOS
595
+ end
596
+ def test_return_with_no_expression
597
+ check(C::Return, <<-EOS)
598
+ | return;
599
+ EOS
600
+ end
601
+ def test_return_labelled
602
+ check(C::Return, <<-EOS)
603
+ |one:
604
+ | return 0;
605
+ EOS
606
+ end
607
+
608
+ # ------------------------------------------------------------------
609
+ # ExpressionStatement
610
+ # ------------------------------------------------------------------
611
+
612
+ def test_expression_statement
613
+ check(C::ExpressionStatement, <<-EOS)
614
+ | ;
615
+ EOS
616
+ end
617
+ def test_expression_statement_with_expression
618
+ check(C::ExpressionStatement, <<-EOS)
619
+ | 1;
620
+ EOS
621
+ end
622
+ def test_expression_statement_labelled
623
+ check(C::ExpressionStatement, <<-EOS)
624
+ |one:
625
+ | 1;
626
+ EOS
627
+ end
628
+
629
+ # ------------------------------------------------------------------
630
+ # PlainLabel
631
+ # ------------------------------------------------------------------
632
+
633
+ def test_plain_label
634
+ check(C::PlainLabel, <<-EOS)
635
+ |one:
636
+ EOS
637
+ end
638
+
639
+ # ------------------------------------------------------------------
640
+ # Default
641
+ # ------------------------------------------------------------------
642
+
643
+ def test_default
644
+ check(C::Default, <<-EOS)
645
+ |default:
646
+ EOS
647
+ end
648
+
649
+ # ------------------------------------------------------------------
650
+ # TestCase
651
+ # ------------------------------------------------------------------
652
+
653
+ def test_case
654
+ check(C::Case, <<-EOS)
655
+ |case 1:
656
+ EOS
657
+ end
658
+
659
+ # ------------------------------------------------------------------
660
+ # Comma
661
+ # ------------------------------------------------------------------
662
+
663
+ def test_comma_two_expressions
664
+ check(C::Comma, <<-EOS)
665
+ |1, 2
666
+ EOS
667
+ end
668
+ def test_comma_three_expressions
669
+ check(C::Comma, <<-EOS)
670
+ |1, 2, 3
671
+ EOS
672
+ end
673
+
674
+ # ------------------------------------------------------------------
675
+ # Conditional
676
+ # ------------------------------------------------------------------
677
+
678
+ def test_conditional
679
+ check(C::Conditional, <<-EOS)
680
+ |a ? b : c
681
+ EOS
682
+ end
683
+ def test_conditional_precedences
684
+ check(C::Or, <<-EOS)
685
+ |a || (b ? c || d : e && f)
686
+ EOS
687
+ end
688
+ def test_conditional_nested
689
+ # TODO: handle else-if towers
690
+ check(C::Conditional, <<-EOS)
691
+ |(a ? b : c) ? (d ? e : f) : (g ? h : i)
692
+ EOS
693
+ end
694
+
695
+ # ------------------------------------------------------------------
696
+ # Variable
697
+ # ------------------------------------------------------------------
698
+
699
+ def test_variable
700
+ check(C::Variable, <<-EOS)
701
+ |x
702
+ EOS
703
+ end
704
+
705
+ # ------------------------------------------------------------------
706
+ # BlockExpression
707
+ # ------------------------------------------------------------------
708
+
709
+ def test_block_expression
710
+ @parser.enable_block_expressions
711
+ check(C::BlockExpression, <<-EOS)
712
+ |({
713
+ | ;
714
+ |})
715
+ EOS
716
+ end
717
+
718
+ # ------------------------------------------------------------------
719
+ # Index
720
+ # ------------------------------------------------------------------
721
+
722
+ def test_index
723
+ check(C::Index, <<-EOS)
724
+ |a[0]
725
+ EOS
726
+ end
727
+ def test_index_precedences
728
+ check(C::Index, <<-EOS)
729
+ |(*a)[*a]
730
+ EOS
731
+ end
732
+ def test_index_nested
733
+ check(C::Index, <<-EOS)
734
+ |a[a[0]][0]
735
+ EOS
736
+ end
737
+
738
+ # ------------------------------------------------------------------
739
+ # Call
740
+ # ------------------------------------------------------------------
741
+
742
+ def test_call
743
+ check(C::Call, <<-EOS)
744
+ |a()
745
+ EOS
746
+ end
747
+ def test_call_with_args
748
+ check(C::Call, <<-EOS)
749
+ |a(1, (2, 3))
750
+ EOS
751
+ end
752
+ def test_call_precedences
753
+ check(C::Call, <<-EOS)
754
+ |(*a)(*a)
755
+ EOS
756
+ end
757
+ def test_call_nested
758
+ check(C::Call, <<-EOS)
759
+ |(*a())(a())
760
+ EOS
761
+ end
762
+
763
+ # ------------------------------------------------------------------
764
+ # Dot
765
+ # ------------------------------------------------------------------
766
+
767
+ def test_dot
768
+ check(C::Dot, <<-EOS)
769
+ |a.b
770
+ EOS
771
+ end
772
+ def test_dot_precendences
773
+ check(C::Dot, <<-EOS)
774
+ |(a ? b : c).d
775
+ EOS
776
+ end
777
+ def test_dot_nested
778
+ check(C::Dot, <<-EOS)
779
+ |a.b.c
780
+ EOS
781
+ end
782
+
783
+ # ------------------------------------------------------------------
784
+ # Arrow
785
+ # ------------------------------------------------------------------
786
+
787
+ def test_arrow
788
+ check(C::Arrow, <<-EOS)
789
+ |a->b
790
+ EOS
791
+ end
792
+ def test_arrow_precedences
793
+ check(C::Arrow, <<-EOS)
794
+ |(a ? b : c)->d
795
+ EOS
796
+ end
797
+ def test_arrow_nested
798
+ check(C::Arrow, <<-EOS)
799
+ |a->b->c
800
+ EOS
801
+ end
802
+
803
+ # ------------------------------------------------------------------
804
+ # PostInc
805
+ # ------------------------------------------------------------------
806
+
807
+ def test_post_inc
808
+ check(C::PostInc, <<-EOS)
809
+ |a++
810
+ EOS
811
+ end
812
+ def test_post_inc_precedences
813
+ check(C::PostInc, <<-EOS)
814
+ |(a++ ? b++ : c++)++
815
+ EOS
816
+ end
817
+ def test_post_inc_nested
818
+ check(C::PostInc, <<-EOS)
819
+ |a++++
820
+ EOS
821
+ end
822
+
823
+ # ------------------------------------------------------------------
824
+ # PostDec
825
+ # ------------------------------------------------------------------
826
+
827
+ def test_post_dec
828
+ check(C::PostDec, <<-EOS)
829
+ |a--
830
+ EOS
831
+ end
832
+ def test_post_dec_precedences
833
+ check(C::PostDec, <<-EOS)
834
+ |(a-- ? b-- : c--)--
835
+ EOS
836
+ end
837
+ def test_post_dec_nested
838
+ check(C::PostDec, <<-EOS)
839
+ |a----
840
+ EOS
841
+ end
842
+
843
+ # ------------------------------------------------------------------
844
+ # Cast
845
+ # ------------------------------------------------------------------
846
+
847
+ def test_cast
848
+ check(C::Cast, <<-EOS)
849
+ |(int)a
850
+ EOS
851
+ end
852
+ def test_cast_precedences
853
+ check(C::Cast, <<-EOS)
854
+ |(int)((int)a + (int)b)
855
+ EOS
856
+ end
857
+ def test_cast_nested
858
+ check(C::Cast, <<-EOS)
859
+ |(int)(int)a
860
+ EOS
861
+ end
862
+
863
+ # ------------------------------------------------------------------
864
+ # Address
865
+ # ------------------------------------------------------------------
866
+
867
+ def test_address
868
+ check(C::Address, <<-EOS)
869
+ |&a
870
+ EOS
871
+ end
872
+ def test_address_precedences
873
+ check(C::Address, <<-EOS)
874
+ |&(a + 1)
875
+ EOS
876
+ end
877
+ def test_address_nested
878
+ check(C::Address, <<-EOS)
879
+ |& &a
880
+ EOS
881
+ end
882
+
883
+ # ------------------------------------------------------------------
884
+ # Dereference
885
+ # ------------------------------------------------------------------
886
+
887
+ def test_dereference
888
+ check(C::Dereference, <<-EOS)
889
+ |*a
890
+ EOS
891
+ end
892
+ def test_dereference_precedences
893
+ check(C::Dereference, <<-EOS)
894
+ |*(a + 1)
895
+ EOS
896
+ end
897
+ def test_dereference_nested
898
+ check(C::Dereference, <<-EOS)
899
+ |**a
900
+ EOS
901
+ end
902
+
903
+ # ------------------------------------------------------------------
904
+ # Sizeof
905
+ # ------------------------------------------------------------------
906
+
907
+ def test_sizeof
908
+ check(C::Sizeof, <<-EOS)
909
+ |sizeof(a)
910
+ EOS
911
+ end
912
+ def test_sizeof_precedences
913
+ check(C::Index, <<-EOS)
914
+ |(sizeof(a + 1))[b]
915
+ EOS
916
+ end
917
+ def test_sizeof_nested
918
+ check(C::Sizeof, <<-EOS)
919
+ |sizeof(sizeof(a))
920
+ EOS
921
+ end
922
+
923
+ # ------------------------------------------------------------------
924
+ # Positive
925
+ # ------------------------------------------------------------------
926
+
927
+ def test_positive
928
+ check(C::Positive, <<-EOS)
929
+ |+a
930
+ EOS
931
+ end
932
+ def test_positive_precedences
933
+ check(C::Add, <<-EOS)
934
+ |a + +(+a + +b)
935
+ EOS
936
+ end
937
+ def test_positive_nested
938
+ check(C::Positive, <<-EOS)
939
+ |+ +a
940
+ EOS
941
+ end
942
+
943
+ # ------------------------------------------------------------------
944
+ # Negative
945
+ # ------------------------------------------------------------------
946
+
947
+ def test_negative
948
+ check(C::Negative, <<-EOS)
949
+ |-a
950
+ EOS
951
+ end
952
+ def test_negative_precedences
953
+ check(C::Subtract, <<-EOS)
954
+ |a - -(-a - -b)
955
+ EOS
956
+ end
957
+ def test_negative_nested
958
+ check(C::Negative, <<-EOS)
959
+ |- -a
960
+ EOS
961
+ end
962
+
963
+ # ------------------------------------------------------------------
964
+ # PreInc
965
+ # ------------------------------------------------------------------
966
+
967
+ def test_pre_inc
968
+ check(C::PreInc, <<-EOS)
969
+ |++a
970
+ EOS
971
+ end
972
+ def test_pre_inc_precedences
973
+ check(C::Add, <<-EOS)
974
+ |++a + ++(++b + ++c)
975
+ EOS
976
+ end
977
+ def test_pre_inc_nested
978
+ check(C::PreInc, <<-EOS)
979
+ |++++a
980
+ EOS
981
+ end
982
+
983
+ # ------------------------------------------------------------------
984
+ # PreDec
985
+ # ------------------------------------------------------------------
986
+
987
+ def test_pre_dec
988
+ check(C::PreDec, <<-EOS)
989
+ |--a
990
+ EOS
991
+ end
992
+ def test_pre_dec_precedences
993
+ check(C::Subtract, <<-EOS)
994
+ |--a - --(--b - --c)
995
+ EOS
996
+ end
997
+ def test_pre_dec_nested
998
+ check(C::PreDec, <<-EOS)
999
+ |----a
1000
+ EOS
1001
+ end
1002
+
1003
+ # ------------------------------------------------------------------
1004
+ # BitNot
1005
+ # ------------------------------------------------------------------
1006
+
1007
+ def test_bit_not
1008
+ check(C::BitNot, <<-EOS)
1009
+ |~a
1010
+ EOS
1011
+ end
1012
+ def test_bit_not_precedences
1013
+ check(C::Equal, <<-EOS)
1014
+ |~a == (~b | ~c)
1015
+ EOS
1016
+ end
1017
+ def test_bit_not_nested
1018
+ check(C::BitNot, <<-EOS)
1019
+ |~~a
1020
+ EOS
1021
+ end
1022
+
1023
+ # ------------------------------------------------------------------
1024
+ # Not
1025
+ # ------------------------------------------------------------------
1026
+
1027
+ def test_not
1028
+ check(C::Not, <<-EOS)
1029
+ |!a
1030
+ EOS
1031
+ end
1032
+ def test_not_precedences
1033
+ check(C::Equal, <<-EOS)
1034
+ |!a == !(!b || !c)
1035
+ EOS
1036
+ end
1037
+ def test_not_nested
1038
+ check(C::Not, <<-EOS)
1039
+ |!!a
1040
+ EOS
1041
+ end
1042
+
1043
+ # ------------------------------------------------------------------
1044
+ # Add
1045
+ # ------------------------------------------------------------------
1046
+
1047
+ def test_add
1048
+ check(C::Add, <<-EOS)
1049
+ |a + b
1050
+ EOS
1051
+ end
1052
+ def test_add_precedences
1053
+ check(C::Add, <<-EOS)
1054
+ |a * b + (c == d)
1055
+ EOS
1056
+ end
1057
+ def test_add_nested
1058
+ check(C::Add, <<-EOS)
1059
+ |a + b + (c + d)
1060
+ EOS
1061
+ end
1062
+
1063
+ # ------------------------------------------------------------------
1064
+ # Subtract
1065
+ # ------------------------------------------------------------------
1066
+
1067
+ def test_subtract
1068
+ check(C::Subtract, <<-EOS)
1069
+ |a - b
1070
+ EOS
1071
+ end
1072
+ def test_subtract_precedences
1073
+ check(C::Subtract, <<-EOS)
1074
+ |a * b - (c == d)
1075
+ EOS
1076
+ end
1077
+ def test_subtract_nested
1078
+ check(C::Subtract, <<-EOS)
1079
+ |a - b - (c - d)
1080
+ EOS
1081
+ end
1082
+
1083
+ # ------------------------------------------------------------------
1084
+ # Multiply
1085
+ # ------------------------------------------------------------------
1086
+
1087
+ def test_multiply
1088
+ check(C::Multiply, <<-EOS)
1089
+ |a * b
1090
+ EOS
1091
+ end
1092
+ def test_multiply_precedences
1093
+ check(C::Multiply, <<-EOS)
1094
+ |*a * (b + c)
1095
+ EOS
1096
+ end
1097
+ def test_multiply_nested
1098
+ check(C::Multiply, <<-EOS)
1099
+ |a * b * (c * d)
1100
+ EOS
1101
+ end
1102
+
1103
+ # ------------------------------------------------------------------
1104
+ # Divide
1105
+ # ------------------------------------------------------------------
1106
+
1107
+ def test_divide
1108
+ check(C::Divide, <<-EOS)
1109
+ |a / b
1110
+ EOS
1111
+ end
1112
+ def test_divide_precedences
1113
+ check(C::Divide, <<-EOS)
1114
+ |*a / (b + c)
1115
+ EOS
1116
+ end
1117
+ def test_divide_nested
1118
+ check(C::Divide, <<-EOS)
1119
+ |a / b / (c / d)
1120
+ EOS
1121
+ end
1122
+
1123
+ # ------------------------------------------------------------------
1124
+ # Mod
1125
+ # ------------------------------------------------------------------
1126
+
1127
+ def test_mod
1128
+ check(C::Mod, <<-EOS)
1129
+ |a % b
1130
+ EOS
1131
+ end
1132
+ def test_mod_precedences
1133
+ check(C::Mod, <<-EOS)
1134
+ |*a % (b + c)
1135
+ EOS
1136
+ end
1137
+ def test_mod_nested
1138
+ check(C::Mod, <<-EOS)
1139
+ |a % b % (c % d)
1140
+ EOS
1141
+ end
1142
+
1143
+ # ------------------------------------------------------------------
1144
+ # Equal
1145
+ # ------------------------------------------------------------------
1146
+
1147
+ def test_equal
1148
+ check(C::Equal, <<-EOS)
1149
+ |a == b
1150
+ EOS
1151
+ end
1152
+ def test_equal_precedences
1153
+ check(C::Equal, <<-EOS)
1154
+ |a + b == (c ? d : e)
1155
+ EOS
1156
+ end
1157
+ def test_equal_nested
1158
+ check(C::Equal, <<-EOS)
1159
+ |a == b == (c == d)
1160
+ EOS
1161
+ end
1162
+
1163
+ # ------------------------------------------------------------------
1164
+ # NotEqual
1165
+ # ------------------------------------------------------------------
1166
+
1167
+ def test_not_equal
1168
+ check(C::NotEqual, <<-EOS)
1169
+ |a != b
1170
+ EOS
1171
+ end
1172
+ def test_not_equal_precedences
1173
+ check(C::NotEqual, <<-EOS)
1174
+ |a + b != (c ? d : e)
1175
+ EOS
1176
+ end
1177
+ def test_not_equal_nested
1178
+ check(C::NotEqual, <<-EOS)
1179
+ |a != b != (c != d)
1180
+ EOS
1181
+ end
1182
+
1183
+ # ------------------------------------------------------------------
1184
+ # Less
1185
+ # ------------------------------------------------------------------
1186
+
1187
+ def test_less
1188
+ check(C::Less, <<-EOS)
1189
+ |a < b
1190
+ EOS
1191
+ end
1192
+ def test_less_precedences
1193
+ check(C::Less, <<-EOS)
1194
+ |a + b < (c ? d : e)
1195
+ EOS
1196
+ end
1197
+ def test_less_nested
1198
+ check(C::Less, <<-EOS)
1199
+ |a < b < (c < d)
1200
+ EOS
1201
+ end
1202
+
1203
+ # ------------------------------------------------------------------
1204
+ # More
1205
+ # ------------------------------------------------------------------
1206
+
1207
+ def test_more
1208
+ check(C::More, <<-EOS)
1209
+ |a > b
1210
+ EOS
1211
+ end
1212
+ def test_more_precedences
1213
+ check(C::More, <<-EOS)
1214
+ |a + b > (c ? d : e)
1215
+ EOS
1216
+ end
1217
+ def test_more_nested
1218
+ check(C::More, <<-EOS)
1219
+ |a > b > (c > d)
1220
+ EOS
1221
+ end
1222
+
1223
+ # ------------------------------------------------------------------
1224
+ # LessOrEqual
1225
+ # ------------------------------------------------------------------
1226
+
1227
+ def test_less_or_equal
1228
+ check(C::LessOrEqual, <<-EOS)
1229
+ |a <= b
1230
+ EOS
1231
+ end
1232
+ def test_less_or_equal_precedences
1233
+ check(C::LessOrEqual, <<-EOS)
1234
+ |a + b <= (c ? d : e)
1235
+ EOS
1236
+ end
1237
+ def test_less_or_equal_nested
1238
+ check(C::LessOrEqual, <<-EOS)
1239
+ |a <= b <= (c <= d)
1240
+ EOS
1241
+ end
1242
+
1243
+ # ------------------------------------------------------------------
1244
+ # MoreOrEqual
1245
+ # ------------------------------------------------------------------
1246
+
1247
+ def test_more_or_equal
1248
+ check(C::MoreOrEqual, <<-EOS)
1249
+ |a >= b
1250
+ EOS
1251
+ end
1252
+ def test_more_or_equal_precedences
1253
+ check(C::MoreOrEqual, <<-EOS)
1254
+ |a + b >= (c ? d : e)
1255
+ EOS
1256
+ end
1257
+ def test_more_or_equal_nested
1258
+ check(C::MoreOrEqual, <<-EOS)
1259
+ |a >= b >= (c >= d)
1260
+ EOS
1261
+ end
1262
+
1263
+ # ------------------------------------------------------------------
1264
+ # BitAnd
1265
+ # ------------------------------------------------------------------
1266
+
1267
+ def test_bit_and
1268
+ check(C::BitAnd, <<-EOS)
1269
+ |a & b
1270
+ EOS
1271
+ end
1272
+ def test_bit_and_precedences
1273
+ check(C::BitAnd, <<-EOS)
1274
+ |a + b & (c ? d : e)
1275
+ EOS
1276
+ end
1277
+ def test_bit_and_nested
1278
+ check(C::BitAnd, <<-EOS)
1279
+ |a & b & (c & d)
1280
+ EOS
1281
+ end
1282
+
1283
+ # ------------------------------------------------------------------
1284
+ # BitOr
1285
+ # ------------------------------------------------------------------
1286
+
1287
+ def test_bit_or
1288
+ check(C::BitOr, <<-EOS)
1289
+ |a | b
1290
+ EOS
1291
+ end
1292
+ def test_bit_or_precedences
1293
+ check(C::BitOr, <<-EOS)
1294
+ |a + b | (c ? d : e)
1295
+ EOS
1296
+ end
1297
+ def test_bit_or_nested
1298
+ check(C::BitOr, <<-EOS)
1299
+ |a | b | (c | d)
1300
+ EOS
1301
+ end
1302
+
1303
+ # ------------------------------------------------------------------
1304
+ # BitXor
1305
+ # ------------------------------------------------------------------
1306
+
1307
+ def test_bit_xor
1308
+ check(C::BitXor, <<-EOS)
1309
+ |a ^ b
1310
+ EOS
1311
+ end
1312
+ def test_bit_xor_precedences
1313
+ check(C::BitXor, <<-EOS)
1314
+ |a + b ^ (c ? d : e)
1315
+ EOS
1316
+ end
1317
+ def test_bit_xor_nested
1318
+ check(C::BitXor, <<-EOS)
1319
+ |a ^ b ^ (c ^ d)
1320
+ EOS
1321
+ end
1322
+
1323
+ # ------------------------------------------------------------------
1324
+ # ShiftLeft
1325
+ # ------------------------------------------------------------------
1326
+
1327
+ def test_shift_left
1328
+ check(C::ShiftLeft, <<-EOS)
1329
+ |a << b
1330
+ EOS
1331
+ end
1332
+ def test_shift_left_precedences
1333
+ check(C::ShiftLeft, <<-EOS)
1334
+ |a + b << (c ? d : e)
1335
+ EOS
1336
+ end
1337
+ def test_shift_left_nested
1338
+ check(C::ShiftLeft, <<-EOS)
1339
+ |a << b << (c << d)
1340
+ EOS
1341
+ end
1342
+
1343
+ # ------------------------------------------------------------------
1344
+ # ShiftRight
1345
+ # ------------------------------------------------------------------
1346
+
1347
+ def test_shift_right
1348
+ check(C::ShiftRight, <<-EOS)
1349
+ |a >> b
1350
+ EOS
1351
+ end
1352
+ def test_shift_right_precedences
1353
+ check(C::ShiftRight, <<-EOS)
1354
+ |a + b >> (c ? d : e)
1355
+ EOS
1356
+ end
1357
+ def test_shift_right_nested
1358
+ check(C::ShiftRight, <<-EOS)
1359
+ |a >> b >> (c >> d)
1360
+ EOS
1361
+ end
1362
+
1363
+ # ------------------------------------------------------------------
1364
+ # And
1365
+ # ------------------------------------------------------------------
1366
+
1367
+ def test_and
1368
+ check(C::And, <<-EOS)
1369
+ |a && b
1370
+ EOS
1371
+ end
1372
+ def test_and_precedences
1373
+ check(C::And, <<-EOS)
1374
+ |a + b && (c ? d : e)
1375
+ EOS
1376
+ end
1377
+ def test_and_nested
1378
+ check(C::And, <<-EOS)
1379
+ |a && b && (c && d)
1380
+ EOS
1381
+ end
1382
+
1383
+ # ------------------------------------------------------------------
1384
+ # Or
1385
+ # ------------------------------------------------------------------
1386
+
1387
+ def test_or
1388
+ check(C::Or, <<-EOS)
1389
+ |a || b
1390
+ EOS
1391
+ end
1392
+ def test_or_precedences
1393
+ check(C::Or, <<-EOS)
1394
+ |a + b || (c ? d : e)
1395
+ EOS
1396
+ end
1397
+ def test_or_nested
1398
+ check(C::Or, <<-EOS)
1399
+ |a || b || (c || d)
1400
+ EOS
1401
+ end
1402
+
1403
+ # ------------------------------------------------------------------
1404
+ # Assign
1405
+ # ------------------------------------------------------------------
1406
+
1407
+ def test_assign
1408
+ check(C::Assign, <<-EOS)
1409
+ |a = b
1410
+ EOS
1411
+ end
1412
+ def test_assign_precedences
1413
+ check(C::Assign, <<-EOS)
1414
+ |a = b ? c : d
1415
+ EOS
1416
+ end
1417
+ def test_assign_nested
1418
+ check(C::Assign, <<-EOS)
1419
+ |a = b = (c, d)
1420
+ EOS
1421
+ end
1422
+
1423
+ # ------------------------------------------------------------------
1424
+ # MultiplyAssign
1425
+ # ------------------------------------------------------------------
1426
+
1427
+ def test_multiply_assign
1428
+ check(C::MultiplyAssign, <<-EOS)
1429
+ |a *= b
1430
+ EOS
1431
+ end
1432
+ def test_multiply_assign_precedences
1433
+ check(C::MultiplyAssign, <<-EOS)
1434
+ |a *= b ? c : d
1435
+ EOS
1436
+ end
1437
+ def test_multiply_assign_nested
1438
+ check(C::MultiplyAssign, <<-EOS)
1439
+ |a *= b *= (c, d)
1440
+ EOS
1441
+ end
1442
+
1443
+ # ------------------------------------------------------------------
1444
+ # DivideAssign
1445
+ # ------------------------------------------------------------------
1446
+
1447
+ def test_divide_assign
1448
+ check(C::DivideAssign, <<-EOS)
1449
+ |a /= b
1450
+ EOS
1451
+ end
1452
+ def test_divide_assign_precedences
1453
+ check(C::DivideAssign, <<-EOS)
1454
+ |a /= b ? c : d
1455
+ EOS
1456
+ end
1457
+ def test_divide_assign_nested
1458
+ check(C::DivideAssign, <<-EOS)
1459
+ |a /= b /= c
1460
+ EOS
1461
+ end
1462
+
1463
+ # ------------------------------------------------------------------
1464
+ # ModAssign
1465
+ # ------------------------------------------------------------------
1466
+
1467
+ def test_mod_assign
1468
+ check(C::ModAssign, <<-EOS)
1469
+ |a %= b
1470
+ EOS
1471
+ end
1472
+ def test_mod_assign_precedences
1473
+ check(C::ModAssign, <<-EOS)
1474
+ |a %= b ? c : d
1475
+ EOS
1476
+ end
1477
+ def test_mod_assign_nested
1478
+ check(C::ModAssign, <<-EOS)
1479
+ |a %= b %= (c, d)
1480
+ EOS
1481
+ end
1482
+
1483
+ # ------------------------------------------------------------------
1484
+ # AddAssign
1485
+ # ------------------------------------------------------------------
1486
+
1487
+ def test_add_assign
1488
+ check(C::AddAssign, <<-EOS)
1489
+ |a += b
1490
+ EOS
1491
+ end
1492
+ def test_add_assign_precedences
1493
+ check(C::AddAssign, <<-EOS)
1494
+ |a += b ? c : d
1495
+ EOS
1496
+ end
1497
+ def test_add_assign_nested
1498
+ check(C::AddAssign, <<-EOS)
1499
+ |a += b += (c, d)
1500
+ EOS
1501
+ end
1502
+
1503
+ # ------------------------------------------------------------------
1504
+ # SubtractAssign
1505
+ # ------------------------------------------------------------------
1506
+
1507
+ def test_subtract_assign
1508
+ check(C::SubtractAssign, <<-EOS)
1509
+ |a -= b
1510
+ EOS
1511
+ end
1512
+ def test_subtract_assign_precedences
1513
+ check(C::SubtractAssign, <<-EOS)
1514
+ |a -= b ? c : d
1515
+ EOS
1516
+ end
1517
+ def test_subtract_assign_nested
1518
+ check(C::SubtractAssign, <<-EOS)
1519
+ |a -= b -= (c, d)
1520
+ EOS
1521
+ end
1522
+
1523
+ # ------------------------------------------------------------------
1524
+ # ShiftLeftAssign
1525
+ # ------------------------------------------------------------------
1526
+
1527
+ def test_shift_left_assign
1528
+ check(C::ShiftLeftAssign, <<-EOS)
1529
+ |a <<= b
1530
+ EOS
1531
+ end
1532
+ def test_shift_left_assign_precedences
1533
+ check(C::ShiftLeftAssign, <<-EOS)
1534
+ |a <<= b ? c : d
1535
+ EOS
1536
+ end
1537
+ def test_shift_left_assign_nested
1538
+ check(C::ShiftLeftAssign, <<-EOS)
1539
+ |a <<= b <<= (c, d)
1540
+ EOS
1541
+ end
1542
+
1543
+ # ------------------------------------------------------------------
1544
+ # ShiftRightAssign
1545
+ # ------------------------------------------------------------------
1546
+
1547
+ def test_shift_right_assign
1548
+ check(C::ShiftRightAssign, <<-EOS)
1549
+ |a >>= b
1550
+ EOS
1551
+ end
1552
+ def test_shift_right_assign_precedences
1553
+ check(C::ShiftRightAssign, <<-EOS)
1554
+ |a >>= b ? c : d
1555
+ EOS
1556
+ end
1557
+ def test_shift_right_assign_nested
1558
+ check(C::ShiftRightAssign, <<-EOS)
1559
+ |a >>= b >>= (c, d)
1560
+ EOS
1561
+ end
1562
+
1563
+ # ------------------------------------------------------------------
1564
+ # BitAndAssign
1565
+ # ------------------------------------------------------------------
1566
+
1567
+ def test_bit_and_assign
1568
+ check(C::BitAndAssign, <<-EOS)
1569
+ |a &= b
1570
+ EOS
1571
+ end
1572
+ def test_bit_and_assign_precedences
1573
+ check(C::BitAndAssign, <<-EOS)
1574
+ |a &= b ? c : d
1575
+ EOS
1576
+ end
1577
+ def test_bit_and_assign_nested
1578
+ check(C::BitAndAssign, <<-EOS)
1579
+ |a &= b &= (c, d)
1580
+ EOS
1581
+ end
1582
+
1583
+ # ------------------------------------------------------------------
1584
+ # BitXorAssign
1585
+ # ------------------------------------------------------------------
1586
+
1587
+ def test_bit_xor_assign
1588
+ check(C::BitXorAssign, <<-EOS)
1589
+ |a ^= b
1590
+ EOS
1591
+ end
1592
+ def test_bit_xor_assign_precedences
1593
+ check(C::BitXorAssign, <<-EOS)
1594
+ |a ^= b ? c : d
1595
+ EOS
1596
+ end
1597
+ def test_bit_xor_assign_nested
1598
+ check(C::BitXorAssign, <<-EOS)
1599
+ |a ^= b ^= (c, d)
1600
+ EOS
1601
+ end
1602
+
1603
+ # ------------------------------------------------------------------
1604
+ # BitOrAssign
1605
+ # ------------------------------------------------------------------
1606
+
1607
+ def test_bit_or_assign
1608
+ check(C::BitOrAssign, <<-EOS)
1609
+ |a |= b
1610
+ EOS
1611
+ end
1612
+ def test_bit_or_assign_precedences
1613
+ check(C::BitOrAssign, <<-EOS)
1614
+ |a |= b ? c : d
1615
+ EOS
1616
+ end
1617
+ def test_bit_or_assign_nested
1618
+ check(C::BitOrAssign, <<-EOS)
1619
+ |a |= b |= (c, d)
1620
+ EOS
1621
+ end
1622
+
1623
+ # ------------------------------------------------------------------
1624
+ # StringLiteral
1625
+ # ------------------------------------------------------------------
1626
+
1627
+ # TODO: handle unusual characters
1628
+ # TODO: handle prefixes (wide)
1629
+ def test_string_literal_empty
1630
+ check(C::StringLiteral, <<-EOS)
1631
+ |""
1632
+ EOS
1633
+ end
1634
+ def test_string_literal_simple
1635
+ check(C::StringLiteral, <<-EOS)
1636
+ |"hi"
1637
+ EOS
1638
+ end
1639
+ def test_string_literal_complex
1640
+ check(C::StringLiteral, <<-EOS)
1641
+ |"\0000\0xfff"
1642
+ EOS
1643
+ end
1644
+
1645
+ # ------------------------------------------------------------------
1646
+ # CharLiteral
1647
+ # ------------------------------------------------------------------
1648
+
1649
+ # TODO: handle unusual characters
1650
+ # TODO: handle prefixes (wide)
1651
+ def test_char_literal_simple
1652
+ check(C::CharLiteral, <<-EOS)
1653
+ |'x'
1654
+ EOS
1655
+ end
1656
+ def test_char_literal_complex
1657
+ check(C::CharLiteral, <<-EOS)
1658
+ |'\0000\0xfff'
1659
+ EOS
1660
+ end
1661
+
1662
+ # ------------------------------------------------------------------
1663
+ # CompoundLiteral
1664
+ # ------------------------------------------------------------------
1665
+
1666
+ def test_compound_literal_no_type
1667
+ check(C::CompoundLiteral, <<-EOS)
1668
+ |{
1669
+ | 1
1670
+ |}
1671
+ EOS
1672
+ end
1673
+ def test_compound_literal_type
1674
+ check(C::CompoundLiteral, <<-EOS)
1675
+ |(int []) {
1676
+ | 1
1677
+ |}
1678
+ EOS
1679
+ end
1680
+ def test_compound_literal_one_member
1681
+ check(C::CompoundLiteral, <<-EOS)
1682
+ |(struct s) {
1683
+ | .one = 1
1684
+ |}
1685
+ EOS
1686
+ end
1687
+ def test_compound_literal_two_members
1688
+ check(C::CompoundLiteral, <<-EOS)
1689
+ |(union u) {
1690
+ | .one = 1,
1691
+ | .two = 2
1692
+ |}
1693
+ EOS
1694
+ end
1695
+ def test_compound_literal_nested
1696
+ check(C::CompoundLiteral, <<-EOS)
1697
+ |(T) {
1698
+ | .one = (T) {
1699
+ | 2
1700
+ | }
1701
+ |}
1702
+ EOS
1703
+ end
1704
+
1705
+ # ------------------------------------------------------------------
1706
+ # IntLiteral
1707
+ # ------------------------------------------------------------------
1708
+
1709
+ def test_int_literal_small
1710
+ check(C::IntLiteral, <<-EOS)
1711
+ |1
1712
+ EOS
1713
+ end
1714
+ def test_int_literal_oct
1715
+ check(C::IntLiteral, <<-EOS)
1716
+ |010
1717
+ EOS
1718
+ end
1719
+ def test_int_literal_hex
1720
+ check(C::IntLiteral, <<-EOS)
1721
+ |0x10
1722
+ EOS
1723
+ end
1724
+ def test_int_literal_suffix
1725
+ check(C::IntLiteral, <<-EOS)
1726
+ |1L
1727
+ EOS
1728
+ end
1729
+ # TODO: handle big ints -- this test fails
1730
+ def xtest_int_literal_big
1731
+ check(C::IntLiteral, <<-EOS)
1732
+ |10000000000
1733
+ EOS
1734
+ end
1735
+
1736
+ # ------------------------------------------------------------------
1737
+ # FloatLiteral
1738
+ # ------------------------------------------------------------------
1739
+
1740
+ # TODO: handle precisions properly -- probably need to store string,
1741
+ # or integer,mantissa,exponent separately
1742
+ def test_float_literal
1743
+ check(C::FloatLiteral, <<-EOS)
1744
+ |1.0
1745
+ EOS
1746
+ end
1747
+ def test_float_literal_exponent
1748
+ check(C::FloatLiteral, <<-EOS)
1749
+ |1.23e45
1750
+ EOS
1751
+ end
1752
+ def test_float_literal_suffix
1753
+ check(C::FloatLiteral, <<-EOS)
1754
+ |1.0f
1755
+ EOS
1756
+ end
1757
+ def test_float_literal_hex_exponent
1758
+ check(C::FloatLiteral, <<-EOS)
1759
+ |0x12.abp3
1760
+ EOS
1761
+ end
1762
+ def test_float_literal_precise
1763
+ check(C::FloatLiteral, <<-EOS)
1764
+ |1.0000000001
1765
+ EOS
1766
+ end
1767
+
1768
+ # ------------------------------------------------------------------
1769
+ # Pointer
1770
+ # ------------------------------------------------------------------
1771
+
1772
+ def test_pointer
1773
+ check(C::Pointer, <<-EOS)
1774
+ |int *
1775
+ EOS
1776
+ end
1777
+ def test_pointer_precedences
1778
+ check(C::Pointer, <<-EOS)
1779
+ |int *(*)[]
1780
+ EOS
1781
+ end
1782
+ def test_pointer_nested
1783
+ check(C::Pointer, <<-EOS)
1784
+ |int **
1785
+ EOS
1786
+ end
1787
+
1788
+ # ------------------------------------------------------------------
1789
+ # Array
1790
+ # ------------------------------------------------------------------
1791
+ def test_array
1792
+ check(C::Array, <<-EOS)
1793
+ |int []
1794
+ EOS
1795
+ end
1796
+ def test_array_precedences
1797
+ check(C::Pointer, <<-EOS)
1798
+ |int (*)[]
1799
+ EOS
1800
+ end
1801
+ def test_array_nested
1802
+ check(C::Array, <<-EOS)
1803
+ |int [][]
1804
+ EOS
1805
+ end
1806
+
1807
+ # ------------------------------------------------------------------
1808
+ # Function
1809
+ # ------------------------------------------------------------------
1810
+
1811
+ def test_function
1812
+ check(C::Function, <<-EOS)
1813
+ |int ()
1814
+ EOS
1815
+ end
1816
+ def test_function_no_params
1817
+ check(C::Function, <<-EOS)
1818
+ |int (void)
1819
+ EOS
1820
+ end
1821
+ def test_function_params
1822
+ check(C::Function, <<-EOS)
1823
+ |int (int, int)
1824
+ EOS
1825
+ end
1826
+ def test_function_precedences
1827
+ check(C::Pointer, <<-EOS)
1828
+ |int (*)()
1829
+ EOS
1830
+ end
1831
+ def test_function_nested
1832
+ check(C::Function, <<-EOS)
1833
+ |int ()()
1834
+ EOS
1835
+ end
1836
+
1837
+ # ------------------------------------------------------------------
1838
+ # Struct
1839
+ # ------------------------------------------------------------------
1840
+
1841
+ def test_struct_basic
1842
+ check(C::Struct, <<-EOS)
1843
+ |struct {
1844
+ | int i;
1845
+ |}
1846
+ EOS
1847
+ end
1848
+ def test_struct_with_name
1849
+ check(C::Struct, <<-EOS)
1850
+ |struct s {
1851
+ | int i;
1852
+ |}
1853
+ EOS
1854
+ end
1855
+ def test_struct_with_two_members
1856
+ check(C::Struct, <<-EOS)
1857
+ |struct {
1858
+ | int i;
1859
+ | int j;
1860
+ |}
1861
+ EOS
1862
+ end
1863
+ def test_struct_with_all
1864
+ check(C::Struct, <<-EOS)
1865
+ |struct s {
1866
+ | int i;
1867
+ | int j;
1868
+ |}
1869
+ EOS
1870
+ end
1871
+
1872
+ # ------------------------------------------------------------------
1873
+ # Union
1874
+ # ------------------------------------------------------------------
1875
+
1876
+ def test_union_basic
1877
+ check(C::Union, <<-EOS)
1878
+ |union {
1879
+ | int i;
1880
+ |}
1881
+ EOS
1882
+ end
1883
+ def test_union_with_name
1884
+ check(C::Union, <<-EOS)
1885
+ |union u {
1886
+ | int i;
1887
+ |}
1888
+ EOS
1889
+ end
1890
+ def test_union_with_two_members
1891
+ check(C::Union, <<-EOS)
1892
+ |union {
1893
+ | int i;
1894
+ | int j;
1895
+ |}
1896
+ EOS
1897
+ end
1898
+ def test_union_with_all
1899
+ check(C::Union, <<-EOS)
1900
+ |union u {
1901
+ | int i;
1902
+ | int j;
1903
+ |}
1904
+ EOS
1905
+ end
1906
+
1907
+ # ------------------------------------------------------------------
1908
+ # Enum
1909
+ # ------------------------------------------------------------------
1910
+
1911
+ def test_enum_basic
1912
+ check(C::Enum, <<-EOS)
1913
+ |enum {
1914
+ | E1
1915
+ |}
1916
+ EOS
1917
+ end
1918
+ def test_enum_with_name
1919
+ check(C::Enum, <<-EOS)
1920
+ |enum e {
1921
+ | E1
1922
+ |}
1923
+ EOS
1924
+ end
1925
+ def test_enum_with_two_members
1926
+ check(C::Enum, <<-EOS)
1927
+ |enum {
1928
+ | E1,
1929
+ | E2
1930
+ |}
1931
+ EOS
1932
+ end
1933
+ def test_enum_with_all
1934
+ check(C::Enum, <<-EOS)
1935
+ |enum {
1936
+ | E1,
1937
+ | E2
1938
+ |}
1939
+ EOS
1940
+ end
1941
+
1942
+ # ------------------------------------------------------------------
1943
+ # CustomType
1944
+ # ------------------------------------------------------------------
1945
+
1946
+ def test_custom_type_unqualified
1947
+ check(C::CustomType, <<-EOS)
1948
+ |T
1949
+ EOS
1950
+ end
1951
+ def test_custom_type_qualified
1952
+ check(C::CustomType, <<-EOS)
1953
+ |const restrict volatile T
1954
+ EOS
1955
+ end
1956
+
1957
+ # ------------------------------------------------------------------
1958
+ # Void
1959
+ # ------------------------------------------------------------------
1960
+
1961
+ def test_void_unqualified
1962
+ check(C::Void, <<-EOS)
1963
+ |void
1964
+ EOS
1965
+ end
1966
+ def test_void_qualified
1967
+ check(C::Void, <<-EOS)
1968
+ |const restrict volatile void
1969
+ EOS
1970
+ end
1971
+
1972
+ # ------------------------------------------------------------------
1973
+ # Int
1974
+ # ------------------------------------------------------------------
1975
+
1976
+ def test_int_unqualified
1977
+ check(C::Int, <<-EOS)
1978
+ |int
1979
+ EOS
1980
+ end
1981
+ def test_int_qualified
1982
+ check(C::Int, <<-EOS)
1983
+ |const restrict volatile int
1984
+ EOS
1985
+ end
1986
+ def test_int_qualified_short
1987
+ check(C::Int, <<-EOS)
1988
+ |const restrict volatile short int
1989
+ EOS
1990
+ end
1991
+ def test_int_qualified_long
1992
+ check(C::Int, <<-EOS)
1993
+ |const restrict volatile long int
1994
+ EOS
1995
+ end
1996
+ def test_int_qualified_long_long
1997
+ check(C::Int, <<-EOS)
1998
+ |const restrict volatile long long int
1999
+ EOS
2000
+ end
2001
+
2002
+ # ------------------------------------------------------------------
2003
+ # Float
2004
+ # ------------------------------------------------------------------
2005
+
2006
+ def test_float_unqualified
2007
+ check(C::Float, <<-EOS)
2008
+ |float
2009
+ EOS
2010
+ end
2011
+ def test_float_qualified
2012
+ check(C::Float, <<-EOS)
2013
+ |const restrict volatile float
2014
+ EOS
2015
+ end
2016
+ def test_float_qualified_double
2017
+ check(C::Float, <<-EOS)
2018
+ |const restrict volatile double
2019
+ EOS
2020
+ end
2021
+ def test_float_qualified_long_double
2022
+ check(C::Float, <<-EOS)
2023
+ |const restrict volatile long double
2024
+ EOS
2025
+ end
2026
+
2027
+ # ------------------------------------------------------------------
2028
+ # Char
2029
+ # ------------------------------------------------------------------
2030
+
2031
+ def test_char_unqualified
2032
+ check(C::Char, <<-EOS)
2033
+ |char
2034
+ EOS
2035
+ end
2036
+ def test_char_qualified
2037
+ check(C::Char, <<-EOS)
2038
+ |const restrict volatile char
2039
+ EOS
2040
+ end
2041
+ def test_char_qualified_signed
2042
+ check(C::Char, <<-EOS)
2043
+ |const restrict volatile signed char
2044
+ EOS
2045
+ end
2046
+ def test_char_qualified_unsigned
2047
+ check(C::Char, <<-EOS)
2048
+ |const restrict volatile unsigned char
2049
+ EOS
2050
+ end
2051
+
2052
+ # ------------------------------------------------------------------
2053
+ # Bool
2054
+ # ------------------------------------------------------------------
2055
+
2056
+ def test_bool_unqualified
2057
+ check(C::Bool, <<-EOS)
2058
+ |_Bool
2059
+ EOS
2060
+ end
2061
+ def test_bool_qualified
2062
+ check(C::Bool, <<-EOS)
2063
+ |const restrict volatile _Bool
2064
+ EOS
2065
+ end
2066
+
2067
+ # ------------------------------------------------------------------
2068
+ # Complex
2069
+ # ------------------------------------------------------------------
2070
+
2071
+ def test_complex_unqualified
2072
+ check(C::Complex, <<-EOS)
2073
+ |_Complex float
2074
+ EOS
2075
+ end
2076
+ def test_complex_qualified
2077
+ check(C::Complex, <<-EOS)
2078
+ |const restrict volatile _Complex float
2079
+ EOS
2080
+ end
2081
+ def test_complex_qualified_double
2082
+ check(C::Complex, <<-EOS)
2083
+ |const restrict volatile _Complex double
2084
+ EOS
2085
+ end
2086
+ def test_complex_qualified_long_double
2087
+ check(C::Complex, <<-EOS)
2088
+ |const restrict volatile _Complex long double
2089
+ EOS
2090
+ end
2091
+
2092
+ # ------------------------------------------------------------------
2093
+ # Imaginary
2094
+ # ------------------------------------------------------------------
2095
+
2096
+ def test_imaginary_unqualified
2097
+ check(C::Imaginary, <<-EOS)
2098
+ |_Imaginary float
2099
+ EOS
2100
+ end
2101
+ def test_imaginary_qualified
2102
+ check(C::Imaginary, <<-EOS)
2103
+ |const restrict volatile _Imaginary float
2104
+ EOS
2105
+ end
2106
+ def test_imaginary_qualified_double
2107
+ check(C::Imaginary, <<-EOS)
2108
+ |const restrict volatile _Imaginary double
2109
+ EOS
2110
+ end
2111
+ def test_imaginary_qualified_long_double
2112
+ check(C::Imaginary, <<-EOS)
2113
+ |const restrict volatile _Imaginary long double
2114
+ EOS
2115
+ end
2116
+ end