package name.abuchen.portfolio.util;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.nullValue;

import org.junit.Test;

import com.google.common.base.Strings;

@SuppressWarnings("nls")
public class TextUtilTest
{

    @Test
    public void testStripNonNumberCharacters()
    {
        assertThat(TextUtil.stripNonNumberCharacters("+ 123,34 x"), is("123,34"));
        assertThat(TextUtil.stripNonNumberCharacters("abcd"), is(""));
        assertThat(TextUtil.stripNonNumberCharacters(",123"), is(",123"));
    }

    @Test
    public void testWordwrap()
    {
        String text = Strings.repeat("t ", 40) + "(test)";
        assertThat(TextUtil.wordwrap(text), is(endsWith("\n(test)")));
    }

    @Test
    public void testStripCallbacksJsonObjects()
    {
        String json = "{\"name\"=\"value\"}";

        assertThat(TextUtil.stripJavaScriptCallback(json), is(json));
        assertThat(TextUtil.stripJavaScriptCallback("callback(" + json + ");"), is(json));
        assertThat(TextUtil.stripJavaScriptCallback(null), is(nullValue()));
        assertThat(TextUtil.stripJavaScriptCallback("something"), is("something"));
        assertThat(TextUtil.stripJavaScriptCallback("}something{"), is("}something{"));

        json = Strings.repeat("texttext", 100);
        assertThat(TextUtil.stripJavaScriptCallback(json), is(json));
    }

    @Test
    public void testStripCallbacksJsonArrays()
    {
        String json = "[{\"name\"=\"value\"}]";

        assertThat(TextUtil.stripJavaScriptCallback(json), is(json));
        assertThat(TextUtil.stripJavaScriptCallback("callback(" + json + ");"), is(json));
        assertThat(TextUtil.stripJavaScriptCallback("angular.callbacks._u(" + json + ")"), is(json));
        assertThat(TextUtil.stripJavaScriptCallback("sd" + json), is("sd" + json));
        assertThat(TextUtil.stripJavaScriptCallback("]something["), is("]something["));
    }

    @Test
    public void testSanitizeFilename()
    {
        assertThat(TextUtil.sanitizeFilename("?a\\b/c:d|e<f>g//h*i"), is("_a_b_c_d_e_f_g_h_i"));
        assertThat(TextUtil.sanitizeFilename("a    b"), is("a_b"));
        assertThat(TextUtil.sanitizeFilename("äöüÄÖÜß"), is("äöüÄÖÜß"));
        assertThat(TextUtil.sanitizeFilename("Акти"), is("Акти"));
    }

}

@@ -628,24 +628,177 @@
 s(%22,123%22));%0A
+        assertThat(TextUtil.stripNonNumberCharacters(%22-1,23%22), is(%22-1,23%22));%0A        assertThat(TextUtil.stripNonNumberCharacters(%22+1,23%22), is(%221,23%22));%0A
     %7D%0A%0A    @
@@ -2544,10 +2544,1134 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testStripBlanks()%0A    %7B%0A        assertThat(TextUtil.stripBlanks(%22a b c%22), is(%22abc%22));%0A        assertThat(TextUtil.stripBlanks(%22 a  b  c %22), is(%22abc%22));%0A    %7D%0A%0A    @Test%0A    public void testStripBlanksAndUnderscores()%0A    %7B%0A        assertThat(TextUtil.stripBlanksAndUnderscores(%22a _ b _ c%22), is(%22abc%22));%0A        assertThat(TextUtil.stripBlanksAndUnderscores(%22_ a _ b _ c _%22), is(%22abc%22));%0A    %7D%0A%0A    @Test%0A    public void testTooltip()%0A    %7B%0A        assertThat(TextUtil.tooltip(%22Drag & drop%22), is(%22Drag && drop%22));%0A    %7D%0A%0A    @Test%0A    public void testLimit()%0A    %7B%0A        String text = Strings.repeat(%22Lorem ipsum %22, 2);%0A        assertThat(TextUtil.limit(text, 5), is(%22Lorem%E2%80%A6%22));%0A    %7D%0A%0A    @Test%0A    public void testTrimStringInArray()%0A    %7B%0A        String toTrimString = %22 Portfolio , Performance ,   is  , a, great tool! %22;%0A        String%5B%5D trimPartsAnswer = %7B %22Portfolio%22, %22Performance%22, %22is%22, %22a%22, %22great tool!%22 %7D;%0A%0A        String%5B%5D trimParts = TextUtil.trim(toTrimString.split(%22,%22));%0A%0A        assertThat(TextUtil.trim(%22 %22), is(%22%22));%0A        assertThat(trimParts, is(trimPartsAnswer));%0A    %7D%0A%0A
 %7D%0A

Add tests to the TextUtilTest.java