package be.iminds.ilabt.jfed.util;

import org.testng.annotations.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class TextUtilTest {

    @Test
    public void testIndent1() throws Exception {
        String in = "";
        String expected = "";
        String actual = TextUtil.indent(4, in);
        assertThat(actual, equalTo(expected));
    }
    @Test
    public void testIndent2() throws Exception {
        String in = "\ntest\n\na\nb";
        String expected = "  \n  test\n  \n  a\n  b";
        String actual = TextUtil.indent(2, in);
        assertThat(actual, equalTo(expected));
    }
    @Test
    public void testIndent3a() throws Exception {
        String in = "test";
        String expected = "   test";
        String actual = TextUtil.indent(3, in);
        assertThat(actual, equalTo(expected));
    }
    @Test
    public void testIndent3b() throws Exception {
        String in = "a";
        String expected = "   a";
        String actual = TextUtil.indent(3, in);
        assertThat(actual, equalTo(expected));
    }
    @Test
    public void testIndent3c() throws Exception {
        String in = " ";
        String expected = "    ";
        String actual = TextUtil.indent(3, in);
        assertThat(actual, equalTo(expected));
    }
    @Test
    public void testIndent4() throws Exception {
        String in = "This is a test\nAnd another line\nAll looks ok\n";
        String expected = " This is a test\n" +
                " And another line\n" +
                " All looks ok\n";
        String actual = TextUtil.indent(1, in);
        assertThat(actual, equalTo(expected));
    }
    @Test
    public void testIndent5() throws Exception {
        String in = "test\n";
        String expected = "     test\n";
        String actual = TextUtil.indent(5, in);
        assertThat(actual, equalTo(expected));
    }

    @Test
    public void testWrap() throws Exception {

        assertThat(TextUtil.wrap("0123456789012345678901234567890123456789", 5),
                equalTo("01234\n56789\n01234\n56789\n01234\n56789\n01234\n56789"));


        assertThat(TextUtil.wrap("0123456789012345678901234567890123\n456789", 5),
                equalTo("01234\n56789\n01234\n56789\n01234\n56789\n0123\n45678\n9"));

        assertThat(TextUtil.wrap("01234\n56789012345678901234567890123\n456789", 5),
                equalTo("01234\n56789\n01234\n56789\n01234\n56789\n0123\n45678\n9"));
    }
}