2021-01-11 19:05:05 +08:00
|
|
|
defmodule LiveBook.Evaluator.IOProxyTest do
|
|
|
|
use ExUnit.Case, async: true
|
|
|
|
|
|
|
|
alias LiveBook.Evaluator.IOProxy
|
|
|
|
|
|
|
|
setup do
|
|
|
|
{:ok, io} = IOProxy.start_link()
|
|
|
|
IOProxy.configure(io, self(), :ref)
|
|
|
|
%{io: io}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Test the basic ways users interact with :stdio
|
|
|
|
|
|
|
|
test "IO.puts", %{io: io} do
|
|
|
|
IO.puts(io, "hey")
|
2021-02-11 19:42:17 +08:00
|
|
|
assert_received {:evaluation_stdout, :ref, "hey\n"}
|
2021-01-11 19:05:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test "IO.write", %{io: io} do
|
|
|
|
IO.write(io, "hey")
|
2021-02-11 19:42:17 +08:00
|
|
|
assert_received {:evaluation_stdout, :ref, "hey"}
|
2021-01-11 19:05:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test "IO.inspect", %{io: io} do
|
|
|
|
IO.inspect(io, %{}, [])
|
2021-02-11 19:42:17 +08:00
|
|
|
assert_received {:evaluation_stdout, :ref, "%{}\n"}
|
2021-01-11 19:05:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test "IO.read", %{io: io} do
|
|
|
|
assert IO.read(io, :all) == {:error, :enotsup}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "IO.gets", %{io: io} do
|
|
|
|
assert IO.gets(io, "> ") == {:error, :enotsup}
|
|
|
|
end
|
|
|
|
end
|