Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary toPath in TreeStyleOpInfo #150

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ jobs:
disable-animations: true
script: |
adb shell pm list packages | grep dev.yorkie.test && adb uninstall dev.yorkie.test || true;
./gradlew yorkie:connectedCheck -Pandroid.testInstrumentationRunnerArguments.notAnnotation=androidx.test.filters.LargeTest --no-build-cache --no-daemon --stacktrace
./gradlew yorkie:connectedCheck -Pandroid.testInstrumentationRunnerArguments.annotation=androidx.test.filters.LargeTest --no-build-cache --no-daemon --stacktrace
./gradlew yorkie:connectedCheck -Pandroid.testInstrumentationRunnerArguments.notAnnotation=dev.yorkie.TreeTest --no-build-cache --no-daemon --stacktrace
./gradlew yorkie:connectedCheck -Pandroid.testInstrumentationRunnerArguments.annotation=dev.yorkie.TreeBasicTest --no-build-cache --no-daemon --stacktrace
./gradlew yorkie:connectedCheck -Pandroid.testInstrumentationRunnerArguments.annotation=dev.yorkie.TreeSplitMergeTest --no-build-cache --no-daemon --stacktrace
- if: ${{ matrix.api-level == 24 }}
run: ./gradlew yorkie:jacocoDebugTestReport
- if: ${{ matrix.api-level == 24 }}
Expand Down
13 changes: 13 additions & 0 deletions yorkie/src/androidTest/kotlin/dev/yorkie/TestAnnotations.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.yorkie

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class TreeTest

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class TreeBasicTest

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class TreeSplitMergeTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
package dev.yorkie.document.json

import androidx.test.ext.junit.runners.AndroidJUnit4
import dev.yorkie.TreeSplitMergeTest
import dev.yorkie.TreeTest
import dev.yorkie.core.withTwoClientsAndDocuments
import dev.yorkie.document.json.JsonTreeTest.Companion.rootTree
import kotlin.test.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

@TreeTest
@TreeSplitMergeTest
@RunWith(AndroidJUnit4::class)
class JsonTreeSplitMergeTest {

@Test
fun test_contained_split_and_split_at_the_same_position() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.setNewTree(
"t",
TreeBuilder.element("r") {
element("p") {
text { "ab" }
}
},
)
},
JsonTreeTest.Companion.Updater(c2, d2),
)
JsonTreeTest.assertTreesXmlEquals("<r><p>ab</p></r>", d1, d2)

JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 1)
},
JsonTreeTest.Companion.Updater(c2, d2) { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 1)
},
) {
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p>b</p></r>", d1, d2)
}
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p></p><p>b</p></r>", d1, d2)
}
}

@Test
fun test_contained_split_and_split_at_different_positions_on_the_same_node() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.setNewTree(
"t",
TreeBuilder.element("r") {
element("p") {
text { "abc" }
}
},
)
},
JsonTreeTest.Companion.Updater(c2, d2),
)
JsonTreeTest.assertTreesXmlEquals("<r><p>abc</p></r>", d1, d2)

JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 1)
},
JsonTreeTest.Companion.Updater(c2, d2) { root, _ ->
root.rootTree().edit(3, 3, splitLevel = 1)
},
) {
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p>bc</p></r>", d1)
JsonTreeTest.assertTreesXmlEquals("<r><p>ab</p><p>c</p></r>", d2)
}
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p>b</p><p>c</p></r>", d1, d2)
}
}

@Test
fun test_contained_split_and_insert_into_the_split_position() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.setNewTree(
"t",
TreeBuilder.element("r") {
element("p") {
text { "ab" }
}
},
)
},
JsonTreeTest.Companion.Updater(c2, d2),
)
JsonTreeTest.assertTreesXmlEquals("<r><p>ab</p></r>", d1, d2)

JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 1)
},
JsonTreeTest.Companion.Updater(c2, d2) { root, _ ->
root.rootTree().edit(2, 2, TreeBuilder.text { "c" })
},
) {
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p>b</p></r>", d1)
JsonTreeTest.assertTreesXmlEquals("<r><p>acb</p></r>", d2)
}
JsonTreeTest.assertTreesXmlEquals("<r><p>ac</p><p>b</p></r>", d1, d2)
}
}

@Test
fun test_contained_split_and_insert_into_original_node() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.setNewTree(
"t",
TreeBuilder.element("r") {
element("p") {
text { "ab" }
}
},
)
},
JsonTreeTest.Companion.Updater(c2, d2),
)
JsonTreeTest.assertTreesXmlEquals("<r><p>ab</p></r>", d1, d2)

JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 1)
},
JsonTreeTest.Companion.Updater(c2, d2) { root, _ ->
root.rootTree().edit(1, 1, TreeBuilder.text { "c" })
},
) {
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p>b</p></r>", d1)
JsonTreeTest.assertTreesXmlEquals("<r><p>cab</p></r>", d2)
}
JsonTreeTest.assertTreesXmlEquals("<r><p>ca</p><p>b</p></r>", d1, d2)
}
}

