@@ -142,10 +142,54 @@ protocol_with_typedefs_test() ->
142142 # function {name = " ping" , extra = undefined }]},
143143 parse_idl (" protocol_with_typedefs" )).
144144
145+ array_types_test () ->
146+ Probes =
147+ [{int , " int" },
148+ {{decimal , 1 , 2 }, " decimal(1, 2)" },
149+ {null , " null" },
150+ {{custom , " MyType" }, " MyType" },
151+ {{custom , " my_ns.MyType" }, " my_ns.MyType" },
152+ {{union , [int , null ]}, " union{int, null}" },
153+ {{array , int }, " array<int>" },
154+ {{map , int }, " map<int>" }],
155+ lists :foreach (
156+ fun ({ExpectType , IdlType }) ->
157+ test_field_type ({array , ExpectType }, " array<" ++ IdlType ++ " >" )
158+ end , Probes ).
159+
160+ map_types_test () ->
161+ Probes =
162+ [{int , " int" },
163+ {{custom , " MyType" }, " MyType" },
164+ {{array , int }, " array<int>" },
165+ {{map , int }, " map<int>" }],
166+ lists :foreach (
167+ fun ({ExpectType , IdlType }) ->
168+ test_field_type ({map , ExpectType }, " map<" ++ IdlType ++ " >" )
169+ end , Probes ).
170+
171+ % % Helpers
172+
173+ test_field_type (ExpectType , IdlType ) ->
174+ Idl = (" protocol P {"
175+ " record R { " ++ IdlType ++ " f; }"
176+ " }" ),
177+ # protocol {
178+ definitions =
179+ [# record {
180+ fields =
181+ [# field {type = Type }]}]} = parse_str (Idl ),
182+ ? assertEqual (ExpectType , Type ,
183+ #{proto => Idl ,
184+ type => IdlType }).
185+
145186parse_idl (Name ) ->
146187 File = " test/data/" ++ Name ++ " .avdl" ,
147188 {ok , B } = file :read_file (File ),
148- {ok , T0 , _ } = avro_idl_lexer :string (binary_to_list (B )),
189+ parse_str (binary_to_list (B )).
190+
191+ parse_str (Str ) ->
192+ {ok , T0 , _ } = avro_idl_lexer :string (Str ),
149193 % % ?debugFmt("Name: ~p~nTokens:~n~p", [Name, T0]),
150194 T = avro_idl_lexer :preprocess (T0 , [drop_comments , trim_doc ]),
151195 {ok , Tree } = avro_idl_parser :parse (T ),
0 commit comments