defmodule LivebookWeb.Helpers.ANSITest do use ExUnit.Case, async: true alias LivebookWeb.Helpers.ANSI describe "ansi_string_to_html/2" do test "converts ANSI escape codes to span tags" do assert ~s{cat} == ANSI.ansi_string_to_html("\e[34mcat\e[0m") |> Phoenix.HTML.safe_to_string() assert ~s{cat} == ANSI.ansi_string_to_html("\e[44mcat\e[0m") |> Phoenix.HTML.safe_to_string() assert ~s{cat} == ANSI.ansi_string_to_html("\e[1mcat\e[0m") |> Phoenix.HTML.safe_to_string() assert ~s{cat} == ANSI.ansi_string_to_html("\e[4mcat\e[0m") |> Phoenix.HTML.safe_to_string() end test "renders 8-bit rgb colors as regular rgb" do assert ~s{cat} == ANSI.ansi_string_to_html("\e[38;5;67mcat\e[0m") |> Phoenix.HTML.safe_to_string() end test "renders 8-bit grayscale as regular rgb" do assert ~s{cat} == ANSI.ansi_string_to_html("\e[38;5;240mcat\e[0m") |> Phoenix.HTML.safe_to_string() end test "escapes HTML in the resulting string" do assert ~s{<div>} == ANSI.ansi_string_to_html("