Search in sources :

Example 6 with NotePosition

use of com.orgzly.android.NotePosition in project orgzly-android by orgzly.

the class MiscTest method testLftRgt.

@Test
public void testLftRgt() {
    shelfTestUtils.setupBook("booky", "Preface\n* Note 1\n** Note 2\n* Note 3\n");
    activityRule.launchActivity(null);
    NotePosition n1 = shelf.getNote("Note 1").getPosition();
    NotePosition n2 = shelf.getNote("Note 2").getPosition();
    NotePosition n3 = shelf.getNote("Note 3").getPosition();
    assertTrue(n1.getLft() < n2.getLft());
    assertTrue(n2.getLft() < n2.getRgt());
    assertTrue(n2.getRgt() < n1.getRgt());
    assertTrue(n1.getRgt() < n3.getLft());
    assertTrue(n3.getLft() < n3.getRgt());
}
Also used : NotePosition(com.orgzly.android.NotePosition) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 7 with NotePosition

use of com.orgzly.android.NotePosition in project orgzly-android by orgzly.

the class StructureTest method testPasteUnder.

@Test
public void testPasteUnder() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "*** Note 1.1.1\n" + "** Note 1.2\n" + "*** Note 1.2.1\n" + "*** Note 1.2.2\n" + "* Note 2\n");
    /* Cut & paste 1.1 under 1.2. */
    shelf.cut(book.getId(), shelf.getNote("Note 1.1").getId());
    Note n = shelf.getNote("Note 1.2");
    shelf.paste(n.getPosition().getBookId(), n.getId(), Place.UNDER);
    assertEquals("description\n" + "\n" + "* Note 1\n" + "** Note 1.2\n" + "*** Note 1.2.1\n" + "*** Note 1.2.2\n" + "*** Note 1.1\n" + "**** Note 1.1.1\n" + "* Note 2\n", shelf.getBookContent("notebook", BookName.Format.ORG));
    NotePosition n1 = shelf.getNote("Note 1").getPosition();
    NotePosition n12 = shelf.getNote("Note 1.2").getPosition();
    NotePosition n121 = shelf.getNote("Note 1.2.1").getPosition();
    NotePosition n122 = shelf.getNote("Note 1.2.2").getPosition();
    NotePosition n11 = shelf.getNote("Note 1.1").getPosition();
    NotePosition n111 = shelf.getNote("Note 1.1.1").getPosition();
    NotePosition n2 = shelf.getNote("Note 2").getPosition();
    assertEquals(shelf.getNote("Note 1.2").getId(), n11.getParentId());
    assertEquals(1, n1.getLevel());
    assertEquals(2, n12.getLevel());
    assertEquals(3, n121.getLevel());
    assertEquals(3, n122.getLevel());
    assertEquals(3, n11.getLevel());
    assertEquals(4, n111.getLevel());
    assertEquals(1, n2.getLevel());
    assertTrue(n1.getLft() < n12.getLft());
    assertTrue(n12.getLft() < n121.getLft());
    assertTrue(n121.getLft() < n121.getRgt());
    assertTrue(n121.getRgt() < n122.getLft());
    assertTrue(n122.getLft() < n122.getRgt());
    assertTrue(n122.getRgt() < n11.getLft());
    assertTrue(n11.getLft() < n111.getLft());
    assertTrue(n111.getLft() < n111.getRgt());
    assertTrue(n111.getRgt() < n11.getRgt());
    assertTrue(n11.getRgt() < n12.getRgt());
    assertTrue(n12.getRgt() < n1.getRgt());
    assertTrue(n1.getRgt() < n2.getLft());
    assertTrue(n2.getLft() < n2.getRgt());
    assertEquals(5, n1.getDescendantsCount());
    assertEquals(4, n12.getDescendantsCount());
    assertEquals(0, n121.getDescendantsCount());
    assertEquals(0, n122.getDescendantsCount());
    assertEquals(1, n11.getDescendantsCount());
    assertEquals(0, n111.getDescendantsCount());
    assertEquals(0, n2.getDescendantsCount());
}
Also used : Book(com.orgzly.android.Book) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 8 with NotePosition

use of com.orgzly.android.NotePosition in project orgzly-android by orgzly.

the class StructureTest method testPromoteFolded.

