cast 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
1
- ###
2
- ### ##################################################################
3
- ###
4
- ### Tests for the parse methods.
5
- ###
6
- ### ##################################################################
7
- ###
1
+ ######################################################################
2
+ #
3
+ # Tests for the parse methods.
4
+ #
5
+ ######################################################################
6
+
7
+ require 'test/test_helper'
8
8
 
9
9
  class MatchTest < Test::Unit::TestCase
10
10
  def setup
@@ -22,21 +22,21 @@ class MatchTest < Test::Unit::TestCase
22
22
  i = C::Int.new
23
23
  assert_same(false, i.match?('unsigned int'))
24
24
  assert_same(false, i.match?('long int'))
25
- assert_same(false, i.match?('no int here')) # shouldn't raise!
25
+ assert_same(false, i.match?('no int here')) ## shouldn't raise!
26
26
 
27
27
  l = C::IntLiteral.new(10)
28
28
  assert_same(false, i.match?(10.0))
29
29
 
30
30
  t = C::CustomType.new('T')
31
- ##
31
+ #
32
32
  assert_same(false, t.match?('T'))
33
- ##
33
+ #
34
34
  parser = C::Parser.new
35
35
  parser.type_names << 'T'
36
36
  assert_same(true, t.match?('T', parser))
37
- ##
37
+ #
38
38
  assert_same(false, t.match?('T'))
39
- ##
39
+ #
40
40
  C.default_parser.type_names << 'T'
41
41
  assert_same(true, t.match?('T'))
42
42
  end
@@ -62,22 +62,22 @@ class MatchTest < Test::Unit::TestCase
62
62
  assert_same(false, list.match?([['int']]))
63
63
 
64
64
  t = C::NodeArray[C::CustomType.new('T')]
65
- ##
65
+ #
66
66
  assert_same(false, t.match?(['T']))
67
- ##
67
+ #
68
68
  parser = C::Parser.new
69
69
  parser.type_names << 'T'
70
70
  assert_same(true, t.match?(['T'], parser))
71
- ##
71
+ #
72
72
  assert_same(false, t.match?(['T']))
73
- ##
73
+ #
74
74
  C.default_parser.type_names << 'T'
75
75
  assert_same(true, t.match?(['T']))
76
76
  end
77
77
  end
78
78
 
79
79
  class ParseTests < Test::Unit::TestCase
80
- def check klass, s
80
+ def check(klass, s)
81
81
  check_ast(s){|inp| klass.parse(inp)}
82
82
  end
83
83
 
@@ -192,6 +192,22 @@ Declarator
192
192
  name: "x"
193
193
  EOS
194
194
  check C::Declarator, <<EOS
195
+ x : 2
196
+ ----
197
+ Declarator
198
+ name: "x"
199
+ num_bits: IntLiteral
200
+ val: 2
201
+ EOS
202
+ check C::Declarator, <<EOS
203
+ x = 2
204
+ ----
205
+ Declarator
206
+ name: "x"
207
+ init: IntLiteral
208
+ val: 2
209
+ EOS
210
+ check C::Declarator, <<EOS
195
211
  *x(int argc, char **argv)
196
212
  ----
197
213
  Declarator
@@ -208,6 +224,9 @@ Declarator
208
224
  name: "argv"
209
225
  name: "x"
210
226
  EOS
227
+ assert_raise(C::ParseError){C::Declarator.parse('i:1;}; struct {int i')}
228
+ assert_raise(C::ParseError){C::Declarator.parse('i:1; int j')}
229
+ assert_raise(C::ParseError){C::Declarator.parse('i:1,j')}
211
230
  assert_raise(C::ParseError){C::Declarator.parse('f; int f;')}
212
231
  assert_raise(C::ParseError){C::Declarator.parse('i,j')}
213
232
  assert_raise(C::ParseError){C::Declarator.parse(';')}
@@ -316,6 +335,21 @@ EOS
316
335
  assert_raise(C::ParseError){C::MemberInit.parse('')}
317
336
  end
318
337
 
