alisdair sullivan | fb6ed7e | 2014-07-22 23:40:44 -0700 | [diff] [blame] | 1 | %% |
| 2 | %% Licensed to the Apache Software Foundation (ASF) under one |
| 3 | %% or more contributor license agreements. See the NOTICE file |
| 4 | %% distributed with this work for additional information |
| 5 | %% regarding copyright ownership. The ASF licenses this file |
| 6 | %% to you under the Apache License, Version 2.0 (the |
| 7 | %% "License"); you may not use this file except in compliance |
| 8 | %% with the License. You may obtain a copy of the License at |
| 9 | %% |
| 10 | %% http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | %% |
| 12 | %% Unless required by applicable law or agreed to in writing, |
| 13 | %% software distributed under the License is distributed on an |
| 14 | %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | %% KIND, either express or implied. See the License for the |
| 16 | %% specific language governing permissions and limitations |
| 17 | %% under the License. |
| 18 | %% |
| 19 | |
Jens Geyer | 6d15c30 | 2014-10-02 10:03:09 +0200 | [diff] [blame] | 20 | -module(name_conflict_test). |
alisdair sullivan | fb6ed7e | 2014-07-22 23:40:44 -0700 | [diff] [blame] | 21 | |
| 22 | -include_lib("eunit/include/eunit.hrl"). |
| 23 | |
Nobuaki Sukegawa | 826ea99 | 2015-10-28 22:19:45 +0900 | [diff] [blame] | 24 | -include("gen-erl/name_conflict_test_constants.hrl"). |
alisdair sullivan | fb6ed7e | 2014-07-22 23:40:44 -0700 | [diff] [blame] | 25 | |
| 26 | record_generation_test_() -> |
Sergei Elin | 4576409 | 2022-09-23 23:21:31 +0300 | [diff] [blame] | 27 | [ |
| 28 | {"using record", |
| 29 | ?_assertMatch( |
| 30 | {using, _, _}, |
| 31 | #using{single = null, integer = null} |
| 32 | )}, |
| 33 | {"delegate record", |
| 34 | ?_assertMatch( |
| 35 | {delegate, _, _}, |
| 36 | #delegate{partial = null, delegate = null} |
| 37 | )}, |
| 38 | {"get record", |
| 39 | ?_assertMatch( |
| 40 | {get, _}, |
| 41 | #get{sbyte = null} |
| 42 | )}, |
| 43 | {"partial record", |
| 44 | ?_assertMatch( |
| 45 | {partial, _, _, _}, |
| 46 | #partial{using = null} |
| 47 | )}, |
| 48 | {"ClassAndProp record", |
| 49 | ?_assertMatch( |
| 50 | {'ClassAndProp', _, _, _, _}, |
| 51 | #'ClassAndProp'{ |
| 52 | 'ClassAndProp' = null, |
| 53 | 'ClassAndProp_' = null, |
| 54 | 'ClassAndProp__' = null, |
| 55 | 'ClassAndProper' = null |
| 56 | } |
| 57 | )}, |
| 58 | {"second_chance record", |
| 59 | ?_assertMatch( |
| 60 | {second_chance, _, _, _, _}, |
| 61 | #second_chance{ |
| 62 | 'SECOND_CHANCE' = null, |
| 63 | 'SECOND_CHANCE_' = null, |
| 64 | 'SECOND_CHANCE__' = null, |
| 65 | 'SECOND_CHANCES' = null |
| 66 | } |
| 67 | )}, |
| 68 | {"NOW_EAT_THIS record", |
| 69 | ?_assertMatch( |
| 70 | {'NOW_EAT_THIS', _, _, _, _}, |
| 71 | #'NOW_EAT_THIS'{ |
| 72 | now_eat_this = null, |
| 73 | now_eat_this_ = null, |
| 74 | now_eat_this__ = null, |
| 75 | now_eat_this_and_this = null |
| 76 | } |
| 77 | )}, |
| 78 | {"TheEdgeCase record", |
| 79 | ?_assertMatch( |
| 80 | {'TheEdgeCase', _, _, _, _, _, _}, |
| 81 | #'TheEdgeCase'{ |
| 82 | theEdgeCase = null, |
| 83 | theEdgeCase_ = null, |
| 84 | theEdgeCase__ = null, |
| 85 | 'TheEdgeCase' = null, |
| 86 | 'TheEdgeCase_' = null, |
| 87 | 'TheEdgeCase__' = null |
| 88 | } |
| 89 | )}, |
| 90 | {"Tricky_ record", |
| 91 | ?_assertMatch( |
| 92 | {'Tricky_', _, _}, |
| 93 | #'Tricky_'{tricky = null, 'Tricky' = null} |
| 94 | )}, |
| 95 | {"Nested record", |
| 96 | ?_assertMatch( |
| 97 | {'Nested', _, _, _, _, _, _}, |
| 98 | #'Nested'{ |
| 99 | 'ClassAndProp' = null, |
| 100 | second_chance = null, |
| 101 | 'NOW_EAT_THIS' = null, |
| 102 | 'TheEdgeCase' = null, |
| 103 | 'Tricky_' = null, |
| 104 | 'Nested' = null |
| 105 | } |
| 106 | )}, |
| 107 | {"Problem_ record", |
| 108 | ?_assertMatch( |
| 109 | {'Problem_', _, _}, |
| 110 | #'Problem_'{problem = null, 'Problem' = null} |
| 111 | )} |
| 112 | ]. |
alisdair sullivan | fb6ed7e | 2014-07-22 23:40:44 -0700 | [diff] [blame] | 113 | |
| 114 | struct_info_test_() -> |
Sergei Elin | 4576409 | 2022-09-23 23:21:31 +0300 | [diff] [blame] | 115 | [ |
| 116 | {"using definition", |
| 117 | ?_assertEqual( |
| 118 | {struct, [{1, double}, {2, double}]}, |
| 119 | name_conflict_test_types:struct_info(using) |
| 120 | )}, |
| 121 | {"delegate definition", |
| 122 | ?_assertEqual( |
| 123 | {struct, [ |
| 124 | {1, string}, |
| 125 | {2, {struct, {name_conflict_test_types, delegate}}} |
| 126 | ]}, |
| 127 | name_conflict_test_types:struct_info(delegate) |
| 128 | )}, |
| 129 | {"get definition", |
| 130 | ?_assertEqual( |
| 131 | {struct, [{1, bool}]}, |
| 132 | name_conflict_test_types:struct_info(get) |
| 133 | )}, |
| 134 | {"partial definition", |
| 135 | ?_assertEqual( |
| 136 | {struct, [ |
| 137 | {1, {struct, {name_conflict_test_types, using}}}, |
| 138 | {2, bool}, |
| 139 | {3, bool} |
| 140 | ]}, |
| 141 | name_conflict_test_types:struct_info(partial) |
| 142 | )}, |
| 143 | {"ClassAndProp definition", |
| 144 | ?_assertEqual( |
| 145 | {struct, [{1, bool}, {2, bool}, {3, bool}, {4, bool}]}, |
| 146 | name_conflict_test_types:struct_info('ClassAndProp') |
| 147 | )}, |
| 148 | {"second_chance definition", |
| 149 | ?_assertEqual( |
| 150 | {struct, [{1, bool}, {2, bool}, {3, bool}, {4, bool}]}, |
| 151 | name_conflict_test_types:struct_info(second_chance) |
| 152 | )}, |
| 153 | {"NOW_EAT_THIS definition", |
| 154 | ?_assertEqual( |
| 155 | {struct, [{1, bool}, {2, bool}, {3, bool}, {4, bool}]}, |
| 156 | name_conflict_test_types:struct_info('NOW_EAT_THIS') |
| 157 | )}, |
| 158 | {"TheEdgeCase definition", |
| 159 | ?_assertEqual( |
| 160 | {struct, [{1, bool}, {2, bool}, {3, bool}, {4, bool}, {5, bool}, {6, bool}]}, |
| 161 | name_conflict_test_types:struct_info('TheEdgeCase') |
| 162 | )}, |
| 163 | {"Tricky_ definition", |
| 164 | ?_assertEqual( |
| 165 | {struct, [{1, bool}, {2, bool}]}, |
| 166 | name_conflict_test_types:struct_info('Tricky_') |
| 167 | )}, |
| 168 | {"Nested definition", |
| 169 | ?_assertEqual( |
| 170 | {struct, [ |
| 171 | {1, {struct, {name_conflict_test_types, 'ClassAndProp'}}}, |
| 172 | {2, {struct, {name_conflict_test_types, second_chance}}}, |
| 173 | {3, {struct, {name_conflict_test_types, 'NOW_EAT_THIS'}}}, |
| 174 | {4, {struct, {name_conflict_test_types, 'TheEdgeCase'}}}, |
| 175 | {5, {struct, {name_conflict_test_types, 'Tricky_'}}}, |
| 176 | {6, {struct, {name_conflict_test_types, 'Nested'}}} |
| 177 | ]}, |
| 178 | name_conflict_test_types:struct_info('Nested') |
| 179 | )}, |
| 180 | {"Problem_ definition", |
| 181 | ?_assertEqual( |
| 182 | {struct, [{1, bool}, {2, bool}]}, |
| 183 | name_conflict_test_types:struct_info('Problem_') |
| 184 | )}, |
| 185 | {"using extended definition", |
| 186 | ?_assertEqual( |
| 187 | {struct, [ |
| 188 | {1, undefined, double, single, undefined}, |
| 189 | {2, undefined, double, integer, undefined} |
| 190 | ]}, |
| 191 | name_conflict_test_types:struct_info_ext(using) |
| 192 | )}, |
| 193 | {"delegate extended definition", |
| 194 | ?_assertEqual( |
| 195 | {struct, [ |
| 196 | {1, undefined, string, partial, undefined}, |
| 197 | {2, undefined, {struct, {name_conflict_test_types, delegate}}, delegate, |
| 198 | undefined} |
| 199 | ]}, |
| 200 | name_conflict_test_types:struct_info_ext(delegate) |
| 201 | )}, |
| 202 | {"get extended definition", |
| 203 | ?_assertEqual( |
| 204 | {struct, [{1, undefined, bool, sbyte, undefined}]}, |
| 205 | name_conflict_test_types:struct_info_ext(get) |
| 206 | )}, |
| 207 | {"partial extended definition", |
| 208 | ?_assertEqual( |
| 209 | {struct, [ |
| 210 | {1, undefined, {struct, {name_conflict_test_types, using}}, using, #using{}}, |
| 211 | {2, undefined, bool, read, undefined}, |
| 212 | {3, undefined, bool, write, undefined} |
| 213 | ]}, |
| 214 | name_conflict_test_types:struct_info_ext(partial) |
| 215 | )}, |
| 216 | {"ClassAndProp extended definition", |
| 217 | ?_assertEqual( |
| 218 | {struct, [ |
| 219 | {1, undefined, bool, 'ClassAndProp', undefined}, |
| 220 | {2, undefined, bool, 'ClassAndProp_', undefined}, |
| 221 | {3, undefined, bool, 'ClassAndProp__', undefined}, |
| 222 | {4, undefined, bool, 'ClassAndProper', undefined} |
| 223 | ]}, |
| 224 | name_conflict_test_types:struct_info_ext('ClassAndProp') |
| 225 | )}, |
| 226 | {"second_chance extended definition", |
| 227 | ?_assertEqual( |
| 228 | {struct, [ |
| 229 | {1, undefined, bool, 'SECOND_CHANCE', undefined}, |
| 230 | {2, undefined, bool, 'SECOND_CHANCE_', undefined}, |
| 231 | {3, undefined, bool, 'SECOND_CHANCE__', undefined}, |
| 232 | {4, undefined, bool, 'SECOND_CHANCES', undefined} |
| 233 | ]}, |
| 234 | name_conflict_test_types:struct_info_ext(second_chance) |
| 235 | )}, |
| 236 | {"NOW_EAT_THIS extended definition", |
| 237 | ?_assertEqual( |
| 238 | {struct, [ |
| 239 | {1, undefined, bool, now_eat_this, undefined}, |
| 240 | {2, undefined, bool, now_eat_this_, undefined}, |
| 241 | {3, undefined, bool, now_eat_this__, undefined}, |
| 242 | {4, undefined, bool, now_eat_this_and_this, undefined} |
| 243 | ]}, |
| 244 | name_conflict_test_types:struct_info_ext('NOW_EAT_THIS') |
| 245 | )}, |
| 246 | {"TheEdgeCase extended definition", |
| 247 | ?_assertEqual( |
| 248 | {struct, [ |
| 249 | {1, undefined, bool, theEdgeCase, undefined}, |
| 250 | {2, undefined, bool, theEdgeCase_, undefined}, |
| 251 | {3, undefined, bool, theEdgeCase__, undefined}, |
| 252 | {4, undefined, bool, 'TheEdgeCase', undefined}, |
| 253 | {5, undefined, bool, 'TheEdgeCase_', undefined}, |
| 254 | {6, undefined, bool, 'TheEdgeCase__', undefined} |
| 255 | ]}, |
| 256 | name_conflict_test_types:struct_info_ext('TheEdgeCase') |
| 257 | )}, |
| 258 | {"Tricky_ extended definition", |
| 259 | ?_assertEqual( |
| 260 | {struct, [ |
| 261 | {1, undefined, bool, tricky, undefined}, |
| 262 | {2, undefined, bool, 'Tricky', undefined} |
| 263 | ]}, |
| 264 | name_conflict_test_types:struct_info_ext('Tricky_') |
| 265 | )}, |
| 266 | {"Nested extended definition", |
| 267 | ?_assertEqual( |
| 268 | {struct, [ |
| 269 | {1, undefined, |
| 270 | {struct, { |
| 271 | name_conflict_test_types, |
| 272 | 'ClassAndProp' |
| 273 | }}, |
| 274 | 'ClassAndProp', #'ClassAndProp'{}}, |
| 275 | {2, undefined, |
| 276 | {struct, { |
| 277 | name_conflict_test_types, |
| 278 | second_chance |
| 279 | }}, |
| 280 | second_chance, #second_chance{}}, |
| 281 | {3, undefined, |
| 282 | {struct, { |
| 283 | name_conflict_test_types, |
| 284 | 'NOW_EAT_THIS' |
| 285 | }}, |
| 286 | 'NOW_EAT_THIS', #'NOW_EAT_THIS'{}}, |
| 287 | {4, undefined, |
| 288 | {struct, { |
| 289 | name_conflict_test_types, |
| 290 | 'TheEdgeCase' |
| 291 | }}, |
| 292 | 'TheEdgeCase', #'TheEdgeCase'{}}, |
| 293 | {5, undefined, |
| 294 | {struct, { |
| 295 | name_conflict_test_types, |
| 296 | 'Tricky_' |
| 297 | }}, |
| 298 | 'Tricky_', #'Tricky_'{}}, |
| 299 | {6, undefined, |
| 300 | {struct, { |
| 301 | name_conflict_test_types, |
| 302 | 'Nested' |
| 303 | }}, |
| 304 | 'Nested', undefined} |
| 305 | ]}, |
| 306 | name_conflict_test_types:struct_info_ext('Nested') |
| 307 | )}, |
| 308 | {"Problem_ extended definition", |
| 309 | ?_assertEqual( |
| 310 | {struct, [ |
| 311 | {1, undefined, bool, problem, undefined}, |
| 312 | {2, undefined, bool, 'Problem', undefined} |
| 313 | ]}, |
| 314 | name_conflict_test_types:struct_info_ext('Problem_') |
| 315 | )} |
| 316 | ]. |
alisdair sullivan | fb6ed7e | 2014-07-22 23:40:44 -0700 | [diff] [blame] | 317 | |
| 318 | service_info_test_() -> |
Sergei Elin | 4576409 | 2022-09-23 23:21:31 +0300 | [diff] [blame] | 319 | [ |
| 320 | {"event params", |
| 321 | ?_assertEqual( |
| 322 | {struct, [{1, {struct, {name_conflict_test_types, partial}}}]}, |
| 323 | extern_thrift:function_info(event, params_type) |
| 324 | )}, |
| 325 | {"event reply", |
| 326 | ?_assertEqual( |
| 327 | {struct, {name_conflict_test_types, delegate}}, |
| 328 | extern_thrift:function_info(event, reply_type) |
| 329 | )}, |
| 330 | {"event exceptions", |
| 331 | ?_assertEqual( |
| 332 | {struct, []}, |
| 333 | extern_thrift:function_info(event, exceptions) |
| 334 | )}, |
| 335 | {"Foo params", |
| 336 | ?_assertEqual( |
| 337 | {struct, [{1, {struct, {name_conflict_test_types, 'Nested'}}}]}, |
| 338 | extern_thrift:function_info('Foo', params_type) |
| 339 | )}, |
| 340 | {"Foo reply", |
| 341 | ?_assertEqual( |
| 342 | {struct, []}, |
| 343 | extern_thrift:function_info('Foo', reply_type) |
| 344 | )}, |
| 345 | {"Foo exceptions", |
| 346 | ?_assertEqual( |
| 347 | {struct, [{1, {struct, {name_conflict_test_types, 'Problem_'}}}]}, |
| 348 | extern_thrift:function_info('Foo', exceptions) |
| 349 | )} |
| 350 | ]. |