gmbytecode/test/gmb_fate_asm_test.erl
Craig Everett 1cdcb9150b
All checks were successful
Gajumaru Bytecode Tests / tests (push) Successful in -3m34s
Revamp (#235)
Add Gitea tests
Rename
Remove oracle references
Package for zx

Reviewed-on: #235
Reviewed-by: dimitar.p.ivanov <dimitarivanov@qpq.swiss>
Co-authored-by: Craig Everett <zxq9@zxq9.com>
Co-committed-by: Craig Everett <zxq9@zxq9.com>
2025-01-22 21:12:54 +09:00

67 lines
1.6 KiB
Erlang

%%%-------------------------------------------------------------------
%%% @copyright (C) 2025, QPQ AG
%%% @copyright (C) 2018, Aeternity Anstalt
%%% @doc Basic tests for Fate serialization
%%%
%%% To run:
%%% TEST=gmb_fate_asm_test rebar3 eunit
%%%
%%% @end
%%%-------------------------------------------------------------------
-module(gmb_fate_asm_test).
-include_lib("eunit/include/eunit.hrl").
asm_path() ->
filename:join(code:lib_dir(gmbytecode, test), "asm_code").
file_path(File) ->
filename:join(asm_path(), File) ++ ".fate".
read_file(File) ->
FilePath = file_path(File),
Asm = gmb_fate_asm:read_file(FilePath),
Asm.
assemble(Asm) ->
gmb_fate_asm:asm_to_bytecode(Asm, []).
asm_disasm_idenity_test() ->
check_roundtrip(identity).
asm_disasm_files_test_() ->
[{lists:flatten(io_lib:format("~p", [X])),
fun() -> check_roundtrip(X) end}
|| X <- sources()].
sources() ->
[ "arith"
, "bool"
, "comp"
, "jumpif"
, "map"
, "memory"
, "remote"
, "test"
, "tuple"
, "mapofmap"
, "immediates"
, "names"
, "meta"
].
check_roundtrip(File) ->
AssemblerCode = read_file(File),
{_Env, ByteCode} = assemble(AssemblerCode),
FateCode = gmb_fate_code:deserialize(ByteCode),
DissasmCode = gmb_fate_asm:to_asm(FateCode),
{_Env2, ByteCode2} = assemble(DissasmCode),
ByteCode3 = gmb_fate_code:serialize(FateCode),
Code1 = gmb_fate_asm:strip(ByteCode),
Code2 = gmb_fate_asm:strip(ByteCode2),
Code3 = gmb_fate_asm:strip(ByteCode3),
?assertEqual(Code1, Code2),
?assertEqual(Code1, Code3).