Respect \r in individual stdout results

This commit is contained in:
Jonatan Kłosko 2021-12-22 15:48:35 +01:00
parent 4badf40afc
commit 87a17f1fc5
2 changed files with 25 additions and 0 deletions

View file

@ -854,6 +854,8 @@ defmodule Livebook.Session.Data do
)
end
defp add_output([], output) when is_binary(output), do: [apply_rewind(output)]
defp add_output([], output), do: [output]
defp add_output([head | tail], output) when is_binary(head) and is_binary(output) do

View file

@ -1814,6 +1814,29 @@ defmodule Livebook.Session.DataTest do
}, []} = Data.apply_operation(data, operation)
end
test "normalizes individual stdout results to respect CR" do
data =
data_after_operations!([
{:insert_section, self(), 0, "s1"},
{:insert_cell, self(), "s1", 0, :elixir, "c1"},
{:set_runtime, self(), NoopRuntime.new()},
{:queue_cells_evaluation, self(), ["c1"]}
])
operation = {:add_cell_evaluation_output, self(), "c1", "Hola\rHey"}
assert {:ok,
%{
notebook: %{
sections: [
%{
cells: [%{outputs: ["Hey"]}]
}
]
}
}, []} = Data.apply_operation(data, operation)
end
test "normalizes consecutive stdout results to respect CR" do
data =
data_after_operations!([