Improve this `unpipe` function?

Yes, any single pipes, though that particular case I did not account for! It does indeed work here though it adds new lines (which is a separate general issue I’m dealing with).

These were my test cases so far (not super thorough):

defp run(string, func) do
  result =
    string
    |> Sourceror.parse_string!()
    |> func.()
    |> Sourceror.to_string()

  result <> "\n"
end

describe "unpipe" do
  test "changes single pipes into inline calls" do
    source = ~S"""
    socket
    |> assign(:foo, "foo")
    """

    result = run(source, &unpipe/1)

    assert result == ~S"""
           assign(socket, :foo, "foo")
           """
  end

  test "leaves longer pipelines alone" do
    source = ~S"""
    socket
    |> assign(:foo, "foo")
    |> assign(:bar, "bar")
    """

    result = run(source, &unpipe/1)

    assert result == ~S"""
           socket
           |> assign(:foo, "foo")
           |> assign(:bar, "bar")
           """
  end

  test "handles nested pipes" do
    source = ~S"""
    foo
    |> bar()
    |> baz(fn n ->
      n
      |> bar()
      |> baz(fn m ->
        m
        |> foo()
      end)
    end)
    """

    result = run(source, &unpipe/1)

    assert result == ~S"""
           foo
           |> bar()
           |> baz(fn n ->
             n
             |> bar()
             |> baz(fn m ->
               foo(m)
             end)
           end)
           """
  end