Skip to content
Permalink
Browse files

Add test reproducing #646

  • Loading branch information...
rrrene committed Mar 30, 2019
1 parent 024ffff commit dd0d5681cd16de084c3e5ced355b58bdbd20668c
@@ -32,4 +32,42 @@ defmodule Credo.Code.CharlistsTest do

assert expected == source |> Charlists.replace_with_spaces()
end

test "it should not modify commented out code" do
source = """
defmodule Foo do
defmodule Bar do
# @doc \"\"\"
# Reassign a student to a discussion group.
# This will un-assign student from the current discussion group
# \"\"\"
# def assign_group(leader = %User{}, student = %User{}) do
# cond do
# leader.role == :student ->
# {:error, :invalid}
#
# student.role != :student ->
# {:error, :invalid}
#
# true ->
# Repo.transaction(fn ->
# {:ok, _} = unassign_group(student)
#
# %Group{}
# |> Group.changeset(%{})
# |> put_assoc(:leader, leader)
# |> put_assoc(:student, student)
# |> Repo.insert!()
# end)
# end
# end
def baz, do: 123
end
end
"""

expected = source

assert expected == source |> Charlists.replace_with_spaces(".")
end
end
@@ -114,4 +114,42 @@ defmodule Credo.Code.HeredocsTest do
result = source |> Heredocs.replace_with_spaces(".")
assert expected == result
end

test "it should not modify commented out code" do
source = """
defmodule Foo do
defmodule Bar do
# @doc \"\"\"
# Reassign a student to a discussion group.
# This will un-assign student from the current discussion group
# \"\"\"
# def assign_group(leader = %User{}, student = %User{}) do
# cond do
# leader.role == :student ->
# {:error, :invalid}
#
# student.role != :student ->
# {:error, :invalid}
#
# true ->
# Repo.transaction(fn ->
# {:ok, _} = unassign_group(student)
#
# %Group{}
# |> Group.changeset(%{})
# |> put_assoc(:leader, leader)
# |> put_assoc(:student, student)
# |> Repo.insert!()
# end)
# end
# end
def baz, do: 123
end
end
"""

expected = source

assert expected == source |> Heredocs.replace_with_spaces(".")
end
end
@@ -176,4 +176,42 @@ defmodule Credo.Code.SigilsTest do

assert expected == Sigils.replace_with_spaces(source, "")
end

test "it should not modify commented out code" do
source = """
defmodule Foo do
defmodule Bar do
# @doc \"\"\"
# Reassign a student to a discussion group.
# This will un-assign student from the current discussion group
# \"\"\"
# def assign_group(leader = %User{}, student = %User{}) do
# cond do
# leader.role == :student ->
# {:error, :invalid}
#
# student.role != :student ->
# {:error, :invalid}
#
# true ->
# Repo.transaction(fn ->
# {:ok, _} = unassign_group(student)
#
# %Group{}
# |> Group.changeset(%{})
# |> put_assoc(:leader, leader)
# |> put_assoc(:student, student)
# |> Repo.insert!()
# end)
# end
# end
def baz, do: 123
end
end
"""

expected = source

assert expected == Sigils.replace_with_spaces(source, "")
end
end
@@ -124,4 +124,42 @@ defmodule Credo.Code.StringsTest do
result = source |> Strings.replace_with_spaces(".")
assert expected == result
end

test "it should not modify commented out code" do
source = """
defmodule Foo do
defmodule Bar do
# @doc \"\"\"
# Reassign a student to a discussion group.
# This will un-assign student from the current discussion group
# \"\"\"
# def assign_group(leader = %User{}, student = %User{}) do
# cond do
# leader.role == :student ->
# {:error, :invalid}
#
# student.role != :student ->
# {:error, :invalid}
#
# true ->
# Repo.transaction(fn ->
# {:ok, _} = unassign_group(student)
#
# %Group{}
# |> Group.changeset(%{})
# |> put_assoc(:leader, leader)
# |> put_assoc(:student, student)
# |> Repo.insert!()
# end)
# end
# end
def baz, do: 123
end
end
"""

expected = source

assert expected == source |> Strings.replace_with_spaces(".")
end
end

0 comments on commit dd0d568

Please sign in to comment.
You can’t perform that action at this time.