package org.odk.collect.android.utilities;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;


@RunWith(RobolectricTestRunner.class)
public class TextUtilsTest {

    /**
     * Should return null if provided with null and not throw a NPE.
     *
     * This is a silly test but it is here to guarantee this behaviour,
     * since without it the method causes a crash when processing text for
     * questions with no plain text label. See opendatakit/opendatakit#1247.
     */
    @Test
    public void textToHtml_BouncesNullInput() {
        String input = null;
        CharSequence observed = TextUtils.textToHtml(input);
        assertNull(observed);
    }

    /**
     * Should convert Markdown to HTML.
     *
     * In the real app this call would produce the following string, but
     * because the implementation uses android.Html.fromHtml, we end up with
     * robolectric's implementation of fromHtml which isn't exactly the same.
     * See opendatakit/collect#204.
     *
     * <p>This <em>bold</em> markdown is</p><p>- nice,</p><p>- efficient.</p>
     *
     * The main thing is that it's clear this interface processes Markdown to
     * HTML, which is evident from the removal of the stars on *bold* and
     * doubling of line returns (which is due to \n to <p></p> conversion).
     */
    @Test
    public void textToHtml_ConvertsMarkdownToHtml() {
        String input = "This *bold* markdown is \n- nice,\n- efficient.\n";
        String expected = "This bold markdown is\n\n- nice,\n\n- efficient.\n\n";
        CharSequence actual = TextUtils.textToHtml(input);
        assertEquals(expected, actual.toString());
    }
}

@@ -144,53 +144,8 @@
 r;%0A%0A
-import static org.junit.Assert.assertEquals;%0A
 impo
@@ -758,991 +758,6 @@
  %7D%0A%0A
-    /**%0A     * Should convert Markdown to HTML.%0A     *%0A     * In the real app this call would produce the following string, but%0A     * because the implementation uses android.Html.fromHtml, we end up with%0A     * robolectric's implementation of fromHtml which isn't exactly the same.%0A     * See opendatakit/collect#204.%0A     *%0A     * %3Cp%3EThis %3Cem%3Ebold%3C/em%3E markdown is%3C/p%3E%3Cp%3E- nice,%3C/p%3E%3Cp%3E- efficient.%3C/p%3E%0A     *%0A     * The main thing is that it's clear this interface processes Markdown to%0A     * HTML, which is evident from the removal of the stars on *bold* and%0A     * doubling of line returns (which is due to %5Cn to %3Cp%3E%3C/p%3E conversion).%0A     */%0A    @Test%0A    public void textToHtml_ConvertsMarkdownToHtml() %7B%0A        String input = %22This *bold* markdown is %5Cn- nice,%5Cn- efficient.%5Cn%22;%0A        String expected = %22This bold markdown is%5Cn%5Cn- nice,%5Cn%5Cn- efficient.%5Cn%5Cn%22;%0A        CharSequence actual = TextUtils.textToHtml(input);%0A        assertEquals(expected, actual.toString());%0A    %7D%0A
 %7D%0A

remove expected function test, to be done later