Skip to content

Commit

Permalink
correction to naming now allows lowercase suffixes as should be
Browse files Browse the repository at this point in the history
'*s' + 'Case' -> 'Cases' and not 'CaseS' as was previously
  • Loading branch information
elucash committed Jan 2, 2016
1 parent 36dc296 commit fb45b44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions generator/src/org/immutables/generator/Naming.java
Expand Up @@ -204,7 +204,7 @@ public boolean isConstant() {
public Naming requireNonConstant(Preference preference) { public Naming requireNonConstant(Preference preference) {
switch (preference) { switch (preference) {
case SUFFIX: case SUFFIX:
return new PrefixSuffixNaming("", name); return new PrefixSuffixNaming("", Usage.CAPITALIZED.apply(name));
case PREFIX: case PREFIX:
default: default:
return new PrefixSuffixNaming(name, ""); return new PrefixSuffixNaming(name, "");
Expand Down Expand Up @@ -235,7 +235,7 @@ public String apply(String input) {
? Usage.INDIFFERENT ? Usage.INDIFFERENT
: Usage.CAPITALIZED; : Usage.CAPITALIZED;


return prefix + resultFormat.apply(input) + Usage.CAPITALIZED.apply(suffix); return prefix + resultFormat.apply(input) + suffix;
} }


@Override @Override
Expand Down
16 changes: 12 additions & 4 deletions generator/test/org/immutables/generator/NamingTest.java
Expand Up @@ -17,7 +17,7 @@


import org.immutables.generator.Naming.Preference; import org.immutables.generator.Naming.Preference;
import org.junit.Test; import org.junit.Test;
import static org.immutables.check.Checkers.*; import static org.immutables.check.Checkers.check;


public class NamingTest { public class NamingTest {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -125,10 +125,18 @@ public void requireNonConstant() {
check(Naming.from("new*").requireNonConstant(Preference.SUFFIX).apply("x")).is("newX"); check(Naming.from("new*").requireNonConstant(Preference.SUFFIX).apply("x")).is("newX");
} }


@Test
public void lowercaseSuffix() {
check(Naming.from("check*out").detect("checkThisout")).is("this");
check(Naming.from("check*out").apply("it")).is("checkItout");
}

@Test @Test
public void usageCorrection() { public void usageCorrection() {
String apply = Naming.from("of").requireNonConstant(Preference.SUFFIX).apply("Hen"); String suffix = Naming.from("of").requireNonConstant(Preference.SUFFIX).apply("Hen");
check(Naming.Usage.LOWERIZED.apply(apply)).is("henOf"); check(Naming.Usage.LOWERIZED.apply(suffix)).is("henOf");
check(Naming.from("check*out").apply("it")).is("checkItOut");
String prefix = Naming.from("of").requireNonConstant(Preference.PREFIX).apply("Hen");
check(Naming.Usage.CAPITALIZED.apply(prefix)).is("OfHen");
} }
} }

0 comments on commit fb45b44

Please sign in to comment.