Skip to content

Commit a13bb88

Browse files
mworrellCopilotCopilot
authored
Upgrade deps. Add extra cases to z_convert:to_bool/1 (#114)
* Upgrade deps. Add extra cases to z_convert:to_bool/1 * Update src/z_convert.erl Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add EUnit tests for new to_bool/1 and to_bool_strict/1 atom cases Agent-Logs-Url: https://github.com/zotonic/z_stdlib/sessions/591ecb8b-e4b8-4af7-96f8-5b583c9e720b Co-authored-by: mworrell <38268+mworrell@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mworrell <38268+mworrell@users.noreply.github.com>
1 parent d383b8e commit a13bb88

3 files changed

Lines changed: 35 additions & 9 deletions

File tree

rebar.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{"1.2.0",
2-
[{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.13.0">>},0},
3-
{<<"qdate_localtime">>,{pkg,<<"qdate_localtime">>,<<"1.2.1">>},0},
2+
[{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.16.0">>},0},
3+
{<<"qdate_localtime">>,{pkg,<<"qdate_localtime">>,<<"1.2.2">>},0},
44
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.7">>},1},
55
{<<"tls_certificate_check">>,
6-
{pkg,<<"tls_certificate_check">>,<<"1.24.0">>},
6+
{pkg,<<"tls_certificate_check">>,<<"1.32.0">>},
77
0}]}.
88
[
99
{pkg_hash,[
10-
{<<"cowlib">>, <<"DB8F7505D8332D98EF50A3EF34B34C1AFDDEC7506E4EE4DD4A3A266285D282CA">>},
11-
{<<"qdate_localtime">>, <<"72E1034DC6B7FEE8F588281EDDD0BD0DC5260005D758052F50634D265D382C18">>},
10+
{<<"cowlib">>, <<"54592074EBBBB92EE4746C8A8846E5605052F29309D3A873468D76CDF932076F">>},
11+
{<<"qdate_localtime">>, <<"43E1B20102F50A8B2A2BE7042C2F6BE989AD96CA2CC319DB5DF56E122E8873F6">>},
1212
{<<"ssl_verify_fun">>, <<"354C321CF377240C7B8716899E182CE4890C5938111A1296ADD3EC74CF1715DF">>},
13-
{<<"tls_certificate_check">>, <<"D00E2887551FF8CDAE4D0340D90D9FCBC4943C7B5F49D32ED4BC23AFF4DB9A44">>}]},
13+
{<<"tls_certificate_check">>, <<"A9BA9F1EA59F6728F564BC990047B56539C48F17866C2DEFA51D3C872A8DCDF6">>}]},
1414
{pkg_hash_ext,[
15-
{<<"cowlib">>, <<"E1E1284DC3FC030A64B1AD0D8382AE7E99DA46C3246B815318A4B848873800A4">>},
16-
{<<"qdate_localtime">>, <<"1109958D205C65C595C8C5694CB83EBAF2DBE770CF902E4DCE8AFB2C4123764D">>},
15+
{<<"cowlib">>, <<"7F478D80D66B747344F0EA7708C187645CFCC08B11AA424632F78E25BF05DB51">>},
16+
{<<"qdate_localtime">>, <<"A38D5F1C5AE14B22F471E442B262AECCAFB915B664C7C364443DC73179C50FDA">>},
1717
{<<"ssl_verify_fun">>, <<"FE4C190E8F37401D30167C8C405EDA19469F34577987C76DDE613E838BBC67F8">>},
18-
{<<"tls_certificate_check">>, <<"90B25A58EE433D91C17F036D4D354BF8859A089BFDA60E68A86F8EECAE45EF1B">>}]}
18+
{<<"tls_certificate_check">>, <<"38E38DB768244D808E11ED27F812E7D927EA5F999007B07D0473DB44D7F7CC51">>}]}
1919
].

src/z_convert.erl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ to_float(L) when is_list(L) ->
151151

152152
%% @doc Quite loose conversion of values to boolean
153153
-spec to_bool(term()) -> boolean().
154+
to_bool(true) -> true;
155+
to_bool(false) -> false;
156+
to_bool('TRUE') -> true;
157+
to_bool('FALSE') -> false;
158+
to_bool(yes) -> true;
159+
to_bool(no) -> false;
160+
to_bool('YES') -> true;
161+
to_bool('NO') -> false;
154162
to_bool("false") -> false;
155163
to_bool("FALSE") -> false;
156164
to_bool("n") -> false;
@@ -173,6 +181,7 @@ to_bool(V) -> to_bool_strict(V).
173181
% @doc Convert values to boolean values according to the Django rules
174182
-spec to_bool_strict(term()) -> boolean().
175183
to_bool_strict(undefined) -> false;
184+
to_bool_strict(true) -> true;
176185
to_bool_strict(false) -> false;
177186
to_bool_strict(0) -> false;
178187
to_bool_strict(+0.0) -> false;

test/z_convert_test.erl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ convert_datetime_test() ->
4545
?assertDatetime({{2011,10,6},{14,44,0}}, "2011-10-06T16:44:00+0200"),
4646
ok.
4747

48+
convert_bool_test() ->
49+
?assertEqual(true, z_convert:to_bool(true)),
50+
?assertEqual(false, z_convert:to_bool(false)),
51+
?assertEqual(true, z_convert:to_bool('TRUE')),
52+
?assertEqual(false, z_convert:to_bool('FALSE')),
53+
?assertEqual(true, z_convert:to_bool(yes)),
54+
?assertEqual(false, z_convert:to_bool(no)),
55+
?assertEqual(true, z_convert:to_bool('YES')),
56+
?assertEqual(false, z_convert:to_bool('NO')),
57+
ok.
58+
59+
convert_bool_strict_test() ->
60+
?assertEqual(true, z_convert:to_bool_strict(true)),
61+
?assertEqual(false, z_convert:to_bool_strict(false)),
62+
?assertEqual(false, z_convert:to_bool_strict(undefined)),
63+
ok.
64+
4865
datetime_to_iso_test() ->
4966
?assertEqual(<<"2010-09-02T10:11:56Z">>, z_convert:to_isotime({{2010,9,2},{10,11,56}})),
5067
?assertEqual(<<"2010-09-02T01:01:01Z">>, z_convert:to_isotime({{2010,9,2},{1,1,1}})),

0 commit comments

Comments
 (0)