THRIFT-2721: reduce complexity of generated erlang code and add tests