338
+ def test_member
339
+ check C::Member, <<EOS
340
+ x
341
+ ----
342
+ Member
343
+ name: "x"
344
+ EOS
345
+ assert_raise(C::ParseError){C::Member.parse('a = 1};} int f() {struct s x = {a')}
346
+ assert_raise(C::ParseError){C::Member.parse('a = 1}; struct s y = {.a')}
347
+ assert_raise(C::ParseError){C::Member.parse('a = 1}, x = {.a')}
348
+ assert_raise(C::ParseError){C::Member.parse('x = 1, y')}
349
+ assert_raise(C::ParseError){C::Member.parse('1')}
350
+ assert_raise(C::ParseError){C::Member.parse('a .b')}
351
+ end
352
+
319
353
  def test_block
320
354
  check C::Block, <<EOS
321
355
  {}
@@ -1943,6 +1977,18 @@ CompoundLiteral
1943
1977
  - MemberInit
1944
1978
  init: IntLiteral
1945
1979
  val: 30
1980
+ EOS
1981
+ check C::CompoundLiteral, <<EOS
1982
+ {1, 2}
1983
+ ----
1984
+ CompoundLiteral
1985
+ member_inits:
1986
+ - MemberInit
1987
+ init: IntLiteral
1988
+ val: 1
1989
+ - MemberInit
1990
+ init: IntLiteral
1991
+ val: 2
1946
1992
  EOS
1947
1993
  assert_raise(C::ParseError){C::CompoundLiteral.parse('} void f() {')}
1948
1994
  assert_raise(C::ParseError){C::CompoundLiteral.parse(';')}
@@ -1,14 +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
+ ######################################################################
6
+
7
+ require 'test/test_helper'
8
8
 
9
9
  class ParserTest < Test::Unit::TestCase
10
- def check s
11
- check_ast(s){|inp| C::Parser.new.parse(inp)}
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?
12
24
  end
13
25
 
14
26
  def test_comments
@@ -138,31 +150,31 @@ TranslationUnit
138
150
  name: "argv"
139
151
  name: "main"
140
152
  EOS
141
- ## non-function type
153
+ # non-function type
142
154
  assert_raise(C::ParseError){C::Parser.new.parse("int f {}")}
143
155
 
144
- ## both prototype and declist
156
+ # both prototype and declist
145
157
  assert_raise(C::ParseError){C::Parser.new.parse("void f(int argc, int argv) int argc, argv; {}")}
146
158
  assert_raise(C::ParseError){C::Parser.new.parse("void f(int argc, argv) int argv; {}")}
147
159
 
