Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

more tests

  • Loading branch information...
commit c13a787c4c77b24f7f46614a372c20dce0349856 1 parent e6661cd
David Åberg authored
2  src/protobuffs_compile_lib.erl
@@ -393,7 +393,7 @@ filter_decode_extensions_clause(Msgs,[{MsgName,_,Extends}|Tail],
393 393 [{integer,L,FNum},
394 394 {atom,L,FName},
395 395 {atom,L,Type},
396   - erl_parse:abstract(Opts)
  396 + set_line_number(L,erl_parse:abstract(Opts))
397 397 ]
398 398 },
399 399 Acc}
54 test/protobuffs_compile_tests.erl
@@ -457,26 +457,47 @@ test_function_to_record() ->
457 457 test_function_decode_extentions() ->
458 458 Name = "name",
459 459 Fields = [],
460   - Extends = [],
461   - Messages = [{Name,Fields,Extends}],
  460 + Extends = [{1, rule, "int32", "field1", []}],
  461 + Messages1 = [{Name,Fields,[]}],
  462 + Messages2 = [{Name,Fields,disallowed}],
  463 + Messages3 = [{Name,Fields,Extends}],
462 464 Basename = ignored,
463 465 Enums = [],
464 466 Acc = [],
465 467
466 468 DecodeExtensionsFmt = "decode_extensions(#~s{'$extensions' = Extensions} = Record) ->"
467   - ++ " Types = [],"
468   - ++" NewExtensions = decode_extensions(Types, dict:to_list(Extensions), []),"
469   - ++ " Record#~s{'$extensions' = NewExtensions};"
470   - ++ " decode_extensions(Record) -> Record.",
471   -
472   - TemplateFunction = string_format(DecodeExtensionsFmt,["pikachu","pikachu"]),
473   - ExpectedFunction = string_format(DecodeExtensionsFmt,[Name,Name]),
  469 + " Types = ~s,"
  470 + " NewExtensions = decode_extensions(Types, dict:to_list(Extensions), []),"
  471 + " Record#~s{'$extensions' = NewExtensions};",
  472 + DecodeExtensionsDefaultFmt = " decode_extensions(Record) -> Record.",
  473 +
  474 + TemplateFunction = string_format(DecodeExtensionsFmt++DecodeExtensionsDefaultFmt,
  475 + ["pikachu","[]","pikachu"]),
  476 + ExpectedFunction1 = string_format(DecodeExtensionsFmt++DecodeExtensionsDefaultFmt,
  477 + [Name,"[]",Name]),
  478 + ExpectedFunction2 = DecodeExtensionsDefaultFmt,
  479 + ExpectedFunction3 = string_format(DecodeExtensionsFmt++DecodeExtensionsDefaultFmt,
  480 + [Name,"[{1, field1, int32, []}]",Name]),
474 481
475 482 {ok,Function} = parse(TemplateFunction),
476   - {ok,FilterdFunction} = parse(ExpectedFunction),
  483 + {ok,FilterdFunction1} = parse(ExpectedFunction1),
  484 + {ok,FilterdFunction2} = parse(ExpectedFunction2),
  485 + {ok,FilterdFunction3} = parse(ExpectedFunction3),
477 486
478   - [?_assertEqual([FilterdFunction],
479   - protobuffs_compile_lib:filter_forms(Messages,
  487 + [?_assertEqual([FilterdFunction1],
  488 + protobuffs_compile_lib:filter_forms(Messages1,
  489 + [],
  490 + [Function],
  491 + Basename,
  492 + Acc)),
  493 + ?_assertEqual([FilterdFunction2],
  494 + protobuffs_compile_lib:filter_forms(Messages2,
  495 + [],
  496 + [Function],
  497 + Basename,
  498 + Acc)),
  499 + ?_assertEqual([FilterdFunction3],
  500 + protobuffs_compile_lib:filter_forms(Messages3,
480 501 [],
481 502 [Function],
482 503 Basename,
@@ -485,7 +506,7 @@ test_function_decode_extentions() ->
485 506 test_function_extension_size() ->
486 507 Name = "name",
487 508 Fields = [],
488   - Extends = [],
  509 + Extends = [{1, rule, "int32", "field1", []}],
489 510 Messages1 = [{Name,Fields,[]}],
490 511 Messages2 = [{Name,Fields,disallowed}],
491 512 Messages3 = [{Name,Fields,Extends}],
@@ -505,6 +526,7 @@ test_function_extension_size() ->
505 526 {ok,Function} = parse(TemplateFunction),
506 527 {ok,FilterdFunction1} = parse(ExpectedFunction1),
507 528 {ok,FilterdFunction2} = parse(ExpectedFunction2),
  529 + {ok,FilterdFunction3} = parse(ExpectedFunction1),
508 530
509 531 [?_assertEqual([FilterdFunction1],
510 532 protobuffs_compile_lib:filter_forms(Messages1,
@@ -517,6 +539,12 @@ test_function_extension_size() ->
517 539 [],
518 540 [Function],
519 541 Basename,
  542 + Acc)),
  543 + ?_assertEqual([FilterdFunction3],
  544 + protobuffs_compile_lib:filter_forms(Messages3,
  545 + [],
  546 + [Function],
  547 + Basename,
520 548 Acc))].
521 549
522 550 test_function_has_extension() ->

0 comments on commit c13a787

Please sign in to comment.
Something went wrong with that request. Please try again.