public String toString(OrgParserSettings settings) { StringBuilder str = new StringBuilder(); OrgParserWriter parserWriter = new OrgParserWriter(settings); str.append(parserWriter.whiteSpacedFilePreface(file.getPreface())); for (OrgNodeInList nodeInList : headsInList) { str.append(parserWriter.whiteSpacedHead(nodeInList, file.getSettings().isIndented())); } return str.toString(); } }
OrgFile orgFile = new OrgFile(); if (orgFile.getSettings().parseLine(line)) { orgFile.getSettings().setIndented(indentedCount > 0); listener.onFile(orgFile);
/** * Removes empty lines before and after the content. * Called before every announcement. */ private void setTrimmedPreface(OrgFile file, String preface) { file.setPreface(OrgStringUtils.trimLines(preface)); } }
@Test public void testFileSettingsKeywords() throws IOException { OrgParsedFile file = parserBuilder.setInput("#+TITLE: Wrong title\n#+NEWKEYWORD:\n#+TITLE: Org Title\n\n* TODO Note\n").build().parse(); Assert.assertNotNull(file.getFile().getSettings()); Assert.assertNotNull(file.getFile().getSettings().getTitle()); Assert.assertEquals("Org Title", file.getFile().getSettings().getTitle()); Assert.assertNull(file.getFile().getSettings().getKeywordValues(OrgFileSettings.TITLE)); Assert.assertNull(file.getFile().getSettings().getLastKeywordValue("NEWKEYWORD")); Assert.assertTrue(file.getFile().getSettings().getKeywordValues("NEWKEYWORD").isEmpty()); }
@Test public void testSimpleNonASCIICharacters() throws IOException { String preface = parserBuilder.setInput("DIE PERSER (Ü: Andreas Röhler) Schauspiel 1 D 3 H Stand:").build().parse().getFile().getPreface(); Assert.assertEquals("DIE PERSER (Ü: Andreas Röhler) Schauspiel 1 D 3 H Stand:", preface); Assert.assertEquals("DIE PERSER (Ü: Andreas Röhler) Schauspiel 1 D 3 H Stand:\n\n", parserWriter.whiteSpacedFilePreface(preface)); }
@Test public void testFileSettingsTitle() throws IOException { OrgParsedFile file = parserBuilder.setInput("#+TITLE: Org Title\n\n* TODO Note\n").build().parse(); Assert.assertNotNull(file.getFile().getSettings()); Assert.assertNotNull(file.getFile().getSettings().getTitle()); Assert.assertEquals("Org Title", file.getFile().getSettings().getTitle()); }
@Test public void testContentBeforeFirstEntry() throws IOException { String fileContent = "Text on top!\n" + "\n" + "* This is the first line with tag at the end of the line :tag1:\n" + "** [#A] Second heading with priority :tag2:\n" + "*** TODO [#B]Third heading with spaced priority :tag3:\n" + "**** DONE Heading number 4 :tag:todo:\n"; OrgParsedFile file = parserBuilder.setInput(fileContent).build().parse(); Assert.assertEquals("Text on top!", file.getFile().getPreface()); Assert.assertEquals("This is the first line with tag at the end of the line", file.getHeadsInList().get(0).getHead().getTitle()); Assert.assertEquals("Second heading with priority", file.getHeadsInList().get(1).getHead().getTitle()); Assert.assertEquals("Third heading with spaced priority", file.getHeadsInList().get(2).getHead().getTitle()); Assert.assertEquals("Heading number 4", file.getHeadsInList().get(3).getHead().getTitle()); }
@Test public void testFileSettingsAlwaysNonNull() throws IOException { OrgParsedFile file = parserBuilder.setInput("* TODO Note").build().parse(); Assert.assertNotNull(file.getFile().getSettings()); Assert.assertNull(file.getFile().getSettings().getTitle()); }
@Test public void testComplicatedTimestamp() throws IOException { String fileContent = "** TODO Shave\n" + "SCHEDULED: <2009-10-17 Sat .+2d/4d>\n" + " - State \"DONE\" from \"TODO\" [2009-10-15 Thu]\n" + " - State \"DONE\" from \"TODO\" [2009-10-12 Mon]\n" + " :PROPERTIES:\n" + " :STYLE: habit\n" + " :LAST_REPEAT: [2009-10-19 Mon 00:36]\n" + " :END:"; OrgParsedFile file = parserBuilder.setInput(fileContent).build().parse(); Assert.assertEquals("", file.getFile().getPreface()); Assert.assertEquals("Shave", file.getHeadsInList().get(0).getHead().getTitle()); Assert.assertEquals("<2009-10-17 Sat .+2d/4d>", file.getHeadsInList().get(0).getHead().getScheduled().getStartTime().toString()); Assert.assertEquals("** TODO Shave\n" + "SCHEDULED: <2009-10-17 Sat .+2d/4d>\n" + " - State \"DONE\" from \"TODO\" [2009-10-15 Thu]\n" + " - State \"DONE\" from \"TODO\" [2009-10-12 Mon]\n" + " :PROPERTIES:\n" + " :STYLE: habit\n" + " :LAST_REPEAT: [2009-10-19 Mon 00:36]\n" + " :END:\n\n", file.toString()); }
@Test public void testFileSettingsTrimUnsupportedKeyword() throws IOException { OrgParsedFile file = parserBuilder.setInput("#+NAME: value value ").build().parse(); Assert.assertEquals("value value", file.getFile().getSettings().getLastKeywordValue("NAME")); }
@Test public void testNotIndented() throws IOException { OrgParsedFile file = parserBuilder.setInput("* TODO Title\nSCHEDULED: <2015-02-11 Wed +1d>").build().parse(); Assert.assertFalse(file.getFile().getSettings().isIndented()); }
@Test public void testFileSettingsTrimSupportedKeyword() throws IOException { OrgParsedFile file = parserBuilder.setInput("#+TITLE: Title ").build().parse(); Assert.assertEquals("Title", file.getFile().getSettings().getTitle()); }
@Test public void testIndented() throws IOException { OrgParsedFile file = parserBuilder.setInput("* TODO Title\n SCHEDULED: <2015-02-11 Wed +1d>").build().parse(); Assert.assertTrue(file.getFile().getSettings().isIndented()); }
@Test public void testFileSettingsUnsupportedKeyword() throws IOException { OrgParsedFile file = parserBuilder.setInput("#+FOO: bar").build().parse(); Assert.assertEquals("bar", file.getFile().getSettings().getLastKeywordValue("FOO")); }
@Test public void testIndentedAfterCounting() throws IOException { OrgParsedFile file = parserBuilder.setInput("* TODO Title\n SCHEDULED: <2015-02-11 Wed +1d>\nDEADLINE: <2015-02-08 Sun>\n CLOSED: [2015-02-08 Sun]").build().parse(); Assert.assertTrue(file.getFile().getSettings().isIndented()); }
@Test public void testNotIndentedAfterCounting() throws IOException { OrgParsedFile file = parserBuilder.setInput("* TODO Title\nSCHEDULED: <2015-02-11 Wed +1d>\nDEADLINE: <2015-02-08 Sun>\n CLOCK: [2015-02-07 Sat 20:47]--[2015-02-07 Sat 20:47] => 0:00").build().parse(); Assert.assertFalse(file.getFile().getSettings().isIndented()); }