@@ -12,61 +12,88 @@ class TestCParser < TestCase
12
12
13
13
def test_char_ctype
14
14
assert_equal ( TYPE_CHAR , parse_ctype ( 'char' ) )
15
+ assert_equal ( TYPE_CHAR , parse_ctype ( 'const char' ) )
15
16
assert_equal ( TYPE_CHAR , parse_ctype ( 'signed char' ) )
17
+ assert_equal ( TYPE_CHAR , parse_ctype ( 'const signed char' ) )
16
18
assert_equal ( -TYPE_CHAR , parse_ctype ( 'unsigned char' ) )
19
+ assert_equal ( -TYPE_CHAR , parse_ctype ( 'const unsigned char' ) )
17
20
end
18
21
19
22
def test_short_ctype
20
23
assert_equal ( TYPE_SHORT , parse_ctype ( 'short' ) )
24
+ assert_equal ( TYPE_SHORT , parse_ctype ( 'const short' ) )
21
25
assert_equal ( TYPE_SHORT , parse_ctype ( 'short int' ) )
26
+ assert_equal ( TYPE_SHORT , parse_ctype ( 'const short int' ) )
22
27
assert_equal ( TYPE_SHORT , parse_ctype ( 'signed short' ) )
28
+ assert_equal ( TYPE_SHORT , parse_ctype ( 'const signed short' ) )
23
29
assert_equal ( TYPE_SHORT , parse_ctype ( 'signed short int' ) )
30
+ assert_equal ( TYPE_SHORT , parse_ctype ( 'const signed short int' ) )
24
31
assert_equal ( -TYPE_SHORT , parse_ctype ( 'unsigned short' ) )
32
+ assert_equal ( -TYPE_SHORT , parse_ctype ( 'const unsigned short' ) )
25
33
assert_equal ( -TYPE_SHORT , parse_ctype ( 'unsigned short int' ) )
34
+ assert_equal ( -TYPE_SHORT , parse_ctype ( 'const unsigned short int' ) )
26
35
end
27
36
28
37
def test_int_ctype
29
38
assert_equal ( TYPE_INT , parse_ctype ( 'int' ) )
39
+ assert_equal ( TYPE_INT , parse_ctype ( 'const int' ) )
30
40
assert_equal ( TYPE_INT , parse_ctype ( 'signed int' ) )
41
+ assert_equal ( TYPE_INT , parse_ctype ( 'const signed int' ) )
31
42
assert_equal ( -TYPE_INT , parse_ctype ( 'uint' ) )
43
+ assert_equal ( -TYPE_INT , parse_ctype ( 'const uint' ) )
32
44
assert_equal ( -TYPE_INT , parse_ctype ( 'unsigned int' ) )
45
+ assert_equal ( -TYPE_INT , parse_ctype ( 'const unsigned int' ) )
33
46
end
34
47
35
48
def test_long_ctype
36
49
assert_equal ( TYPE_LONG , parse_ctype ( 'long' ) )
50
+ assert_equal ( TYPE_LONG , parse_ctype ( 'const long' ) )
37
51
assert_equal ( TYPE_LONG , parse_ctype ( 'long int' ) )
52
+ assert_equal ( TYPE_LONG , parse_ctype ( 'const long int' ) )
38
53
assert_equal ( TYPE_LONG , parse_ctype ( 'signed long' ) )
54
+ assert_equal ( TYPE_LONG , parse_ctype ( 'const signed long' ) )
39
55
assert_equal ( TYPE_LONG , parse_ctype ( 'signed long int' ) )
56
+ assert_equal ( TYPE_LONG , parse_ctype ( 'const signed long int' ) )
40
57
assert_equal ( -TYPE_LONG , parse_ctype ( 'unsigned long' ) )
58
+ assert_equal ( -TYPE_LONG , parse_ctype ( 'const unsigned long' ) )
41
59
assert_equal ( -TYPE_LONG , parse_ctype ( 'unsigned long int' ) )
60
+ assert_equal ( -TYPE_LONG , parse_ctype ( 'const unsigned long int' ) )
42
61
end
43
62
44
63
def test_size_t_ctype
45
64
assert_equal ( TYPE_SIZE_T , parse_ctype ( "size_t" ) )
65
+ assert_equal ( TYPE_SIZE_T , parse_ctype ( "const size_t" ) )
46
66
end
47
67
48
68
def test_ssize_t_ctype
49
69
assert_equal ( TYPE_SSIZE_T , parse_ctype ( "ssize_t" ) )
70
+ assert_equal ( TYPE_SSIZE_T , parse_ctype ( "const ssize_t" ) )
50
71
end
51
72
52
73
def test_ptrdiff_t_ctype
53
74
assert_equal ( TYPE_PTRDIFF_T , parse_ctype ( "ptrdiff_t" ) )
75
+ assert_equal ( TYPE_PTRDIFF_T , parse_ctype ( "const ptrdiff_t" ) )
54
76
end
55
77
56
78
def test_intptr_t_ctype
57
79
assert_equal ( TYPE_INTPTR_T , parse_ctype ( "intptr_t" ) )
80
+ assert_equal ( TYPE_INTPTR_T , parse_ctype ( "const intptr_t" ) )
58
81
end
59
82
60
83
def test_uintptr_t_ctype
61
84
assert_equal ( TYPE_UINTPTR_T , parse_ctype ( "uintptr_t" ) )
85
+ assert_equal ( TYPE_UINTPTR_T , parse_ctype ( "const uintptr_t" ) )
62
86
end
63
87
64
88
def test_undefined_ctype
65
89
assert_raise ( DLError ) { parse_ctype ( 'DWORD' ) }
66
90
end
67
91
68
92
def test_undefined_ctype_with_type_alias
69
- assert_equal ( -TYPE_LONG , parse_ctype ( 'DWORD' , { "DWORD" => "unsigned long" } ) )
93
+ assert_equal ( -TYPE_LONG ,
94
+ parse_ctype ( 'DWORD' , { "DWORD" => "unsigned long" } ) )
95
+ assert_equal ( -TYPE_LONG ,
96
+ parse_ctype ( 'const DWORD' , { "DWORD" => "unsigned long" } ) )
70
97
end
71
98
72
99
def expand_struct_types ( types )
@@ -83,11 +110,21 @@ def expand_struct_types(types)
83
110
end
84
111
85
112
def test_struct_basic
86
- assert_equal [ [ TYPE_INT , TYPE_CHAR ] , [ 'i' , 'c' ] ] , parse_struct_signature ( [ 'int i' , 'char c' ] )
113
+ assert_equal ( [ [ TYPE_INT , TYPE_CHAR ] , [ 'i' , 'c' ] ] ,
114
+ parse_struct_signature ( [ 'int i' , 'char c' ] ) )
115
+ assert_equal ( [ [ TYPE_INT , TYPE_CHAR ] , [ 'i' , 'c' ] ] ,
116
+ parse_struct_signature ( [ 'const int i' , 'const char c' ] ) )
87
117
end
88
118
89
119
def test_struct_array
90
- assert_equal [ [ [ TYPE_CHAR , 80 ] , [ TYPE_INT , 5 ] ] , [ 'buffer' , 'x' ] ] , parse_struct_signature ( [ 'char buffer[80]' , 'int[5] x' ] )
120
+ assert_equal ( [ [ [ TYPE_CHAR , 80 ] , [ TYPE_INT , 5 ] ] ,
121
+ [ 'buffer' , 'x' ] ] ,
122
+ parse_struct_signature ( [ 'char buffer[80]' ,
123
+ 'int[5] x' ] ) )
124
+ assert_equal ( [ [ [ TYPE_CHAR , 80 ] , [ TYPE_INT , 5 ] ] ,
125
+ [ 'buffer' , 'x' ] ] ,
126
+ parse_struct_signature ( [ 'const char buffer[80]' ,
127
+ 'const int[5] x' ] ) )
91
128
end
92
129
93
130
def test_struct_nested_struct
@@ -178,15 +215,22 @@ def test_struct_double_nested_struct_outer_array
178
215
end
179
216
180
217
def test_struct_array_str
181
- assert_equal [ [ [ TYPE_CHAR , 80 ] , [ TYPE_INT , 5 ] ] , [ 'buffer' , 'x' ] ] , parse_struct_signature ( 'char buffer[80], int[5] x' )
218
+ assert_equal ( [ [ [ TYPE_CHAR , 80 ] , [ TYPE_INT , 5 ] ] ,
219
+ [ 'buffer' , 'x' ] ] ,
220
+ parse_struct_signature ( 'char buffer[80], int[5] x' ) )
221
+ assert_equal ( [ [ [ TYPE_CHAR , 80 ] , [ TYPE_INT , 5 ] ] ,
222
+ [ 'buffer' , 'x' ] ] ,
223
+ parse_struct_signature ( 'const char buffer[80], const int[5] x' ) )
182
224
end
183
225
184
226
def test_struct_function_pointer
185
- assert_equal [ [ TYPE_VOIDP ] , [ 'cb' ] ] , parse_struct_signature ( [ 'void (*cb)(const char*)' ] )
227
+ assert_equal ( [ [ TYPE_VOIDP ] , [ 'cb' ] ] ,
228
+ parse_struct_signature ( [ 'void (*cb)(const char*)' ] ) )
186
229
end
187
230
188
231
def test_struct_function_pointer_str
189
- assert_equal [ [ TYPE_VOIDP , TYPE_VOIDP ] , [ 'cb' , 'data' ] ] , parse_struct_signature ( 'void (*cb)(const char*), const char* data' )
232
+ assert_equal ( [ [ TYPE_VOIDP , TYPE_VOIDP ] , [ 'cb' , 'data' ] ] ,
233
+ parse_struct_signature ( 'void (*cb)(const char*), const char* data' ) )
190
234
end
191
235
192
236
def test_struct_string
0 commit comments