@Test
public void testPromoteFolded() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "*** Note 1.1.1\n" + "** Note 1.2\n" + "* Note 2\n");
    Note note = shelf.getNote("Note 1.1");
    /* Promote folded 1.1 */
    shelf.toggleFoldedState(note.getId());
    assertEquals(1, shelf.promote(book.getId(), note.getId()));
    assertEquals("description\n" + "\n" + "* Note 1\n" + "** Note 1.2\n" + "* Note 1.1\n" + "** Note 1.1.1\n" + "* Note 2\n", shelf.getBookContent("notebook", BookName.Format.ORG));
    NotePosition n1 = shelf.getNote("Note 1").getPosition();
    NotePosition n12 = shelf.getNote("Note 1.2").getPosition();
    NotePosition n11 = shelf.getNote("Note 1.1").getPosition();
    NotePosition n111 = shelf.getNote("Note 1.1.1").getPosition();
    NotePosition n2 = shelf.getNote("Note 2").getPosition();
    assertEquals(1, n1.getDescendantsCount());
    assertEquals(0, n12.getDescendantsCount());
    assertEquals(1, n11.getDescendantsCount());
    assertEquals(0, n111.getDescendantsCount());
    assertEquals(0, n2.getDescendantsCount());
    assertEquals(1, n1.getLevel());
    assertEquals(2, n12.getLevel());
    assertEquals(1, n11.getLevel());
    assertEquals(2, n111.getLevel());
    assertEquals(1, n2.getLevel());
    assertEquals(0, n1.getFoldedUnderId());
    assertEquals(0, n12.getFoldedUnderId());
    assertEquals(0, n11.getFoldedUnderId());
    assertEquals(shelf.getNote("Note 1.1").getId(), n111.getFoldedUnderId());
    assertEquals(0, n2.getFoldedUnderId());
    assertFalse(n1.isFolded());
    assertFalse(n12.isFolded());
    assertTrue(n11.isFolded());
    assertFalse(n111.isFolded());
    assertFalse(n2.isFolded());
    assertTrue(n1.getLft() < n12.getLft());
    assertTrue(n12.getLft() < n12.getRgt());
    assertTrue(n12.getRgt() < n11.getRgt());
    assertTrue(n1.getRgt() < n11.getLft());
    assertTrue(n11.getLft() < n111.getLft());
    assertTrue(n111.getLft() < n111.getRgt());
    assertTrue(n111.getRgt() < n11.getRgt());
    assertTrue(n11.getRgt() < n2.getLft());
    assertTrue(n2.getLft() < n2.getRgt());
}
Also used : Book(com.orgzly.android.Book) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 9 with NotePosition

use of com.orgzly.android.NotePosition in project orgzly-android by orgzly.

the class StructureTest method testPromote.

@Test
public void testPromote() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "* Note 2\n");
    Note note = shelf.getNote("Note 1.1");
    /* TODO: Assert 0 if trying to promote level 1 note. */
    assertEquals(1, shelf.promote(book.getId(), note.getId()));
    assertEquals("description\n" + "\n" + "* Note 1\n" + "* Note 1.1\n" + "* Note 2\n", shelf.getBookContent("notebook", BookName.Format.ORG));
    NotePosition n1 = shelf.getNote("Note 1").getPosition();
    NotePosition n11 = shelf.getNote("Note 1.1").getPosition();
    NotePosition n2 = shelf.getNote("Note 2").getPosition();
    assertEquals(0, n1.getDescendantsCount());
    assertEquals(0, n11.getDescendantsCount());
    assertEquals(0, n2.getDescendantsCount());
    assertEquals(1, n1.getLevel());
    assertEquals(1, n11.getLevel());
    assertEquals(1, n2.getLevel());
    assertTrue(n1.getLft() < n1.getRgt());
    assertTrue(n1.getRgt() < n11.getLft());
    assertTrue(n11.getLft() < n11.getRgt());
    assertTrue(n11.getRgt() < n2.getLft());
    assertTrue(n2.getLft() < n2.getRgt());
}
Also used : Book(com.orgzly.android.Book) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 10 with NotePosition

use of com.orgzly.android.NotePosition in project orgzly-android by orgzly.

the class StructureTest method testNewBelowFoldable.

@Test
public void testNewBelowFoldable() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n");
    Note newNote = new Note();
    newNote.getPosition().setBookId(book.getId());
    newNote.getHead().setTitle("Note 2");
    shelf.createNote(newNote, new NotePlace(book.getId(), shelf.getNote("Note 1").getId(), Place.BELOW));
    assertEquals("description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "* Note 2\n", shelf.getBookContent("notebook", BookName.Format.ORG));
    NotePosition n1 = shelf.getNote("Note 1").getPosition();
    NotePosition n11 = shelf.getNote("Note 1.1").getPosition();
    NotePosition n2 = shelf.getNote("Note 2").getPosition();
    assertTrue(n1.getLft() < n11.getLft());
    assertTrue(n11.getLft() < n11.getRgt());
    assertTrue(n11.getRgt() < n1.getRgt());
    assertTrue(n1.getRgt() < n2.getLft());
    assertTrue(n2.getLft() < n2.getRgt());
    assertEquals(0, n2.getDescendantsCount());
    assertEquals(shelf.getNote("").getId(), n2.getParentId());
}
Also used : Book(com.orgzly.android.Book) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) NotePlace(com.orgzly.android.ui.NotePlace) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

NotePosition (com.orgzly.android.NotePosition)22 OrgzlyTest (com.orgzly.android.OrgzlyTest)13 Test (org.junit.Test)13 Book (com.orgzly.android.Book)11 Note (com.orgzly.android.Note)11 Cursor (android.database.Cursor)6 ContentValues (android.content.ContentValues)5 NotePlace (com.orgzly.android.ui.NotePlace)4 SuppressLint (android.annotation.SuppressLint)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Uri (android.net.Uri)1 DbNote (com.orgzly.android.provider.models.DbNote)1 SqliteQueryBuilder (com.orgzly.android.query.sql.SqliteQueryBuilder)1 OrgFile (com.orgzly.org.OrgFile)1 OrgHead (com.orgzly.org.OrgHead)1 OrgProperties (com.orgzly.org.OrgProperties)1 OrgNestedSetParserListener (com.orgzly.org.parser.OrgNestedSetParserListener)1 OrgNodeInSet (com.orgzly.org.parser.OrgNodeInSet)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1