DocumentParser { public static Document parser(String content) { if (content == null || content.length() == 0) return Document.builder().build(); if (HtmlDocumentParser.isHtml(content)) { return HtmlDocumentParser.parse(content); } else { return new DocumentParser(content).parse(); } } DocumentParser(final String content); static Document parser(String content); static Document parseOptionDescription(final String description);  }
@Test public void paragraphs() { final String content = "This option causes rsync to set the group of the destination file to be the\n" + " same as the source file. If the receiving program is not running as the super-user\n" + " (or if --no-super was specified), only groups that the invoking user on the receiving\n" + " side is a member of will be preserved. Without this option, the group is set to the\n" + " default group of the invok- ing user on the receiving side.\n" + "\n" + " The preservation of group information will associate matching names by default, but\n" + " may fall back to using the ID number in some circumstances (see also the --numeric-ids\n" + " option for a full discussion)."; final Document document = DocumentParser.parser(content); final String actual = Join.join("\n", document.elements); assertEquals("" + "Paragraph{content='This option causes rsync to set the group of the destination" + " file to be the same as the source file. If the receiving program is not running " + "as the super-user (or if --no-super was specified), only groups that the invoking " + "user on the receiving side is a member of will be preserved. Without this option, " + "the group is set to the default group of the invok- ing user on the receiving side.'}\n" + "Paragraph{content='The preservation of group information will associate matching " + "names by default, but may fall back to using the ID number in some circumstances " + "(see also the --numeric-ids option for a full discussion).'}", actual); }
@Test public void headings() { final String content = "= this is a heading\n" + " This is the source file. If the receiving program is not running as the super-user\n" + " (or if --no-super was specified), only groups that the invoking user on the receiving\n" + "\n" + " SECTION 2\n" + " A fall back to using the ID number in some circumstances (see also the --numeric-ids\n" + " option for a full discussion).\n" + " # section 3\n" + " The preservation of group information will associate matching\n"; final Document document = DocumentParser.parser(content); final String actual = Join.join("\n", document.elements); assertEquals("" + "Heading{content='this is a heading'}\n" + "Paragraph{content='This is the source file. If the receiving" + " program is not running as the super-user (or if --no-super " + "was specified), only groups that the invoking user on the receiving'}\n" + "Heading{content='SECTION 2'}\n" + "Paragraph{content='A fall back to using the ID number in " + "some circumstances (see also the --numeric-ids option for a full discussion).'}\n" + "Heading{content='section 3'}\n" + "Paragraph{content='The preservation of group information will associate matching'}", actual); }
@Test public void bullets() { final String content = "" + "This option causes rsync to set the group of the destination file to be the\n" + "same as the source file. If the receiving program is not running as the super-user\n" + " - only groups that the invoking user on the receiving\n" + " - side is a member of will be preserved.\n" + " - Without this option, the group is set to the default group of the invok- ing user on the receiving side.\n" + "\n" + "The preservation of group information will associate matching names by default, but\n" + "may fall back to using the ID number in some circumstances (see also the --numeric-ids\n" + "option for a full discussion)."; final Document document = DocumentParser.parser(content); final String actual = Join.join("\n", document.elements); assertEquals("" + "Paragraph{content='This option causes rsync to set the group of the " + "destination file to be the same as the source file. If the receiving " + "program is not running as the super-user'}\n" + "" + "Bullet{content='only groups that the invoking user on the receiving'}\n" + "Bullet{content='side is a member of will be preserved.'}\n" + "Bullet{content='Without this option, the group is set to the default group" + " of the invok- ing user on the receiving side.'}\n" + "" + "Paragraph{content='The preservation of group information will associate " + "matching names by default, but may fall back to using the ID number in some " + "circumstances (see also the --numeric-ids option for a full discussion).'}", actual); }
@Test public void multilineBullets() { final String content = "" + "This option causes rsync to set the group of the destination file to be the\n" + "same as the source file. " + " - If the receiving program is not running as the super-user\n" + " only groups that the invoking user on the receiving\n" + " side is a member of will be preserved.\n" + " - Without this option, the group is set to the\n" + " default group of the invok- ing user on the receiving side.\n" + "\n" + "The preservation of group information will associate matching names by default, but\n" + "may fall back to using the ID number in some circumstances (see also the --numeric-ids\n" + "option for a full discussion)."; final Document document = DocumentParser.parser(content); final String actual = Join.join("\n", document.elements); assertEquals("" + "Paragraph{content='This option causes rsync to set the group " + "of the destination file to be the same as the source file. - If " + "the receiving program is not running as the super-user only groups" + " that the invoking user on the receiving side is a member of will " + "be preserved.'}\n" + "Bullet{content='Without this option, the group is set to the default " + "group of the invok- ing user on the receiving side.'}\n" + "Paragraph{content='The preservation of group information will associate " + "matching names by default, but may fall back to using the ID number in " + "some circumstances (see also the --numeric-ids option for a full " + "discussion).'}", actual); }
@Test public void preformatted() { final String content = "" + "This option causes rsync to set the group of the destination file to be the\n" + "same as the source file. If the receiving program is not running as the super-user\n" + "\n" + " for (int i = 0; i < 5; i++) {\n" + " System.out.println(i);\n" + " }" + "\n" + "The preservation of group information will associate matching names by default, but\n" + "may fall back to using the ID number in some circumstances (see also the --numeric-ids\n" + "option for a full discussion)."; final Document document = DocumentParser.parser(content); final String actual = Join.join("\n", document.elements); assertEquals("" + "Paragraph{content='This option causes rsync to set the group of the destination " + "file to be the same as the source file. If the receiving program is not running " + "as the super-user'}\n" + "Preformatted{content='for (int i = 0; i < 5; i++) {\n" + " System.out.println(i);\n" + "}'}\n" + "Paragraph{content='The preservation of group information will associate matching " + "names by default, but may fall back to using the ID number in some circumstances " + "(see also the --numeric-ids option for a full discussion).'}", actual); }