%% Generator for the golden ETF vectors used in tests/test_etf.py. %% Re-run when adding new test cases: %% %% erlc -o /tmp docs/etf_vectors.erl %% erl -noshell -pa /tmp -eval 'etf_vectors:main([]), init:stop().' %% cat /tmp/etf_vectors.txt %% -module(etf_vectors). -export([main/1]). main(_) -> Terms = [ {small_int_0, 0}, {small_int_42, 42}, {small_int_255, 255}, {int_256, 256}, {int_neg_1, -1}, {int_max32, 2147483647}, {int_min32, -2147483648}, {big_pos, 9999999999999999}, {big_neg, -9999999999999999}, {atom_hello, hello}, {atom_true, true}, {atom_false, false}, {atom_nil, nil}, {atom_unicode, 'привет'}, {binary_empty, <<>>}, {binary_hi, <<"hi">>}, {binary_utf8, <<"héllo"/utf8>>}, {tuple_empty, {}}, {tuple_pair, {ok, <<"value">>}}, {tuple_triple, {1, 2, 3}}, {list_empty, []}, {list_ints, [1, 2, 3]}, {list_mixed, [hello, <<"world">>, 42]}, {nested, {gen_call, [{node, 'wallet@cammy'}], {get_balance, xmr}}} ], Out = [ io_lib:format("~s|~s~n", [atom_to_list(N), bin_to_hex(term_to_binary(T))]) || {N, T} <- Terms ], ok = file:write_file("/tmp/etf_vectors.txt", iolist_to_binary(Out)). bin_to_hex(B) -> << <<(hex(N div 16)), (hex(N rem 16))>> || <> <= B >>. hex(N) when N < 10 -> $0 + N; hex(N) -> $a + N - 10.