From 5df23c05c18b9b214e8293f4c8d1d750cb0802c1 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Mon, 28 Apr 2025 11:51:23 +0200 Subject: [PATCH] test case for 'switch' --- src/gmser_dyn.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gmser_dyn.erl b/src/gmser_dyn.erl index 8bb0930..a39843c 100644 --- a/src/gmser_dyn.erl +++ b/src/gmser_dyn.erl @@ -797,6 +797,7 @@ dynamic_types_test_() -> [ ?_test(revert_to_default_types()) , ?_test(t_typed_map()) , ?_test(t_alts()) + , ?_test(t_switch()) , ?_test(t_anyints()) , ?_test(t_missing_labels()) ]. @@ -920,6 +921,14 @@ t_alts() -> t_round_trip_typed(#{alt => [negint, int]}, 4), ok. +t_switch() -> + T = #{switch => #{a => int, b => binary}}, + t_round_trip_typed(T, #{a => 17}), + t_round_trip_typed(T, #{b => <<"foo">>}), + ?assertError({illegal,int,<<"foo">>}, encode_typed(T, #{a => <<"foo">>})), + MMap = #{a => 17, b => <<"foo">>}, + ?assertError({illegal, singleton_map, MMap}, encode_typed(T, MMap)). + t_anyints() -> t_round_trip_typed(anyint, -5), t_round_trip_typed(anyint, 5), @@ -947,7 +956,7 @@ t_new_version() -> Types2 = types_from_list([{vsn, V2}, {modify, {msg1, {int, int, int}}}], Types1), Enc21 = encode_typed(msg1, T2, Types1), - try encode_typed(msg1, T2, Types2) catch error:_ -> ok end, + ?assertError({illegal,{int,int,int},T2}, encode_typed(msg1, T2, Types2)), T3 = {3,5,7}, Enc32 = encode_typed(msg1, T3, Types2), T3 = decode(Enc32, Types2).