package co.phoenixlab.common.localization;

import org.junit.*;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import static org.junit.Assert.*;

public class LocalizerTest {

    private Map<String, String> strings;
    private Localizer localizer;

    @Before
    public void setup() {
        strings = new HashMap<>();
        localizer = new LocalizerImpl(Locale.US);
        localizer.addLocaleStringProvider(new LocaleStringProvider() {
            @Override
            public void setActiveLocale(Locale locale) {
                //  Ignore
            }

            @Override
            public String get(String key) {
                return strings.get(key);
            }

            @Override
            public boolean contains(String key) {
                return strings.containsKey(key);
            }
        });
    }

    @Test
    public void testExampleBaseStr() throws Exception {
        final String key = "test.string";
        final String val = "potato";
        strings.clear();
        strings.put(key, val);
        final String ret = localizer.localize(key);
        assertEquals(val, ret);
    }

    @Test
    public void testExampleStrFmt() throws Exception {
        final String key = "test.string";
        final String val = "{1|%d} potato {0|%s}";
        final String arg0 = "baked";
        final int arg1 = 45;
        final String expected = "45 potato baked";
        strings.clear();
        strings.put(key, val);
        final String ret = localizer.localize(key, arg0, arg1);
        assertEquals(expected, ret);
    }
    
}

@@ -395,16 +395,97 @@
 le.US);%0A
+        localizer.registerPluralityRules(LocalizerImpl.defaultPluralityRules());%0A
         
@@ -543,24 +543,24 @@
 rovider() %7B%0A
-
             
@@ -1674,15 +1674,1791 @@
 ;%0A    %7D%0A
+%0A
     
+@Test%0A    public void testSimplePluralOne() throws Exception %7B%0A        final String key = %22test.string%22;%0A        final String val = %22%7B0%7C%25d%7D %7B0%7C(one;potato),(en_plural;potatoes)%7D%22;%0A        final int arg0 = 1;%0A        final String expected = %221 potato%22;%0A        strings.clear();%0A        strings.put(key, val);%0A        final String ret = localizer.localize(key, arg0);%0A        assertEquals(expected, ret);%0A    %7D%0A%0A    @Test%0A    public void testSimplePluralEnPlural() throws Exception %7B%0A        final String key = %22test.string%22;%0A        final String val = %22%7B0%7C%25d%7D %7B0%7C(one;potato),(en_plural;potatoes)%7D%22;%0A        final int arg0 = 2;%0A        final String expected = %222 potatoes%22;%0A        strings.clear();%0A        strings.put(key, val);%0A        final String ret = localizer.localize(key, arg0);%0A        assertEquals(expected, ret);%0A    %7D%0A%0A    @Test%0A    public void testOrPluralEnPlural() throws Exception %7B%0A        final String key = %22test.string%22;%0A        final String val = %22%7B0%7C(one,en_plural;potatoes)%7D%22;%0A        final int arg1 = 1;%0A        final int arg2 = 2;%0A        final String expected = %22potatoes%22;%0A        strings.clear();%0A        strings.put(key, val);%0A        final String ret1 = localizer.localize(key, arg1);%0A        final String ret2 = localizer.localize(key, arg2);%0A        assertEquals(expected, ret1);%0A        assertEquals(expected, ret2);%0A    %7D%0A%0A    @Test%0A    public void testAndPluralEnPlural() throws Exception %7B%0A        final String key = %22test.string%22;%0A        final String val = %22%7B0%7C(zero+en_plural;potatoes),(en_plural;potato)%7D%22;%0A        final int arg1 = 2;%0A        final String expected = %22potato%22;%0A        strings.clear();%0A        strings.put(key, val);%0A        final String ret1 = localizer.localize(key, arg1);%0A        assertEquals(expected, ret1);%0A    %7D
 %0A%7D%0A

Add plurality tests