+
+ addTest(new TestCase("BasicSupport.processPara() quotes") {
+ @Override
+ public void test() throws Exception {
+ BasicSupportEmpty support = new BasicSupportEmpty() {
+ @Override
+ protected boolean isHtml() {
+ return true;
+ }
+ };
+
+ Paragraph para;
+
+ // sanity check
+ para = support.processPara("");
+ assertEquals(ParagraphType.BLANK, para.getType());
+ //
+
+ para = support.processPara("\"Yes, my Lord!\"");
+ assertEquals(ParagraphType.QUOTE, para.getType());
+ assertEquals(openDoubleQuote + "Yes, my Lord!"
+ + closeDoubleQuote, para.getContent());
+
+ para = support.processPara("«Yes, my Lord!»");
+ assertEquals(ParagraphType.QUOTE, para.getType());
+ assertEquals(openDoubleQuote + "Yes, my Lord!"
+ + closeDoubleQuote, para.getContent());
+
+ para = support.processPara("'Yes, my Lord!'");
+ assertEquals(ParagraphType.QUOTE, para.getType());
+ assertEquals(openQuote + "Yes, my Lord!" + closeQuote,
+ para.getContent());
+
+ para = support.processPara("‹Yes, my Lord!›");
+ assertEquals(ParagraphType.QUOTE, para.getType());
+ assertEquals(openQuote + "Yes, my Lord!" + closeQuote,
+ para.getContent());
+ }
+ });
+
+ addTest(new TestCase(
+ "BasicSupport.processPara() double-simple quotes") {
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ };
+
+ @Override
+ public void tearDown() throws Exception {
+
+ super.tearDown();
+ }
+
+ @Override
+ public void test() throws Exception {
+ BasicSupportEmpty support = new BasicSupportEmpty() {
+ @Override
+ protected boolean isHtml() {
+ return true;
+ }
+ };
+
+ Paragraph para;
+
+ para = support.processPara("''Yes, my Lord!''");
+ assertEquals(ParagraphType.QUOTE, para.getType());
+ assertEquals(openDoubleQuote + "Yes, my Lord!"
+ + closeDoubleQuote, para.getContent());
+
+ para = support.processPara("‹‹Yes, my Lord!››");
+ assertEquals(ParagraphType.QUOTE, para.getType());
+ assertEquals(openDoubleQuote + "Yes, my Lord!"
+ + closeDoubleQuote, para.getContent());
+ }
+ });
+
+ addTest(new TestCase("BasicSupport.processPara() apostrophe") {
+ @Override
+ public void test() throws Exception {
+ BasicSupportEmpty support = new BasicSupportEmpty() {
+ @Override
+ protected boolean isHtml() {
+ return true;
+ }
+ };
+
+ Paragraph para;
+
+ String text = "Nous étions en été, mais cela aurait être l'hiver quand nous n'étions encore qu'à Aubeuge";
+ para = support.processPara(text);
+ assertEquals(ParagraphType.NORMAL, para.getType());
+ assertEquals(text, para.getContent());
+ }
+ });
+
+ addTest(new TestCase("BasicSupport.processPara() words count") {
+ @Override
+ public void test() throws Exception {
+ BasicSupportEmpty support = new BasicSupportEmpty() {
+ @Override
+ protected boolean isHtml() {
+ return true;
+ }
+ };
+
+ Paragraph para;
+
+ para = support.processPara("«Yes, my Lord!»");
+ assertEquals(3, para.getWords());
+
+ para = support.processPara("One, twee, trois.");
+ assertEquals(3, para.getWords());
+ }
+ });
+
+ addTest(new TestCase("BasicSupport.requotify() words count") {
+ @Override
+ public void test() throws Exception {
+ BasicSupportEmpty support = new BasicSupportEmpty();
+
+ char openDoubleQuote = Instance.getTrans().getChar(
+ StringId.OPEN_DOUBLE_QUOTE);
+ char closeDoubleQuote = Instance.getTrans().getChar(
+ StringId.CLOSE_DOUBLE_QUOTE);
+
+ String content = null;
+ Paragraph para = null;
+ List<Paragraph> paras = null;
+ long words = 0;
+
+ content = "One, twee, trois.";
+ para = new Paragraph(ParagraphType.NORMAL, content,
+ content.split(" ").length);
+ paras = support.requotify(para);
+ words = 0;
+ for (Paragraph p : paras) {
+ words += p.getWords();
+ }
+ assertEquals("Bad words count in a single paragraph",
+ para.getWords(), words);
+
+ content = "Such WoW! So Web2.0! With Colours!";
+ para = new Paragraph(ParagraphType.NORMAL, content,
+ content.split(" ").length);
+ paras = support.requotify(para);
+ words = 0;
+ for (Paragraph p : paras) {
+ words += p.getWords();
+ }
+ assertEquals("Bad words count in a single paragraph",
+ para.getWords(), words);
+
+ content = openDoubleQuote + "Such a good idea!"
+ + closeDoubleQuote
+ + ", she said. This ought to be a new para.";
+ para = new Paragraph(ParagraphType.QUOTE, content,
+ content.split(" ").length);
+ paras = support.requotify(para);
+ words = 0;
+ for (Paragraph p : paras) {
+ words += p.getWords();
+ }
+ assertEquals(
+ "Bad words count in a requotified paragraph",
+ para.getWords(), words);
+ }
+ });
+ }
+ });
+
+ addSeries(new TestLauncher("Text", args) {
+ {
+ addTest(new TestCase("Chapter detection simple") {
+ private File tmp;
+
+ @Override
+ public void setUp() throws Exception {
+ tmp = File.createTempFile("fanfix-text-file_", ".test");
+ IOUtils.writeSmallFile(tmp.getParentFile(),
+ tmp.getName(), "TITLE"
+ + "\n"//
+ + "By nona"
+ + "\n" //
+ + "\n" //
+ + "Chapter 0: Resumé" + "\n" + "\n"
+ + "'sume." + "\n" + "\n"
+ + "Chapter 1: chap1" + "\n" + "\n"
+ + "Fanfan." + "\n" + "\n"
+ + "Chapter 2: Chap2" + "\n" + "\n" //
+ + "Tulipe." + "\n");
+ };
+
+ @Override
+ public void tearDown() throws Exception {
+ tmp.delete();
+ };
+
+ @Override
+ public void test() throws Exception {
+ BasicSupport support = BasicSupport
+ .getSupport(SupportType.TEXT);
+
+ Story story = support
+ .process(tmp.toURI().toURL(), null);
+
+ assertEquals(2, story.getChapters().size());
+ assertEquals(1, story.getChapters().get(1)
+ .getParagraphs().size());
+ assertEquals("Tulipe.", story.getChapters().get(1)
+ .getParagraphs().get(0).getContent());
+ }
+ });
+
+ addTest(new TestCase("Chapter detection with String 'Chapter'") {
+ private File tmp;
+
+ @Override
+ public void setUp() throws Exception {
+ tmp = File.createTempFile("fanfix-text-file_", ".test");
+ IOUtils.writeSmallFile(tmp.getParentFile(),
+ tmp.getName(), "TITLE"
+ + "\n"//
+ + "By nona"
+ + "\n" //
+ + "\n" //
+ + "Chapter 0: Resumé" + "\n" + "\n"
+ + "'sume." + "\n" + "\n"
+ + "Chapter 1: chap1" + "\n" + "\n"
+ + "Chapter fout-la-merde" + "\n"
+ + "\n"//
+ + "Fanfan." + "\n" + "\n"
+ + "Chapter 2: Chap2" + "\n" + "\n" //
+ + "Tulipe." + "\n");
+ };
+
+ @Override
+ public void tearDown() throws Exception {
+ tmp.delete();
+ };
+
+ @Override
+ public void test() throws Exception {
+ BasicSupport support = BasicSupport
+ .getSupport(SupportType.TEXT);
+
+ Story story = support
+ .process(tmp.toURI().toURL(), null);
+
+ assertEquals(2, story.getChapters().size());
+ assertEquals(1, story.getChapters().get(1)
+ .getParagraphs().size());
+ assertEquals("Tulipe.", story.getChapters().get(1)
+ .getParagraphs().get(0).getContent());
+ }
+ });