Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
804778b0fc | |||
0e1afa6dc8 |
19
README.md
19
README.md
@@ -10,6 +10,25 @@ The package is named `tinyvm` for 'tiny version manager'.
|
|||||||
Since this is an internship application project, I have assumed that a minimal usage of external libraries is preferred,
|
Since this is an internship application project, I have assumed that a minimal usage of external libraries is preferred,
|
||||||
so that a greater technical understanding can be demonstrated.
|
so that a greater technical understanding can be demonstrated.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Gradle
|
||||||
|
```kotlin
|
||||||
|
repositories {
|
||||||
|
// other repositories
|
||||||
|
maven { url "https://git.koval.net/api/packages/cyclane/maven" }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("net.koval.teamcity-gitea-test-task:tinyvm:0.1.0")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Documentation
|
||||||
|
Use autocompletion and hover menus in your IDE, or download the
|
||||||
|
[generated HTML documentation](https://git.koval.net/cyclane/teamcity-gitea-test-task/releases/download/v0.1.0/tinyvm-0.1.0-javadoc.zip)
|
||||||
|
from the [latest release](https://git.koval.net/cyclane/teamcity-gitea-test-task/releases).
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
|
|
||||||
Create a library that implements simple Git functionality. You need to implement at least three entities:
|
Create a library that implements simple Git functionality. You need to implement at least three entities:
|
||||||
|
@@ -15,9 +15,22 @@ class Tree(val nodes: Map<String, Node>) : Node("tree") {
|
|||||||
nodes.map { (name, node) ->
|
nodes.map { (name, node) ->
|
||||||
"${node.type} $name\u0000${node.hash()}"
|
"${node.type} $name\u0000${node.hash()}"
|
||||||
}.sorted().joinToString()
|
}.sorted().joinToString()
|
||||||
|
|
||||||
|
override fun toString(): String =
|
||||||
|
"tree ${hash()}\n" +
|
||||||
|
nodes.map { (name, node) ->
|
||||||
|
when (node) {
|
||||||
|
is Tree -> "+$name/\n"
|
||||||
|
is Blob -> "+$name\n"
|
||||||
|
} + node.toString().leftMargin()
|
||||||
|
}.sorted().joinToString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A blob is a data container.
|
* A blob is a data container.
|
||||||
*/
|
*/
|
||||||
class Blob(override val data: String) : Node("blob")
|
class Blob(override val data: String) : Node("blob") {
|
||||||
|
override fun toString(): String = "blob ${hash()}\n${data.leftMargin()}"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String.leftMargin(): String = split('\n').joinToString("\n") { "| $it" }
|
@@ -18,22 +18,22 @@ internal class RepositoryTest {
|
|||||||
tree =
|
tree =
|
||||||
Tree(
|
Tree(
|
||||||
mapOf(
|
mapOf(
|
||||||
|
"dir2" to
|
||||||
|
Tree(
|
||||||
|
mapOf(
|
||||||
|
"test1.txt" to Blob("This is a second file"),
|
||||||
|
),
|
||||||
|
),
|
||||||
"dir1" to
|
"dir1" to
|
||||||
Tree(
|
Tree(
|
||||||
mapOf(
|
mapOf(
|
||||||
"test1.txt" to Blob("Hello World!"),
|
"test1.txt" to Blob("Hello World!"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
"dir2" to
|
|
||||||
Tree(
|
|
||||||
mapOf(
|
|
||||||
"test2.txt" to Blob("This is a second file"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
author = Author("Gleb Koval", "gleb@koval.net"),
|
author = Author("Gleb Koval", "gleb@koval.net"),
|
||||||
message = "Move test1.txt and add dir2/test2.txt",
|
message = "Move test1.txt to dir1 and add dir2/test1.txt",
|
||||||
timestamp = Instant.ofEpochSecond(50),
|
timestamp = Instant.ofEpochSecond(50),
|
||||||
),
|
),
|
||||||
Commit(
|
Commit(
|
||||||
@@ -49,7 +49,7 @@ internal class RepositoryTest {
|
|||||||
"dir2" to
|
"dir2" to
|
||||||
Tree(
|
Tree(
|
||||||
mapOf(
|
mapOf(
|
||||||
"test2.txt" to Blob("This is a second file"),
|
"test1.txt" to Blob("This is a second file"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
"README.md" to Blob("# This is a test repo!"),
|
"README.md" to Blob("# This is a test repo!"),
|
||||||
@@ -117,4 +117,39 @@ internal class RepositoryTest {
|
|||||||
assertEquals(committed, repository.findCommit { it.message.matches("Move.*".toRegex()) })
|
assertEquals(committed, repository.findCommit { it.message.matches("Move.*".toRegex()) })
|
||||||
assertEquals(null, repository.getCommit("00000000000000000000"))
|
assertEquals(null, repository.getCommit("00000000000000000000"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `can display commit`() {
|
||||||
|
assertEquals(
|
||||||
|
"""
|
||||||
|
commit 804c6f0c66da0ea0eab8ac29f23a627e03a962b2
|
||||||
|
tree aaebbb258bce30749fc302cbd161b78462252a32
|
||||||
|
author Gleb Koval <gleb@koval.net>
|
||||||
|
timestamp 0
|
||||||
|
|
||||||
|
Add test1.txt
|
||||||
|
""".trimIndent(),
|
||||||
|
commits[0].toString(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `can display tree`() {
|
||||||
|
assertEquals(
|
||||||
|
"""
|
||||||
|
tree 048b8e267dd7a6c5d4849d59f6ff82e6ae948f13
|
||||||
|
+dir1/
|
||||||
|
| tree aaebbb258bce30749fc302cbd161b78462252a32
|
||||||
|
| +test1.txt
|
||||||
|
| | blob c57eff55ebc0c54973903af5f72bac72762cf4f4
|
||||||
|
| | | Hello World!
|
||||||
|
+dir2/
|
||||||
|
| tree 0e14cbdba02924cd63a58c2492fc3dd05dc682bd
|
||||||
|
| +test1.txt
|
||||||
|
| | blob da3fcc31cbc16fcbb7526d68771f77e7e7f02fb1
|
||||||
|
| | | This is a second file
|
||||||
|
""".trimIndent(),
|
||||||
|
commits[1].tree.toString(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user