Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(reduced_test_case).
- -define(NODEBUG, 1).
- -include_lib("eunit/include/eunit.hrl").
- -behavior(gen_server).
- %-compile(export_all).
- -export([init/1, code_change/3, handle_call/3, handle_cast/2, handle_info/2, terminate/2]).
- -export([start/0]).
- -define(SERVER, ?MODULE).
- start() ->
- {ok, PID} = gen_server:start_link({local, ?SERVER}, ?MODULE, [], []),
- PID ! {hi, [1040,1044]}, % try a string/list
- PID ! {hi, <<"\xa9">>}, % try a latin1 binary
- PID ! {hi, <<"\xd0\x90\xd0\x94">>}, % try a utf8 binary
- PID ! {hi, [[1040,1044], <<"\xa9">>, <<"\xd0\x90\xd0\x94">>]}, % all together in a iolist
- {ok, PID}.
- to_binary(IoList) when is_binary(IoList) ->
- IoList;
- to_binary(IoList) ->
- to_binary(IoList, []).
- to_binary([], Acc) ->
- Acc;
- to_binary([Head | Tail], Acc) when is_binary(Head) ->
- to_binary(Tail, [Acc | Head]);
- to_binary(IoList, Acc) ->
- case unicode:characters_to_binary(IoList) of
- {error, Bin, Rest} ->
- to_binary(Rest, [Acc|Bin]);
- {incomplete, Bin1, Bin2} ->
- [Acc | [Bin1, Bin2]];
- Bin ->
- Bin
- end.
- print(Data) ->
- port_command(stdout, [to_binary(Data), "\n"]).
- init(_) ->
- StdOut = open_port("/dev/stdout", [binary, out]),
- register(stdout, StdOut),
- {ok, []}.
- handle_info({hi, Data}, State) ->
- print(Data),
- {noreply, State};
- handle_info(_Msg, State) -> {noreply, State}.
- handle_call(_Msg, _Caller, State) -> {noreply, State}.
- handle_cast(_Msg, State) -> {noreply, State}.
- terminate(_Reason, _State) -> ok.
- code_change(_OldVersion, State, _Extra) -> {ok, State}.
Add Comment
Please, Sign In to add comment