Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
fix bug with verbs ending in -er, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonwells committed Oct 25, 2021
1 parent 7cf2142 commit 0b0b6c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/suffix.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Suffix do

@consonant_pattern "[bcdfghjklmnpqrstvwxz]"
@doubled_consonant_pattern "[bcdfghklmnprstz]"
@doubled_consonant_pattern "[bcdfghklmnprstz]{2}"
@vowel_pattern "[aeiouy]"
@doubled_vowel_pattern "[aeiouy]"

Expand All @@ -12,6 +12,8 @@ defmodule Suffix do
String.replace_suffix(infinitive, "y", "ied")
ends_vowel_lf?(infinitive) ->
String.replace_suffix(infinitive, "lf", "lved")
ends_er?(infinitive) ->
infinitive <> "ed"
ends_consonant_vowel_consonant?(infinitive) ->
infinitive <> String.last(infinitive) <> "ed"
true -> infinitive <> "ed"
Expand Down Expand Up @@ -47,11 +49,15 @@ defmodule Suffix do
def ends_consonant_vowel_consonant?(infinitive) do
pattern = @consonant_pattern <>
@doubled_vowel_pattern <>
@doubled_consonant_pattern <> "$"
@consonant_pattern <> "$"
{:ok, regex} = Regex.compile(pattern, "i")
Regex.match?(regex, infinitive)
end

def ends_er?(infinitive) do
Regex.match?(~r/er/, infinitive)
end

def ends_consonant_plus_y?(infinitive) do
{:ok, regex} = Regex.compile(@consonant_pattern <> "y$", "i")
Regex.match?(regex, infinitive)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Verbs.Mixfile do
source_url: "https://github.com/shannonwells/verbs_ex",
homepage_url: "https://github.com/shannonwells/verbs_ex",
package: package(),
version: "0.6.0",
version: "0.6.1",
elixir: "~> 1.5",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand Down
20 changes: 19 additions & 1 deletion test/conjugate_regular_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,23 @@ defmodule ConjugateRegularTest do

end

test "ends two consonants" do
[ %{tense: "past", verb: "hack", expected: "hacked"},
]
end

end
test "-er, and odd, not irregular verb forms" do
[
%{tense: "past", verb: "clobber", expected: "clobbered"},
%{tense: "past", verb: "shatter", expected: "shattered"},
%{tense: "past", verb: "hack", expected: "hacked"},
%{tense: "past", verb: "miter", expected: "mitered"},
%{tense: "past", verb: "corner", expected: "cornered"},
%{tense: "past", verb: "belittle", expected: "belittled"},
]
|> Enum.each( fn tc ->
options = %{:tense => tc.tense, :person => "first", :plurality => "singular"}
assert ConjugateRegular.conjugate(tc.verb, options) == tc.expected
end)
end
end

0 comments on commit 0b0b6c5

Please sign in to comment.