Skip to content

Commit a6cc84c

Browse files
committed
indent the text
1 parent 11d9944 commit a6cc84c

File tree

5 files changed

+50
-19
lines changed

5 files changed

+50
-19
lines changed

lib/elixir/lib/exception.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,11 +1997,22 @@ defmodule Protocol.UndefinedError do
19971997

19981998
@impl true
19991999
def message(%{protocol: protocol, value: value, description: description}) do
2000+
inspected =
2001+
value
2002+
|> inspect(pretty: true)
2003+
|> String.replace(~r/^(?=.+)/m, " ")
2004+
20002005
"protocol #{inspect(protocol)} not implemented for type " <>
20012006
value_type(value) <>
20022007
maybe_description(description) <>
20032008
maybe_available(protocol) <>
2004-
"\n\nGot value:\n\n#{inspect(value, pretty: true)}"
2009+
"""
2010+
2011+
2012+
Got value:
2013+
2014+
#{inspected}
2015+
"""
20052016
end
20062017

20072018
defp value_type(%{__struct__: struct}), do: "#{inspect(struct)} (a struct)"

lib/elixir/test/elixir/inspect_test.exs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -530,16 +530,16 @@ defmodule Inspect.MapTest do
530530
531531
Got value:
532532
533-
#Inspect.Error<
534-
got ArgumentError with message:
533+
#Inspect.Error<
534+
got ArgumentError with message:
535535
536-
"""
537-
errors were found at the given arguments:
536+
"""
537+
errors were found at the given arguments:
538538
539-
* 1st argument: not an atom
540-
"""
539+
* 1st argument: not an atom
540+
"""
541541
542-
while inspecting:
542+
while inspecting:
543543
544544
'''
545545

@@ -934,7 +934,7 @@ defmodule Inspect.CustomProtocolTest do
934934
935935
Got value:
936936
937-
%Inspect.CustomProtocolTest.MissingImplementation{}
937+
%Inspect.CustomProtocolTest.MissingImplementation{}
938938
"""
939939
940940
while inspecting:
@@ -965,7 +965,7 @@ defmodule Inspect.CustomProtocolTest do
965965
966966
Got value:
967967
968-
%Inspect.CustomProtocolTest.MissingImplementation{}
968+
%Inspect.CustomProtocolTest.MissingImplementation{}
969969
"""
970970
971971
while inspecting:

lib/elixir/test/elixir/protocol/consolidation_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ defmodule Protocol.ConsolidationTest do
184184
message =
185185
"protocol Protocol.ConsolidationTest.Sample not implemented for type Atom. " <>
186186
"This protocol is implemented for the following type(s): Protocol.ConsolidationTest.ImplStruct" <>
187-
"\n\nGot value:\n\n:foo"
187+
"\n\nGot value:\n\n :foo\n"
188188

189189
assert_raise Protocol.UndefinedError, message, fn ->
190190
sample = String.to_atom("Elixir.Protocol.ConsolidationTest.Sample")

lib/elixir/test/elixir/protocol_test.exs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,14 @@ defmodule ProtocolTest do
113113
end
114114

115115
test "protocol not implemented" do
116-
message = "protocol ProtocolTest.Sample not implemented for type Atom\n\nGot value:\n\n:foo"
116+
message =
117+
"""
118+
protocol ProtocolTest.Sample not implemented for type Atom
119+
120+
Got value:
121+
122+
:foo
123+
"""
117124

118125
assert_raise Protocol.UndefinedError, message, fn ->
119126
sample = String.to_atom("Elixir.ProtocolTest.Sample")

lib/elixir/test/elixir/string/chars_test.exs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,36 @@ defmodule String.Chars.ErrorsTest do
105105

106106
test "bitstring" do
107107
message =
108-
"protocol String.Chars not implemented for type BitString, cannot convert a bitstring to a string\n\nGot value:\n\n<<0, 1::size(4)>>"
108+
"""
109+
protocol String.Chars not implemented for type BitString, cannot convert a bitstring to a string
110+
111+
Got value:
112+
113+
<<0, 1::size(4)>>
114+
"""
109115

110116
assert_raise Protocol.UndefinedError, message, fn ->
111117
to_string(<<1::size(12)-integer-signed>>)
112118
end
113119
end
114120

115121
test "tuple" do
116-
message = "protocol String.Chars not implemented for type Tuple\n\nGot value:\n\n{1, 2, 3}"
122+
message = """
123+
protocol String.Chars not implemented for type Tuple
124+
125+
Got value:
126+
127+
{1, 2, 3}
128+
"""
117129

118130
assert_raise Protocol.UndefinedError, message, fn ->
119131
to_string({1, 2, 3})
120132
end
121133
end
122134

123135
test "PID" do
124-
message = ~r"^protocol String\.Chars not implemented for type PID\n\nGot value:\n\n#PID<.+?>$"
136+
message =
137+
~r"^protocol String\.Chars not implemented for type PID\n\nGot value:\n\n #PID<.+?>$"
125138

126139
assert_raise Protocol.UndefinedError, message, fn ->
127140
to_string(self())
@@ -130,7 +143,7 @@ defmodule String.Chars.ErrorsTest do
130143

131144
test "ref" do
132145
message =
133-
~r"^protocol String\.Chars not implemented for type Reference\n\nGot value:\n\n#Reference<.+?>$"
146+
~r"^protocol String\.Chars not implemented for type Reference\n\nGot value:\n\n #Reference<.+?>$"
134147

135148
assert_raise Protocol.UndefinedError, message, fn ->
136149
to_string(make_ref()) == ""
@@ -139,7 +152,7 @@ defmodule String.Chars.ErrorsTest do
139152

140153
test "function" do
141154
message =
142-
~r"^protocol String\.Chars not implemented for type Function\n\nGot value:\n\n#Function<.+?>$"
155+
~r"^protocol String\.Chars not implemented for type Function\n\nGot value:\n\n #Function<.+?>$"
143156

144157
assert_raise Protocol.UndefinedError, message, fn ->
145158
to_string(fn -> nil end)
@@ -150,7 +163,7 @@ defmodule String.Chars.ErrorsTest do
150163
[port | _] = Port.list()
151164

152165
message =
153-
~r"^protocol String\.Chars not implemented for type Port\n\nGot value:\n\n#Port<.+?>$"
166+
~r"^protocol String\.Chars not implemented for type Port\n\nGot value:\n\n #Port<.+?>$"
154167

155168
assert_raise Protocol.UndefinedError, message, fn ->
156169
to_string(port)
@@ -159,7 +172,7 @@ defmodule String.Chars.ErrorsTest do
159172

160173
test "user-defined struct" do
161174
message =
162-
"protocol String\.Chars not implemented for type String.Chars.ErrorsTest.Foo (a struct)\n\nGot value:\n\n%String.Chars.ErrorsTest.Foo{foo: \"bar\"}"
175+
"protocol String\.Chars not implemented for type String.Chars.ErrorsTest.Foo (a struct)\n\nGot value:\n\n %String.Chars.ErrorsTest.Foo{foo: \"bar\"}\n"
163176

164177
assert_raise Protocol.UndefinedError, message, fn ->
165178
to_string(%Foo{})

0 commit comments

Comments
 (0)