/src/fitnesse/wikitext/test/TextMakerTest.java

http://github.com/unclebob/fitnesse · Java · 69 lines · 56 code · 12 blank · 1 comment · 0 complexity · 4e7dce5b38cee09f242fbd40963e065c MD5 · raw file

  1. package fitnesse.wikitext.test;
  2. import fitnesse.wikitext.parser.*;
  3. import fitnesse.wikitext.parser.VariableSource;
  4. import org.junit.Test;
  5. import static org.junit.Assert.assertEquals;
  6. import static org.junit.Assert.assertTrue;
  7. public class TextMakerTest {
  8. private VariableSource source = new TestVariableSource("x", "y");
  9. private SourcePage sourcePage = new TestSourcePage();
  10. @Test
  11. public void makesText() {
  12. assertText("hi");
  13. }
  14. @Test
  15. public void makesTextFromWikiWordWithUnderscore() {
  16. // this replicates old parser behavior based on bug (IMO) in WikiWord regexp
  17. assertText("HiMom_Dad");
  18. }
  19. private void assertText(String input) {
  20. SymbolMatch match = makeMatch(input);
  21. assertTrue(match.getSymbol().isType(SymbolType.Text));
  22. assertEquals(input, match.getSymbol().getContent());
  23. assertEquals(input.length(), match.getMatchLength());
  24. }
  25. @Test
  26. public void makesWikiWord() {
  27. assertWikiWord("HiMom", "HiMom");
  28. }
  29. @Test
  30. public void makesWikiWordWithTrailingText() {
  31. assertWikiWord("HiMom's", "HiMom");
  32. }
  33. @Test
  34. public void makesWikiWordWithIncludedDots() {
  35. assertWikiWord("HiMom.HiDad", "HiMom.HiDad");
  36. }
  37. @Test
  38. public void makesWikiWordWithTrailingDots() {
  39. assertWikiWord("HiMom..HiDad", "HiMom");
  40. }
  41. private void assertWikiWord(String input, String wikiWord) {
  42. SymbolMatch match = makeMatch(input);
  43. assertTrue(match.getSymbol().isType(WikiWord.symbolType));
  44. assertEquals(wikiWord, match.getSymbol().getContent());
  45. assertEquals(wikiWord.length(), match.getMatchLength());
  46. }
  47. @Test
  48. public void makesEMail() {
  49. SymbolMatch match = makeMatch("bob@bl.org");
  50. assertTrue(match.getSymbol().isType(SymbolType.EMail));
  51. assertEquals("bob@bl.org", match.getSymbol().getContent());
  52. assertEquals(10, match.getMatchLength());
  53. }
  54. private SymbolMatch makeMatch(String text) {
  55. return new TextMaker(source, sourcePage).make(new ParseSpecification(), text);
  56. }
  57. }