package net.afnf.blog.common;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Test;

public class AfnfUtilTest {

    @Test
    public void testGetTagList() {

        int index = 0;
        List<String> tagList;

        tagList = AfnfUtil.getTagList(null);
        assertEquals(0, tagList.size());

        tagList = AfnfUtil.getTagList("");
        assertEquals(0, tagList.size());

        tagList = AfnfUtil.getTagList(" ");
        assertEquals(0, tagList.size());

        tagList = AfnfUtil.getTagList(",,");
        assertEquals(0, tagList.size());

        tagList = AfnfUtil.getTagList(" , ,  , ,,,, , ");
        assertEquals(0, tagList.size());

        tagList = AfnfUtil.getTagList("tag1,tag2,tag3");
        assertEquals(3, tagList.size());
        index = 0;
        assertEquals("tag1", tagList.get(index++));
        assertEquals("tag2", tagList.get(index++));
        assertEquals("tag3", tagList.get(index++));

        tagList = AfnfUtil.getTagList("tag1,,tag2,,tag3,tag3");
        assertEquals(3, tagList.size());
        index = 0;
        assertEquals("tag1", tagList.get(index++));
        assertEquals("tag2", tagList.get(index++));
        assertEquals("tag3", tagList.get(index++));

        tagList = AfnfUtil.getTagList(",,,,tag1,,tag2,,tag3,tag3  , , ,     ,, tag4 ,,  tag1,tag1,");
        assertEquals(4, tagList.size());
        index = 0;
        assertEquals("tag1", tagList.get(index++));
        assertEquals("tag2", tagList.get(index++));
        assertEquals("tag3", tagList.get(index++));
        assertEquals("tag4", tagList.get(index++));
    }

    @Test
    public void testNormalizegTag() {

        assertEquals("", AfnfUtil.normalizegTag(null));
        assertEquals("", AfnfUtil.normalizegTag(""));
        assertEquals("", AfnfUtil.normalizegTag(" "));
        assertEquals("", AfnfUtil.normalizegTag(" ,, "));
        assertEquals("", AfnfUtil.normalizegTag(" , ,  , ,,,, , "));
        assertEquals("tag1, tag2, tag3", AfnfUtil.normalizegTag("tag1,tag2,tag3"));
        assertEquals("tag1, tag2, tag3", AfnfUtil.normalizegTag("tag1,,tag2,,tag3,tag3"));
        assertEquals("tag1, tag2, tag3, tag4",
                AfnfUtil.normalizegTag(",,,,tag1,,tag2,,tag3,tag3  , , ,     ,, tag4 ,,  tag1,tag1,"));
    }
}

@@ -1664,24 +1664,436 @@
 (index++));%0D
+%0A%0D%0A        tagList = AfnfUtil.getTagList(%22,,,,%E3%81%82%E3%81%82%E3%81%82,,%E3%81%84%E3%81%84,,%E5%AE%87%E5%AE%87%E5%AE%87,%E3%81%88%E3%83%BC%E3%83%BC%E3%83%BC%E3%81%88, , ,     ,, %E3%81%8A %E3%81%8A ,%E5%AE%87%E5%AE%87%E5%AE%87%22);%0D%0A        assertEquals(5, tagList.size());%0D%0A        index = 0;%0D%0A        assertEquals(%22%E3%81%82%E3%81%82%E3%81%82%22, tagList.get(index++));%0D%0A        assertEquals(%22%E3%81%84%E3%81%84%22, tagList.get(index++));%0D%0A        assertEquals(%22%E5%AE%87%E5%AE%87%E5%AE%87%22, tagList.get(index++));%0D%0A        assertEquals(%22%E3%81%88%E3%83%BC%E3%83%BC%E3%83%BC%E3%81%88%22, tagList.get(index++));%0D%0A        assertEquals(%22%E3%81%8A %E3%81%8A%22, tagList.get(index++));%0D
 %0A    %7D%0D%0A%0D%0A  
@@ -2765,22 +2765,144 @@
 ,tag1,%22));%0D%0A
+        assertEquals(%22%E3%81%82%E3%81%82%E3%81%82, %E3%81%84%E3%81%84, %E5%AE%87%E5%AE%87%E5%AE%87, %E3%81%88%E3%83%BC%E3%83%BC%E3%83%BC%E3%81%88, %E3%81%8A %E3%81%8A%22, AfnfUtil.normalizegTag(%22,,,,%E3%81%82%E3%81%82%E3%81%82,,%E3%81%84%E3%81%84,,%E5%AE%87%E5%AE%87%E5%AE%87,%E3%81%88%E3%83%BC%E3%83%BC%E3%83%BC%E3%81%88, , ,     ,, %E3%81%8A %E3%81%8A ,%E5%AE%87%E5%AE%87%E5%AE%87%22));%0D%0A
     %7D%0D%0A%7D%0D%0A

add i18n tag