@Test
fun test_contained_split_and_insert_into_split_node() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.setNewTree(
"t",
TreeBuilder.element("r") {
element("p") {
text { "ab" }
}
},
)
},
JsonTreeTest.Companion.Updater(c2, d2),
)
JsonTreeTest.assertTreesXmlEquals("<r><p>ab</p></r>", d1, d2)

JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 1)
},
JsonTreeTest.Companion.Updater(c2, d2) { root, _ ->
root.rootTree().edit(3, 3, TreeBuilder.text { "c" })
},
) {
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p>b</p></r>", d1)
JsonTreeTest.assertTreesXmlEquals("<r><p>abc</p></r>", d2)
}
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p>bc</p></r>", d2)
}
}

@Test
fun test_contained_split_and_delete_contents_in_split_node() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.setNewTree(
"t",
TreeBuilder.element("r") {
element("p") {
text { "ab" }
}
},
)
},
JsonTreeTest.Companion.Updater(c2, d2),
)
JsonTreeTest.assertTreesXmlEquals("<r><p>ab</p></r>", d1, d2)

JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 1)
},
JsonTreeTest.Companion.Updater(c2, d2) { root, _ ->
root.rootTree().edit(2, 3)
},
) {
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p>b</p></r>", d1)
JsonTreeTest.assertTreesXmlEquals("<r><p>a</p></r>", d2)
}

JsonTreeTest.assertTreesXmlEquals("<r><p>a</p><p></p></r>", d1, d2)
}
}

@Test
fun test_split_and_merge_with_empty_paragraph_left() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
d1.updateAsync { root, _ ->
root.setNewTree(
"t",
TreeBuilder.element("doc") {
element("p") {
text { "a" }
text { "b" }
}
},
)
}.await()
JsonTreeTest.assertTreesXmlEquals("<doc><p>ab</p></doc>", d1)

d1.updateAsync { root, _ ->
root.rootTree().edit(1, 1, splitLevel = 1)
}.await()
JsonTreeTest.assertTreesXmlEquals("<doc><p></p><p>ab</p></doc>", d1)

JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.rootTree().edit(1, 3)
},
JsonTreeTest.Companion.Updater(c2, d2),
)
JsonTreeTest.assertTreesXmlEquals("<doc><p>ab</p></doc>", d1, d2)
}
}

@Test
fun test_split_and_merge_with_empty_paragraph_left_and_multiple_split_level_left() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
d1.updateAsync { root, _ ->
root.setNewTree(
"t",
TreeBuilder.element("doc") {
element("p") {
element("p") {
text { "a" }
text { "b" }
}
}
},
)
}.await()
assertEquals("<doc><p><p>ab</p></p></doc>", d1.getRoot().rootTree().toXml())

d1.updateAsync { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 2)
}.await()
assertEquals(
"<doc><p><p></p></p><p><p>ab</p></p></doc>",
d1.getRoot().rootTree().toXml(),
)

JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.rootTree().edit(2, 6)
},
JsonTreeTest.Companion.Updater(c2, d2),
)
JsonTreeTest.assertTreesXmlEquals("<doc><p><p>ab</p></p></doc>", d1, d2)
}
}

@Test
fun test_split_same_offset_multiple_times() {
withTwoClientsAndDocuments(realTimeSync = false) { c1, c2, d1, d2, _ ->
d1.updateAsync { root, _ ->
root.setNewTree(
"t",
TreeBuilder.element("doc") {
element("p") {
text { "a" }
text { "b" }
}
},
)
}.await()
assertEquals("<doc><p>ab</p></doc>", d1.getRoot().rootTree().toXml())

d1.updateAsync { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 1)
}.await()
assertEquals("<doc><p>a</p><p>b</p></doc>", d1.getRoot().rootTree().toXml())

d1.updateAsync { root, _ ->
root.rootTree().edit(2, 2, TreeBuilder.text { "c" })
}.await()
assertEquals("<doc><p>ac</p><p>b</p></doc>", d1.getRoot().rootTree().toXml())

d1.updateAsync { root, _ ->
root.rootTree().edit(2, 2, splitLevel = 1)
}.await()
assertEquals("<doc><p>a</p><p>c</p><p>b</p></doc>", d1.getRoot().rootTree().toXml())

JsonTreeTest.updateAndSync(
JsonTreeTest.Companion.Updater(c1, d1) { root, _ ->
root.rootTree().edit(2, 7)
},
JsonTreeTest.Companion.Updater(c2, d2),
)
JsonTreeTest.assertTreesXmlEquals("<doc><p>ab</p></doc>", d1, d2)
}
}
}
Loading
Loading