148
- ## bad param name
160
+ # bad param name
149
161
  assert_raise(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc; {}")}
150
162
  assert_raise(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc, argv; {}")}
151
163
 
152
- ## type missing
164
+ # type missing
153
165
  assert_raise(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argc; {}")}
154
166
 
155
- ## bad storage
167
+ # bad storage
156
168
  assert_raise(C::ParseError){C::Parser.new.parse("typedef void f(argc, argv) int argc; {}")}
157
169
  assert_raise(C::ParseError){C::Parser.new.parse("auto void f(argc, argv) int argc; {}")}
158
170
  assert_raise(C::ParseError){C::Parser.new.parse("register void f(argc, argv) int argc; {}")}
159
171
 
160
- ## duplicate storages
172
+ # duplicate storages
161
173
  assert_raise(C::ParseError){C::Parser.new.parse("static auto int i;")}
162
174
  assert_raise(C::ParseError){C::Parser.new.parse("static extern int i;")}
163
175
  assert_raise(C::ParseError){C::Parser.new.parse("typedef register int i;")}
164
176
 
165
- ## `inline' can be repeated
177
+ # `inline' can be repeated
166
178
  assert_nothing_raised{C::Parser.new.parse("inline inline int i() {}")}
167
179
  end
168
180
 
@@ -833,12 +845,12 @@ TranslationUnit
833
845
  - Declarator
834
846
  name: "j"
835
847
  EOS
836
- ## duplicate storages
848
+ # duplicate storages
837
849
  assert_raise(C::ParseError){C::Parser.new.parse("static auto int ;")}
838
850
  assert_raise(C::ParseError){C::Parser.new.parse("static extern int i ;")}
839
851
  assert_raise(C::ParseError){C::Parser.new.parse("typedef register int i, j;")}
840
852
 
841
- ## `inline' can be repeated
853
+ # `inline' can be repeated
842
854
  assert_nothing_raised{C::Parser.new.parse("inline inline int f();")}
843
855
  end
844
856
 
@@ -1150,7 +1162,7 @@ TranslationUnit
1150
1162
  type: CustomType
1151
1163
  name: "I"
1152
1164
  EOS
1153
- ## some illegal combos
1165
+ # some illegal combos
1154
1166
  assert_raise(C::ParseError){C::Parser.new.parse("int float;")}
1155
1167
  assert_raise(C::ParseError){C::Parser.new.parse("struct s {} int;")}
1156
1168
  assert_raise(C::ParseError){C::Parser.new.parse("_Complex;")}
@@ -1300,7 +1312,7 @@ TranslationUnit
1300
1312
  expr: Sizeof
1301
1313
  expr: Int (const)
1302
1314
  EOS
1303
- ## quals can be repeated
1315
+ # quals can be repeated
1304
1316
  assert_nothing_raised{C::Parser.new.parse("void f() {sizeof(const const int);}")}
1305
1317
  end
1306
1318
 
@@ -1561,7 +1573,7 @@ EOS
1561
1573
  end
1562
1574
 
1563
1575
  def test_direct_declarator
1564
- ## TODO
1576
+ # TODO
1565
1577
  end
1566
1578
 
1567
1579
  def test_pointer
@@ -1817,7 +1829,7 @@ EOS
1817
1829
  end
1818
1830
 
1819
1831
  def test_direct_abstract_declarator
1820
- ## TODO
1832
+ # TODO
1821
1833
  end
1822
1834
 
1823
1835
  def test_typedef_name
@@ -2069,6 +2081,34 @@ TranslationUnit
2069
2081
  EOS
2070
2082
  end
2071
2083
 
2084
+ def test_primary_expression_block_expression
2085
+ src = <<EOS
2086
+ void f() {
2087
+ ({;});
2088
+ }
2089
+ EOS
2090
+ assert_raise(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
+
2072
2112
  def test_postfix_expression
2073
2113
  check <<EOS
2074
2114
  void f() {
@@ -0,0 +1,87 @@
1
+ ######################################################################
2
+ #
3
+ # Tests for the preprocessor.
4
+ #
5
+ ######################################################################
6
+
7
+ require 'test/test_helper'
8
+
9
+ # publicize the private methods so we can test them easily
10
+ class C::Preprocessor
11
+ public :shellquote, :full_command
12
+ end
13
+ class PreprocessorTest < Test::Unit::TestCase
14
+ attr_accessor :cpp
15
+ def setup
16
+ @cpp = C::Preprocessor.new
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_shellquote
29
+ assert_equal('a', cpp.shellquote('a'))
30
+ assert_equal("'a b'", cpp.shellquote('a b'))
31
+ assert_equal("'a$b'", cpp.shellquote('a$b'))
32
+ assert_equal("'a\"b'", cpp.shellquote("a\"b"))
33
+ assert_equal("'\\'", cpp.shellquote("\\"))
34
+ assert_equal("\"a'b\"", cpp.shellquote("a'b"))
35
+ assert_equal("\"a\\\\\\$\\\"'\"", cpp.shellquote("a\\$\"'"))
36
+ end
37
+ def test_full_command
38
+ original_command = C::Preprocessor.command
39
+ C::Preprocessor.command = 'COMMAND'
40
+ assert_equal("COMMAND -Idir1 '-Idir 2' -DI=5 '-DS=\"blah\"' " <<
41
+ "'-DSWAP(a,b)=a ^= b ^= a ^= b' -DV 'a file.c'",
42
+ cpp.full_command('a file.c'))
43
+ ensure
44
+ C::Preprocessor.command = original_command
45
+ end
46
+ def test_preprocess
47
+ output = cpp.preprocess("I S SWAP(x, y)")
48
+ assert_match(/5/, output)
49
+ assert_match(/"blah"/, output)
50
+ assert_match(/x \^= y \^= x \^= y/, output)
51
+ end
52
+ def test_preprocess_include
53
+ one_h = "#{TEST_DIR}/one.h"
54
+ two_h = "#{TEST_DIR}/foo/two.h"
55
+ File.open(one_h, 'w'){|f| f.puts "int one = 1;"}
56
+ FileUtils.mkdir(File.dirname(two_h))
57
+ File.open(two_h, 'w'){|f| f.puts "int two = 2;"}
58
+ output = nil
59
+ FileUtils.cd(TEST_DIR) do
60
+ output = cpp.preprocess(<<EOS)
61
+ #include "one.h"
62
+ #include "foo/two.h"
63
+ int three = 3;
64
+ EOS
65
+ end
66
+ assert_match(/int one = 1;/, output)
67
+ assert_match(/int two = 2;/, output)
68
+ assert_match(/int three = 3;/, output)
69
+ end
70
+ def test_preprocess_file
71
+ one_h = "#{TEST_DIR}/one.h"
72
+ two_h = "#{TEST_DIR}/foo/two.h"
73
+ main_c = "#{TEST_DIR}/main.c"
74
+ File.open(one_h, 'w'){|f| f.puts "int one = 1;"}
75
+ FileUtils.mkdir(File.dirname(two_h))
76
+ File.open(two_h, 'w'){|f| f.puts "int two = 2;"}
77
+ File.open(main_c, 'w'){|f| f.puts <<EOS}
78
+ #include "one.h"
79
+ #include "foo/two.h"
80
+ int three = 3;
81
+ EOS
82
+ output = cpp.preprocess_file(main_c)
83
+ assert_match(/int one = 1;/, output)
84
+ assert_match(/int two = 2;/, output)
85
+ assert_match(/int three = 3;/, output)
86
+ end
87
+ end
@@ -0,0 +1,2086 @@
1
+ ######################################################################
2
+ #
3
+ # Tests for the #render method of each Node.
4
+ #
5
+ ######################################################################
6
+
7
+ require 'test/test_helper'
8
+
9
+ class RenderTest < Test::Unit::TestCase
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
+ # TODO: handle big ints -- this test fails
1715
+ def xtest_int_literal_big
1716
+ check(C::IntLiteral, <<-EOS)
1717
+ |10000000000
1718
+ EOS
1719
+ end
1720
+
1721
+ # ------------------------------------------------------------------
1722
+ # FloatLiteral
1723
+ # ------------------------------------------------------------------
1724
+
1725
+ # TODO: handle precisions properly -- probably need to store string,
1726
+ # or integer,mantissa,exponent separately
1727
+ def test_float_literal
1728
+ check(C::FloatLiteral, <<-EOS)
1729
+ |1.0
1730
+ EOS
1731
+ end
1732
+ def test_float_literal_precise
1733
+ check(C::FloatLiteral, <<-EOS)
1734
+ |1.0000000001
1735
+ EOS
1736
+ end
1737
+
1738
+ # ------------------------------------------------------------------
1739
+ # Pointer
1740
+ # ------------------------------------------------------------------
1741
+
1742
+ def test_pointer
1743
+ check(C::Pointer, <<-EOS)
1744
+ |int *
1745
+ EOS
1746
+ end
1747
+ def test_pointer_precedences
1748
+ check(C::Pointer, <<-EOS)
1749
+ |int *(*)[]
1750
+ EOS
1751
+ end
1752
+ def test_pointer_nested
1753
+ check(C::Pointer, <<-EOS)
1754
+ |int **
1755
+ EOS
1756
+ end
1757
+
1758
+ # ------------------------------------------------------------------
1759
+ # Array
1760
+ # ------------------------------------------------------------------
1761
+ def test_array
1762
+ check(C::Array, <<-EOS)
1763
+ |int []
1764
+ EOS
1765
+ end
1766
+ def test_array_precedences
1767
+ check(C::Pointer, <<-EOS)
1768
+ |int (*)[]
1769
+ EOS
1770
+ end
1771
+ def test_array_nested
1772
+ check(C::Array, <<-EOS)
1773
+ |int [][]
1774
+ EOS
1775
+ end
1776
+
1777
+ # ------------------------------------------------------------------
1778
+ # Function
1779
+ # ------------------------------------------------------------------
1780
+
1781
+ def test_function
1782
+ check(C::Function, <<-EOS)
1783
+ |int ()
1784
+ EOS
1785
+ end
1786
+ def test_function_no_params
1787
+ check(C::Function, <<-EOS)
1788
+ |int (void)
1789
+ EOS
1790
+ end
1791
+ def test_function_params
1792
+ check(C::Function, <<-EOS)
1793
+ |int (int, int)
1794
+ EOS
1795
+ end
1796
+ def test_function_precedences
1797
+ check(C::Pointer, <<-EOS)
1798
+ |int (*)()
1799
+ EOS
1800
+ end
1801
+ def test_function_nested
1802
+ check(C::Function, <<-EOS)
1803
+ |int ()()
1804
+ EOS
1805
+ end
1806
+
1807
+ # ------------------------------------------------------------------
1808
+ # Struct
1809
+ # ------------------------------------------------------------------
1810
+
1811
+ def test_struct_basic
1812
+ check(C::Struct, <<-EOS)
1813
+ |struct {
1814
+ | int i;
1815
+ |}
1816
+ EOS
1817
+ end
1818
+ def test_struct_with_name
1819
+ check(C::Struct, <<-EOS)
1820
+ |struct s {
1821
+ | int i;
1822
+ |}
1823
+ EOS
1824
+ end
1825
+ def test_struct_with_two_members
1826
+ check(C::Struct, <<-EOS)
1827
+ |struct {
1828
+ | int i;
1829
+ | int j;
1830
+ |}
1831
+ EOS
1832
+ end
1833
+ def test_struct_with_all
1834
+ check(C::Struct, <<-EOS)
1835
+ |struct s {
1836
+ | int i;
1837
+ | int j;
1838
+ |}
1839
+ EOS
1840
+ end
1841
+
1842
+ # ------------------------------------------------------------------
1843
+ # Union
1844
+ # ------------------------------------------------------------------
1845
+
1846
+ def test_union_basic
1847
+ check(C::Union, <<-EOS)
1848
+ |union {
1849
+ | int i;
1850
+ |}
1851
+ EOS
1852
+ end
1853
+ def test_union_with_name
1854
+ check(C::Union, <<-EOS)
1855
+ |union u {
1856
+ | int i;
1857
+ |}
1858
+ EOS
1859
+ end
1860
+ def test_union_with_two_members
1861
+ check(C::Union, <<-EOS)
1862
+ |union {
1863
+ | int i;
1864
+ | int j;
1865
+ |}
1866
+ EOS
1867
+ end
1868
+ def test_union_with_all
1869
+ check(C::Union, <<-EOS)
1870
+ |union u {
1871
+ | int i;
1872
+ | int j;
1873
+ |}
1874
+ EOS
1875
+ end
1876
+
1877
+ # ------------------------------------------------------------------
1878
+ # Enum
1879
+ # ------------------------------------------------------------------
1880
+
1881
+ def test_enum_basic
1882
+ check(C::Enum, <<-EOS)
1883
+ |enum {
1884
+ | E1
1885
+ |}
1886
+ EOS
1887
+ end
1888
+ def test_enum_with_name
1889
+ check(C::Enum, <<-EOS)
1890
+ |enum e {
1891
+ | E1
1892
+ |}
1893
+ EOS
1894
+ end
1895
+ def test_enum_with_two_members
1896
+ check(C::Enum, <<-EOS)
1897
+ |enum {
1898
+ | E1,
1899
+ | E2
1900
+ |}
1901
+ EOS
1902
+ end
1903
+ def test_enum_with_all
1904
+ check(C::Enum, <<-EOS)
1905
+ |enum {
1906
+ | E1,
1907
+ | E2
1908
+ |}
1909
+ EOS
1910
+ end
1911
+
1912
+ # ------------------------------------------------------------------
1913
+ # CustomType
1914
+ # ------------------------------------------------------------------
1915
+
1916
+ def test_custom_type_unqualified
1917
+ check(C::CustomType, <<-EOS)
1918
+ |T
1919
+ EOS
1920
+ end
1921
+ def test_custom_type_qualified
1922
+ check(C::CustomType, <<-EOS)
1923
+ |const restrict volatile T
1924
+ EOS
1925
+ end
1926
+
1927
+ # ------------------------------------------------------------------
1928
+ # Void
1929
+ # ------------------------------------------------------------------
1930
+
1931
+ def test_void_unqualified
1932
+ check(C::Void, <<-EOS)
1933
+ |void
1934
+ EOS
1935
+ end
1936
+ def test_void_qualified
1937
+ check(C::Void, <<-EOS)
1938
+ |const restrict volatile void
1939
+ EOS
1940
+ end
1941
+
1942
+ # ------------------------------------------------------------------
1943
+ # Int
1944
+ # ------------------------------------------------------------------
1945
+
1946
+ def test_int_unqualified
1947
+ check(C::Int, <<-EOS)
1948
+ |int
1949
+ EOS
1950
+ end
1951
+ def test_int_qualified
1952
+ check(C::Int, <<-EOS)
1953
+ |const restrict volatile int
1954
+ EOS
1955
+ end
1956
+ def test_int_qualified_short
1957
+ check(C::Int, <<-EOS)
1958
+ |const restrict volatile short int
1959
+ EOS
1960
+ end
1961
+ def test_int_qualified_long
1962
+ check(C::Int, <<-EOS)
1963
+ |const restrict volatile long int
1964
+ EOS
1965
+ end
1966
+ def test_int_qualified_long_long
1967
+ check(C::Int, <<-EOS)
1968
+ |const restrict volatile long long int
1969
+ EOS
1970
+ end
1971
+
1972
+ # ------------------------------------------------------------------
1973
+ # Float
1974
+ # ------------------------------------------------------------------
1975
+
1976
+ def test_float_unqualified
1977
+ check(C::Float, <<-EOS)
1978
+ |float
1979
+ EOS
1980
+ end
1981
+ def test_float_qualified
1982
+ check(C::Float, <<-EOS)
1983
+ |const restrict volatile float
1984
+ EOS
1985
+ end
1986
+ def test_float_qualified_double
1987
+ check(C::Float, <<-EOS)
1988
+ |const restrict volatile double
1989
+ EOS
1990
+ end
1991
+ def test_float_qualified_long_double
1992
+ check(C::Float, <<-EOS)
1993
+ |const restrict volatile long double
1994
+ EOS
1995
+ end
1996
+
1997
+ # ------------------------------------------------------------------
1998
+ # Char
1999
+ # ------------------------------------------------------------------
2000
+
2001
+ def test_char_unqualified
2002
+ check(C::Char, <<-EOS)
2003
+ |char
2004
+ EOS
2005
+ end
2006
+ def test_char_qualified
2007
+ check(C::Char, <<-EOS)
2008
+ |const restrict volatile char
2009
+ EOS
2010
+ end
2011
+ def test_char_qualified_signed
2012
+ check(C::Char, <<-EOS)
2013
+ |const restrict volatile signed char
2014
+ EOS
2015
+ end
2016
+ def test_char_qualified_unsigned
2017
+ check(C::Char, <<-EOS)
2018
+ |const restrict volatile unsigned char
2019
+ EOS
2020
+ end
2021
+
2022
+ # ------------------------------------------------------------------
2023
+ # Bool
2024
+ # ------------------------------------------------------------------
2025
+
2026
+ def test_bool_unqualified
2027
+ check(C::Bool, <<-EOS)
2028
+ |_Bool
2029
+ EOS
2030
+ end
2031
+ def test_bool_qualified
2032
+ check(C::Bool, <<-EOS)
2033
+ |const restrict volatile _Bool
2034
+ EOS
2035
+ end
2036
+
2037
+ # ------------------------------------------------------------------
2038
+ # Complex
2039
+ # ------------------------------------------------------------------
2040
+
2041
+ def test_complex_unqualified
2042
+ check(C::Complex, <<-EOS)
2043
+ |_Complex float
2044
+ EOS
2045
+ end
2046
+ def test_complex_qualified
2047
+ check(C::Complex, <<-EOS)
2048
+ |const restrict volatile _Complex float
2049
+ EOS
2050
+ end
2051
+ def test_complex_qualified_double
2052
+ check(C::Complex, <<-EOS)
2053
+ |const restrict volatile _Complex double
2054
+ EOS
2055
+ end
2056
+ def test_complex_qualified_long_double
2057
+ check(C::Complex, <<-EOS)
2058
+ |const restrict volatile _Complex long double
2059
+ EOS
2060
+ end
2061
+
2062
+ # ------------------------------------------------------------------
2063
+ # Imaginary
2064
+ # ------------------------------------------------------------------
2065
+
2066
+ def test_imaginary_unqualified
2067
+ check(C::Imaginary, <<-EOS)
2068
+ |_Imaginary float
2069
+ EOS
2070
+ end
2071
+ def test_imaginary_qualified
2072
+ check(C::Imaginary, <<-EOS)
2073
+ |const restrict volatile _Imaginary float
2074
+ EOS
2075
+ end
2076
+ def test_imaginary_qualified_double
2077
+ check(C::Imaginary, <<-EOS)
2078
+ |const restrict volatile _Imaginary double
2079
+ EOS
2080
+ end
2081
+ def test_imaginary_qualified_long_double
2082
+ check(C::Imaginary, <<-EOS)
2083
+ |const restrict volatile _Imaginary long double
2084
+ EOS
2085
+ end
2086
+ end