Skip to content

Commit 66e0c53

Browse files
author
José Valim
committed
Revert "Deprecate =~"
This reverts commit e42e3e5.
1 parent d7bf2aa commit 66e0c53

29 files changed

+257
-188
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* Deprecations
1717
* [Kernel] `binary_to_term/1`, `binary_to_term/2`, `term_to_binary/1` and `term_to_binary/2` are deprecated in favor of their counterparts in the `:erlang` module
1818
* [Kernel] `//` for default arguments is deprecated in favor of `\\`. This is a soft deprecation, no warnings will be emitted for it in this release
19-
* [Kernel] Deprecate `=~` in favor of `String.contains?/2` (for strings) and `String.match?/2` (for regexes)
2019
* [Kernel] Deprecate `@behavior` in favor of `@behaviour`
2120
* [Record] Deprecate `to_keywords`, `getter` and `list getter` functionalities in `defrecordp`
2221

lib/elixir/lib/kernel.ex

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,15 +1789,32 @@ defmodule Kernel do
17891789
end
17901790
end
17911791

1792-
@doc false
1792+
@doc """
1793+
Matches the term on the left against the regular expression or string on the
1794+
right. Returns true if `left` matches `right` (if it's a regular expression)
1795+
or contains `right` (if it's a string).
1796+
1797+
## Examples
1798+
1799+
iex> "abcd" =~ %r/c(d)/
1800+
true
1801+
1802+
iex> "abcd" =~ %r/e/
1803+
false
1804+
1805+
iex> "abcd" =~ "bc"
1806+
true
1807+
1808+
iex> "abcd" =~ "ad"
1809+
false
1810+
1811+
"""
17931812
def left =~ right when is_binary(left) and is_binary(right) do
1794-
IO.write :stderr, "left =~ right is deprecated, please use String.match?/2 (for regexes) or String.contains?/2 (for strings) instead\n#{Exception.format_stacktrace}"
17951813
:binary.match(left, right) != :nomatch
17961814
end
17971815

17981816
def left =~ right when is_binary(left) and is_tuple(right) and
17991817
tuple_size(right) > 0 and elem(right, 0) == Regex do
1800-
IO.write :stderr, "left =~ right is deprecated, please use String.match?/2 (for regexes) or String.contains?/2 (for strings) instead\n#{Exception.format_stacktrace}"
18011818
Regex.match?(right, left)
18021819
end
18031820

lib/elixir/lib/version.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ defmodule Version do
363363
@spec parse_pre(String.t) :: [String.t | integer]
364364
def parse_pre(pre) do
365365
String.split(pre, ".") |> Enum.map fn piece ->
366-
if Regex.match?(%r/^(0|[1-9][0-9]*)$/, piece) do
366+
if piece =~ %r/^(0|[1-9][0-9]*)$/ do
367367
binary_to_integer(piece)
368368
else
369369
piece

lib/elixir/test/elixir/exception_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ defmodule Kernel.ExceptionTest do
4747
assert Exception.format_stacktrace_entry({:lists, :bar, [1, 2, 3], []}) == "(stdlib) :lists.bar(1, 2, 3)" end
4848

4949
test "format_stacktrace_entry with fun" do
50-
assert String.match? Exception.format_stacktrace_entry({fn(x) -> x end, [1], []}), %r/#Function<.+>\(1\)/
51-
assert String.match? Exception.format_stacktrace_entry({fn(x, y) -> { x, y } end, 2, []}), %r"#Function<.+>/2"
50+
assert Exception.format_stacktrace_entry({fn(x) -> x end, [1], []}) =~ %r/#Function<.+>\(1\)/
51+
assert Exception.format_stacktrace_entry({fn(x, y) -> { x, y } end, 2, []}) =~ %r"#Function<.+>/2"
5252
end
5353

5454
test "format_mfa" do
@@ -61,7 +61,7 @@ defmodule Kernel.ExceptionTest do
6161
end
6262

6363
test "format_fa" do
64-
assert String.match? Exception.format_fa(fn -> end, 1),
64+
assert Exception.format_fa(fn -> end, 1) =~
6565
%r"#Function<\d\.\d+/0 in Kernel\.ExceptionTest\.test format_fa/1>/1"
6666
end
6767

lib/elixir/test/elixir/hash_dict_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ defmodule HashDictTest do
4949
end
5050

5151
test "inspect" do
52-
assert String.starts_with? inspect(filled_dict(8)), "#HashDict<"
52+
assert inspect(filled_dict(8)) =~ "#HashDict<"
5353
end
5454

5555
defp smoke_test(range) do

lib/elixir/test/elixir/kernel/cli_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ defmodule Kernel.CLI.ParallelCompilerTest do
8787

8888
test "compiles files solving dependencies" do
8989
fixtures = [fixture_path("parallel_compiler/bar.ex"), fixture_path("parallel_compiler/foo.ex")]
90-
assert String.contains? capture_io(fn ->
90+
assert capture_io(fn ->
9191
assert [Bar, Foo] = Kernel.ParallelCompiler.files fixtures
92-
end), "message_from_foo"
92+
end) =~ "message_from_foo"
9393
end
9494

9595
test "does not hang on missing dependencies" do
9696
fixtures = [fixture_path("parallel_compiler/bat.ex")]
97-
assert String.contains? capture_io(fn ->
97+
assert capture_io(fn ->
9898
assert_raise CompileError, fn ->
9999
Kernel.ParallelCompiler.files fixtures
100100
end
101-
end), "Compilation error"
101+
end) =~ "Compilation error"
102102
end
103103

104104
test "handles possible deadlocks" do
@@ -110,8 +110,8 @@ defmodule Kernel.CLI.ParallelCompilerTest do
110110
end
111111
end)
112112

113-
assert String.contains? msg, "* #{fixture_path "parallel_deadlock/foo.ex"} is missing module Bar"
114-
assert String.contains? msg, "* #{fixture_path "parallel_deadlock/bar.ex"} is missing module Foo"
113+
assert msg =~ "* #{fixture_path "parallel_deadlock/foo.ex"} is missing module Bar"
114+
assert msg =~ "* #{fixture_path "parallel_deadlock/bar.ex"} is missing module Foo"
115115
end
116116

117117
test "warnings_as_errors" do

lib/elixir/test/elixir/kernel/expansion_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ defmodule Kernel.ExpansionTest do
153153
## Locals
154154

155155
test "locals: expands to remote calls" do
156-
assert { {:., _, [Kernel, :function_exported?] }, _, [{:a, _, []}, {:b, _, []}, {:c, _, []}] } =
157-
expand(quote do: function_exported?(a, b, c))
156+
assert { {:., _, [Kernel, :=~] }, _, [{:a, _, []}, {:b, _, []}] } =
157+
expand(quote do: a =~ b)
158158
end
159159

160160
test "locals: expands to configured local" do

0 commit comments

Comments
 (0)