package fitnesse.html;

import org.junit.Assert;
import org.junit.Test;

public class HtmlDiffUtilTest {

  @Test
  public void testCompletelyDifferentTexts() {
    String actual = "abc";
    String expected = "xyz";
    String htmlDiff = null;
    htmlDiff = HtmlDiffUtil.buildActual(actual, expected);
    Assert.assertEquals("<span class=\"diff\">abc</span>", htmlDiff);
    htmlDiff = HtmlDiffUtil.buildExpected(actual, expected);
    Assert.assertEquals("<span class=\"diff\">xyz</span>", htmlDiff);
  }

  @Test
  public void testOneDifferentCharInMiddleOfText() {
    String actual = "abc";
    String expected = "axc";
    String htmlDiff = null;
    htmlDiff = HtmlDiffUtil.buildActual(actual, expected);
    Assert.assertEquals("a<span class=\"diff\">b</span>c", htmlDiff);
    htmlDiff = HtmlDiffUtil.buildExpected(actual, expected);
    Assert.assertEquals("a<span class=\"diff\">x</span>c", htmlDiff);
  }

  @Test
  public void testOneDifferentCharAtTheBeginningOfText() {
    String actual = "abc";
    String expected = "xbc";
    String htmlDiff = null;
    htmlDiff = HtmlDiffUtil.buildActual(actual, expected);
    Assert.assertEquals("<span class=\"diff\">a</span>bc", htmlDiff);
    htmlDiff = HtmlDiffUtil.buildExpected(actual, expected);
    Assert.assertEquals("<span class=\"diff\">x</span>bc", htmlDiff);
  }

  @Test
  public void testOneDifferentCharAtTheEndOfText() {
    String actual = "abc";
    String expected = "abx";
    String htmlDiff = null;
    htmlDiff = HtmlDiffUtil.buildActual(actual, expected);
    Assert.assertEquals("ab<span class=\"diff\">c</span>", htmlDiff);
    htmlDiff = HtmlDiffUtil.buildExpected(actual, expected);
    Assert.assertEquals("ab<span class=\"diff\">x</span>", htmlDiff);
  }

  @Test
  public void testBuilderOpeningTag() {
    String actual = "abc";
    String expected = "axc";
    String htmlDiff = null;
    htmlDiff = new HtmlDiffUtil.ActualBuilder(actual, expected)
        .setOpeningTag("<span style=\"font-weight: bold;\">").build();
    Assert.assertEquals("a<span style=\"font-weight: bold;\">b</span>c", htmlDiff);
    htmlDiff = new HtmlDiffUtil.ExpectedBuilder(actual, expected)
        .setOpeningTag("<span style=\"font-weight: bold;\">").build();
    Assert.assertEquals("a<span style=\"font-weight: bold;\">x</span>c", htmlDiff);
  }

  @Test
  public void testBuilderClosingTag() {
    String actual = "abc";
    String expected = "axc";
    String htmlDiff = null;
    htmlDiff = new HtmlDiffUtil.ActualBuilder(actual, expected)
        .setClosingTag("</span class=\"diff\">").build();
    Assert.assertEquals("a<span class=\"diff\">b</span class=\"diff\">c", htmlDiff);
    htmlDiff = new HtmlDiffUtil.ExpectedBuilder(actual, expected)
        .setClosingTag("</span class=\"diff\">").build();
    Assert.assertEquals("a<span class=\"diff\">x</span class=\"diff\">c", htmlDiff);
  }

  @Test
  public void testEscapeHtmlCharacters() {
    String actual = "1 > 2";
    String expected = "1 < 2";
    String htmlDiff = null;
    htmlDiff = HtmlDiffUtil.buildActual(actual, expected);
    Assert.assertEquals("1 <span class=\"diff\">&gt;</span> 2", htmlDiff);  
    htmlDiff = HtmlDiffUtil.buildExpected(actual, expected);
    Assert.assertEquals("1 <span class=\"diff\">&lt;</span> 2", htmlDiff);  
  }
  
}

@@ -2608,39 +2608,38 @@
 gTag(%22%3C/span
- class=%5C%22diff%5C%22
+%3E%3Cem%3Eextra%3C/em
 %3E%22).build();
@@ -2690,39 +2690,38 @@
 ff%5C%22%3Eb%3C/span
- class=%5C%22diff%5C%22
+%3E%3Cem%3Eextra%3C/em
 %3Ec%22, htmlDif
@@ -2822,31 +2822,30 @@
 (%22%3C/span
- class=%5C%22diff%5C%22
+%3E%3Cem%3Eextra%3C/em
 %3E%22).buil
@@ -2904,31 +2904,30 @@
 %3Ex%3C/span
- class=%5C%22diff%5C%22
+%3E%3Cem%3Eextra%3C/em
 %3Ec%22, htm

Rework test of closing tag