11package com.orgzly.android.ui.notes
22
3- import com.orgzly.android.ui.notes.NoteContent.TableNoteContent
4- import com.orgzly.android.ui.notes.NoteContent.TextNoteContent
53import org.hamcrest.Matchers.emptyCollectionOf
64import org.junit.Assert.assertEquals
75import org.junit.Assert.assertThat
@@ -19,7 +17,7 @@ class NoteContentTest {
1917
2018 @Test
2119 fun emptyLinesShouldStayInSingleSection () {
22- checkExpected(" \n\n " , listOf (TextNoteContent (" \n\n " )))
20+ checkExpected(" \n\n " , listOf (NoteContent (" \n\n " , 0 , 1 , NoteContent . TextType . TEXT )))
2321 }
2422
2523 @Test
@@ -28,36 +26,36 @@ class NoteContentTest {
2826|
2927
3028foo|bar""" , listOf (
31- TextNoteContent (" foo\n " ),
32- TableNoteContent (" |\n " ),
33- TextNoteContent (" \n foo|bar" )
29+ NoteContent (" foo\n " , 0 , 3 , NoteContent . TextType . TEXT ),
30+ NoteContent (" |\n " , 4 , 5 , NoteContent . TextType . TABLE ),
31+ NoteContent (" \n foo|bar" , 6 , 13 , NoteContent . TextType . TEXT )
3432 ))
3533 }
3634
3735 @Test
3836 fun singleTable () {
3937 checkExpected(""" |a|b|
4038|c|d|
41- """ , listOf (TableNoteContent (""" |a|b|
39+ """ , listOf (NoteContent (""" |a|b|
4240|c|d|
43- """ )))
41+ """ , 0 , 11 , NoteContent . TextType . TABLE )))
4442 }
4543
4644 @Test
4745 fun singleTableNoFinalNewline () {
4846 checkExpected(""" |a|b|
49- |c|d|""" , listOf (TableNoteContent (""" |a|b|
50- |c|d|""" )))
47+ |c|d|""" , listOf (NoteContent (""" |a|b|
48+ |c|d|""" , 0 , 10 , NoteContent . TextType . TABLE )))
5149 }
5250
5351 @Test
5452 fun singleLineTextTableText () {
5553 checkExpected(""" foo
5654|
5755bar""" , listOf (
58- TextNoteContent (" foo\n " ),
59- TableNoteContent (" |\n " ),
60- TextNoteContent (" bar" )
56+ NoteContent (" foo\n " , 0 , 3 , NoteContent . TextType . TEXT ),
57+ NoteContent (" |\n " , 4 , 5 , NoteContent . TextType . TABLE ),
58+ NoteContent (" bar" , 6 , 8 , NoteContent . TextType . TEXT )
6159 ))
6260 }
6361
@@ -68,9 +66,9 @@ bar""", listOf(
6866|
6967bar
7068""" , listOf (
71- TextNoteContent (" \n " ),
72- TableNoteContent (" |\n " ),
73- TextNoteContent (" bar\n " )
69+ NoteContent (" \n " , 0 , 0 , NoteContent . TextType . TEXT ),
70+ NoteContent (" |\n " , 1 , 2 , NoteContent . TextType . TABLE ),
71+ NoteContent (" bar\n " , 3 , 6 , NoteContent . TextType . TEXT )
7472 ))
7573 }
7674
7977 checkExpected(""" |zoo|
8078
8179|zog|""" , listOf (
82- TableNoteContent (" |zoo|\n " ),
83- TextNoteContent (" \n " ),
84- TableNoteContent (" |zog|" )
80+ NoteContent (" |zoo|\n " , 0 , 5 , NoteContent . TextType . TABLE ),
81+ NoteContent (" \n " , 6 , 6 , NoteContent . TextType . TEXT ),
82+ NoteContent (" |zog|" , 7 , 11 , NoteContent . TextType . TABLE )
8583 ))
8684 }
8785
9189|
9290
9391chops""" , listOf (
94- TextNoteContent (" foo\n " ),
95- TableNoteContent (" |\n " ),
96- TextNoteContent (" \n chops" )
92+ NoteContent (" foo\n " , 0 , 3 , NoteContent . TextType . TEXT ),
93+ NoteContent (" |\n " , 4 , 5 , NoteContent . TextType . TABLE ),
94+ NoteContent (" \n chops" , 6 , 11 , NoteContent . TextType . TEXT )
9795 ))
9896 }
9997
@@ -109,11 +107,11 @@ text3c
109107|table4|
110108text5
111109""" , listOf (
112- TextNoteContent (" text1\n " ),
113- TableNoteContent (" |table2a|\n |table2b|\n " ),
114- TextNoteContent (" text3a\n text3b\n text3c\n " ),
115- TableNoteContent (" |table4|\n " ),
116- TextNoteContent (" text5\n " )
110+ NoteContent (" text1\n " , 0 , 5 , NoteContent . TextType . TEXT ),
111+ NoteContent (" |table2a|\n |table2b|\n " , 6 , 25 , NoteContent . TextType . TABLE ),
112+ NoteContent (" text3a\n text3b\n text3c\n " , 26 , 46 , NoteContent . TextType . TEXT ),
113+ NoteContent (" |table4|\n " , 47 , 55 , NoteContent . TextType . TABLE ),
114+ NoteContent (" text5\n " , 56 , 61 , NoteContent . TextType . TEXT )
117115 ))
118116 }
119117
@@ -150,5 +148,8 @@ text5
150148
151149 assertEquals(input, roundTripped)
152150
151+ actual.forEach {
152+ assertEquals(it.text, input.substring(it.startOffset, it.endOffset + 1 ))
153+ }
153154 }
154155}
0 commit comments