Files
erlang/test/ezap_val_tests.erl
zeekay ce51a2074b Complete Cap'n Proto -> ZAP rebrand for ezap Erlang binding
Mechanical, byte-balanced rename across the full tree (1648 ins / 1648 del):
- ecapnp -> ezap, capnpc-erl -> zapc-erl, *_capnp.erl -> *_zap.erl
- .capnp schemas -> .zap (schema, rpc, c++, test, addressbook, calculator)
- "Cap'n Proto" prose -> "Zap" in docs and module @doc comments
- 58 renamed/modified source, header, schema, sample and test files

Brand-neutrality (canonical zap-proto):
- README + overview.edoc project URLs -> zap-proto.io / github.com/zap-proto/erlang
- doc links -> zap-proto.dev (encoding, otherlang, sdks/erlang)
- generator banner (ezap_compiler) + all 6 generated modules ->
  https://github.com/zap-proto/erlang
- Makefile dep_zap_test -> https://github.com/zap-proto/zap_test.git

Build hygiene:
- modernize git:// -> https:// for dep_eunit_formatters (git:// is dead on GitHub)

Upstream license/author attribution headers (Andreas Stenius) preserved.
Tests unchanged: proper_SUITE / ezap_props property tests + eunit suite.
2026-06-19 23:44:06 -07:00

65 lines
2.3 KiB
Erlang

%%
%% Copyright 2013, Andreas Stenius <[email protected]>
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
-module(ezap_val_tests).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
get_test() ->
?assertEqual(false, ezap_val:get(bool, <<0:1>>, <<0:1>>)),
?assertEqual(true, ezap_val:get(bool, <<1:1>>, <<0:1>>)),
?assertEqual(true, ezap_val:get(bool, <<0:1>>, <<1:1>>)),
?assertEqual(false, ezap_val:get(bool, <<1:1>>, <<1:1>>)).
set_test() ->
?assertEqual(<<0:1>>, ezap_val:set(bool, false, <<0:1>>)),
?assertEqual(<<1:1>>, ezap_val:set(bool, true, <<0:1>>)),
?assertEqual(<<1:1>>, ezap_val:set(bool, false, <<1:1>>)),
?assertEqual(<<0:1>>, ezap_val:set(bool, true, <<1:1>>)).
inf_nan_32_test() ->
Pinf = <<0,0,128,127>>,
Ninf = <<0,0,128,255>>,
NaN = <<0,0,192,127>>,
?assertEqual(Pinf, ezap_val:set(float32, inf)),
?assertEqual(Ninf, ezap_val:set(float32, '-inf')),
?assertEqual(NaN, ezap_val:set(float32, nan)),
?assertEqual(inf, ezap_val:get(float32, Pinf)),
?assertEqual('-inf', ezap_val:get(float32, Ninf)),
?assertEqual(nan, ezap_val:get(float32, NaN)).
inf_nan_64_test() ->
Pinf = <<0:32, 0,0,240,127>>,
Ninf = <<0:32, 0,0,240,255>>,
NaN = <<0:32, 0,0,248,127>>,
?assertEqual(Pinf, ezap_val:set(float64, inf)),
?assertEqual(Ninf, ezap_val:set(float64, '-inf')),
?assertEqual(NaN, ezap_val:set(float64, nan)),
?assertEqual(inf, ezap_val:get(float64, Pinf)),
?assertEqual('-inf', ezap_val:get(float64, Ninf)),
?assertEqual(nan, ezap_val:get(float64, NaN)).
float_test() ->
F = 1234.5,
F32 = ezap_val:set(float32, F),
F64 = ezap_val:set(float64, F),
?assertEqual(4, size(F32)),
?assertEqual(8, size(F64)),
?assertEqual(F, ezap_val:get(float32, F32)),
?assertEqual(F, ezap_val:get(float64, F64)).
-endif.