Update nikiroo-utils, bugfixes:
[nikiroo-utils.git] / src / be / nikiroo / fanfix / test / BasicSupportTest.java
index d8565cba85e33c31cf3709e05d1c124af4293621..dba0ef027f8be86e593019f5cacaccb13eeba511 100644 (file)
@@ -17,18 +17,19 @@ import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.supported.BasicSupport;
 import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
 import be.nikiroo.utils.IOUtils;
+import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.test.TestCase;
 import be.nikiroo.utils.test.TestLauncher;
 
-public class BasicSupportTest extends TestLauncher {
+class BasicSupportTest extends TestLauncher {
        // quote chars
-       private char openQuote = Instance.getTrans().getChar(
+       private char openQuote = Instance.getTrans().getCharacter(
                        StringId.OPEN_SINGLE_QUOTE);
-       private char closeQuote = Instance.getTrans().getChar(
+       private char closeQuote = Instance.getTrans().getCharacter(
                        StringId.CLOSE_SINGLE_QUOTE);
-       private char openDoubleQuote = Instance.getTrans().getChar(
+       private char openDoubleQuote = Instance.getTrans().getCharacter(
                        StringId.OPEN_DOUBLE_QUOTE);
-       private char closeDoubleQuote = Instance.getTrans().getChar(
+       private char closeDoubleQuote = Instance.getTrans().getCharacter(
                        StringId.CLOSE_DOUBLE_QUOTE);
 
        public BasicSupportTest(String[] args) {
@@ -50,7 +51,7 @@ public class BasicSupportTest extends TestLauncher {
                                                        }
 
                                                        @Override
-                                                       protected List<Paragraph> requotify(Paragraph para) {
+                                                       public List<Paragraph> requotify(Paragraph para) {
                                                                List<Paragraph> paras = new ArrayList<Paragraph>(
                                                                                1);
                                                                paras.add(para);
@@ -60,13 +61,13 @@ public class BasicSupportTest extends TestLauncher {
 
                                                List<Paragraph> paras = null;
 
-                                               paras = support.makeParagraphs(null, "");
+                                               paras = support.makeParagraphs(null, "", null);
                                                assertEquals(
                                                                "An empty content should not generate paragraphs",
                                                                0, paras.size());
 
                                                paras = support.makeParagraphs(null,
-                                                               "Line 1</p><p>Line 2</p><p>Line 3</p>");
+                                                               "Line 1</p><p>Line 2</p><p>Line 3</p>", null);
                                                assertEquals(5, paras.size());
                                                assertEquals("Line 1", paras.get(0).getContent());
                                                assertEquals(ParagraphType.BLANK, paras.get(1)
@@ -77,7 +78,7 @@ public class BasicSupportTest extends TestLauncher {
                                                assertEquals("Line 3", paras.get(4).getContent());
 
                                                paras = support.makeParagraphs(null,
-                                                               "<p>Line1</p><p>Line2</p><p>Line3</p>");
+                                                               "<p>Line1</p><p>Line2</p><p>Line3</p>", null);
                                                assertEquals(6, paras.size());
                                        }
                                });
@@ -95,34 +96,39 @@ public class BasicSupportTest extends TestLauncher {
                                                List<Paragraph> paras = null;
 
                                                paras = support
-                                                               .makeParagraphs(null,
-                                                                               "<p>Line1</p><p>Line2</p><p>Line3<br/><br><p></p>");
+                                                               .makeParagraphs(
+                                                                               null,
+                                                                               "<p>Line1</p><p>Line2</p><p>Line3<br/><br><p></p>",
+                                                                               null);
                                                assertEquals(5, paras.size());
 
                                                paras = support
-                                                               .makeParagraphs(null,
-                                                                               "<p>Line1</p><p>Line2</p><p>Line3<br/><br><p></p>* * *");
+                                                               .makeParagraphs(
+                                                                               null,
+                                                                               "<p>Line1</p><p>Line2</p><p>Line3<br/><br><p></p>* * *",
+                                                                               null);
                                                assertEquals(5, paras.size());
 
-                                               paras = support.makeParagraphs(null, "1<p>* * *<p>2");
+                                               paras = support.makeParagraphs(null, "1<p>* * *<p>2",
+                                                               null);
                                                assertEquals(3, paras.size());
                                                assertEquals(ParagraphType.BREAK, paras.get(1)
                                                                .getType());
 
                                                paras = support.makeParagraphs(null,
-                                                               "1<p><br/><p>* * *<p>2");
+                                                               "1<p><br/><p>* * *<p>2", null);
                                                assertEquals(3, paras.size());
                                                assertEquals(ParagraphType.BREAK, paras.get(1)
                                                                .getType());
 
                                                paras = support.makeParagraphs(null,
-                                                               "1<p>* * *<br/><p><br><p>2");
+                                                               "1<p>* * *<br/><p><br><p>2", null);
                                                assertEquals(3, paras.size());
                                                assertEquals(ParagraphType.BREAK, paras.get(1)
                                                                .getType());
 
                                                paras = support.makeParagraphs(null,
-                                                               "1<p><br/><br>* * *<br/><p><br><p>2");
+                                                               "1<p><br/><br>* * *<br/><p><br><p>2", null);
                                                assertEquals(3, paras.size());
                                                assertEquals(ParagraphType.BREAK, paras.get(1)
                                                                .getType());
@@ -174,7 +180,7 @@ public class BasicSupportTest extends TestLauncher {
                                        public void setUp() throws Exception {
                                                super.setUp();
 
-                                       };
+                                       }
 
                                        @Override
                                        public void tearDown() throws Exception {
@@ -223,6 +229,79 @@ public class BasicSupportTest extends TestLauncher {
                                                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()
+                                                               .getCharacter(StringId.OPEN_DOUBLE_QUOTE);
+                                               char closeDoubleQuote = Instance.getTrans()
+                                                               .getCharacter(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);
+                                       }
+                               });
                        }
                });
 
@@ -246,12 +325,12 @@ public class BasicSupportTest extends TestLauncher {
                                                                                + "Fanfan." + "\n" + "\n"
                                                                                + "Chapter 2: Chap2" + "\n" + "\n" //
                                                                                + "Tulipe." + "\n");
-                                       };
+                                       }
 
                                        @Override
                                        public void tearDown() throws Exception {
                                                tmp.delete();
-                                       };
+                                       }
 
                                        @Override
                                        public void test() throws Exception {
@@ -289,12 +368,12 @@ public class BasicSupportTest extends TestLauncher {
                                                                                + "Fanfan." + "\n" + "\n"
                                                                                + "Chapter 2: Chap2" + "\n" + "\n" //
                                                                                + "Tulipe." + "\n");
-                                       };
+                                       }
 
                                        @Override
                                        public void tearDown() throws Exception {
                                                tmp.delete();
-                                       };
+                                       }
 
                                        @Override
                                        public void test() throws Exception {
@@ -344,21 +423,21 @@ public class BasicSupportTest extends TestLauncher {
 
                @Override
                protected List<Entry<String, URL>> getChapters(URL source,
-                               InputStream in) throws IOException {
+                               InputStream in, Progress pg) throws IOException {
                        return null;
                }
 
                @Override
                protected String getChapterContent(URL source, InputStream in,
-                               int number) throws IOException {
+                               int number, Progress pg) throws IOException {
                        return null;
                }
 
                @Override
                // and make it public!
-               public List<Paragraph> makeParagraphs(URL source, String content)
-                               throws IOException {
-                       return super.makeParagraphs(source, content);
+               public List<Paragraph> makeParagraphs(URL source, String content,
+                               Progress pg) throws IOException {
+                       return super.makeParagraphs(source, content, pg);
                }
 
                @Override
@@ -372,5 +451,11 @@ public class BasicSupportTest extends TestLauncher {
                public Paragraph processPara(String line) {
                        return super.processPara(line);
                }
+
+               @Override
+               // and make it public!
+               public List<Paragraph> requotify(Paragraph para) {
+                       return super.requotify(para);
+               }
        }
 }