Hi Sergiu,

[snip]

The tests below should be split into several testXXX() methods for  
better maintainability (it's also a junit best practice).

>
> +
> +    public void testSectionSplit() throws XWikiException
> +    {
> +        List<DocumentSection> sections;
> +        // Simple test
> +        document.setContent("1 Section 1\n" + "Content of first  
> section\n" + "1.1 Subsection 2\n"
> +            + "Content of second section\n" + "1 Section 3\n" +  
> "Content of section 3");
> +        sections = document.getSplitSectionsAccordingToTitle();
> +        assertEquals(3, sections.size());
> +        assertEquals("Section 1", sections.get(0).getSectionTitle());
> +        assertEquals("1.1", sections.get(1).getSectionLevel());
> +        assertEquals(3, sections.get(2).getSectionNumber());
> +        assertEquals(80, sections.get(2).getSectionIndex());

another test here: testSectionSplitWhenCommentedOutSection()

>
> +        // Test comments don't break the section editing
> +        document.setContent("1 Section 1\n" + "Content of first  
> section\n"
> +            + "## 1.1 Subsection 2\n" + "Content of second section 
> \n" + "1 Section 3\n"
> +            + "Content of section 3");
> +        sections = document.getSplitSectionsAccordingToTitle();
> +        assertEquals(2, sections.size());
> +        assertEquals("Section 1", sections.get(0).getSectionTitle());
> +        assertEquals("1", sections.get(1).getSectionLevel());
> +        assertEquals(2, sections.get(1).getSectionNumber());
> +        assertEquals(83, sections.get(1).getSectionIndex());

another one here

>
> +        // Test spaces are ignored
> +        document.setContent("1 Section 1\n" + "Content of first  
> section\n"
> +            + "   1.1    Subsection 2  \n" + "Content of second  
> section\n" + "1 Section 3\n"
> +            + "Content of section 3");
> +        sections = document.getSplitSectionsAccordingToTitle();
> +        assertEquals(3, sections.size());
> +        assertEquals("Subsection 2  ",  
> sections.get(1).getSectionTitle());
> +        assertEquals("1.1", sections.get(1).getSectionLevel());

another one

>
> +        // Test lower headings are ignored
> +        document.setContent("1 Section 1\n" + "Content of first  
> section\n"
> +            + "1.1.1 Lower subsection\n" + "This content is not  
> important\n"
> +            + "   1.1    Subsection 2  \n" + "Content of second  
> section\n" + "1 Section 3\n"
> +            + "Content of section 3");
> +        sections = document.getSplitSectionsAccordingToTitle();
> +        assertEquals(3, sections.size());
> +        assertEquals("Section 1", sections.get(0).getSectionTitle());
> +        assertEquals("Subsection 2  ",  
> sections.get(1).getSectionTitle());
> +        assertEquals("1.1", sections.get(1).getSectionLevel());

another one

>
> +        // Test blank lines are preserved
> +        document.setContent("\n\n1 Section 1\n\n\n" + "Content of  
> first section\n\n\n"
> +            + "   1.1    Subsection 2  \n\n" + "Content of second  
> section\n" + "1 Section 3\n"
> +            + "Content of section 3");
> +        sections = document.getSplitSectionsAccordingToTitle();
> +        assertEquals(3, sections.size());
> +        assertEquals(2, sections.get(0).getSectionIndex());
> +        assertEquals("Subsection 2  ",  
> sections.get(1).getSectionTitle());
> +        assertEquals(43, sections.get(1).getSectionIndex());
> +    }
> }

thanks
-Vincent

PS: cool for the tests :)

_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to