Skip to content

Commit

Permalink
Correct list parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinMoskala committed Mar 16, 2023
1 parent dca0c73 commit 157dfb1
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.marcinmoskala"
val libVersion = "0.0.28"
val libVersion = "0.0.31"
version = libVersion

repositories {
Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/note/ListDeletionParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object ListDeletionParser : FullNoteProcessor<ListDeletion> {
override fun render(note: ListDeletion): String = "${if (note.type == ListType.List) "L" else "S"}: {question}\n"
.replace("{question}", note.title)
.plus(note.items.joinToString(separator = "\n") {
if (it.comment.isBlank()) "* ${it.value}" else "* ${it.value} - ${it.comment}"
if (it.comment.isBlank()) "* ${it.value}" else "* ${it.value}: ${it.comment}"
})
.plus(if (note.extra.isNotBlank()) "\nExtra: ${note.extra}" else "")

Expand Down
89 changes: 72 additions & 17 deletions src/commonTest/kotlin/PushingTest.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package ankimarkdown

import ankimarkdown.fakes.FakeAnkiApi
import deckmarkdown.AnkiConnector
import deckmarkdown.Note
import deckmarkdown.api.ApiNote
import deckmarkdown.note.BasicParser
import deckmarkdown.note.DefaultParser
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals

@OptIn(ExperimentalCoroutinesApi::class)
class PushingTest: E2ETest() {
class PushingTest : E2ETest() {

@Test
fun rawText() = testPush(
Expand Down Expand Up @@ -313,6 +310,7 @@ class PushingTest: E2ETest() {
@Test
fun setMultilineCommentsExtra() = testPush(
markdown = """
@98754
S: What are HTTP methods?
* GET: The GET method requests a representation of the specified resource.
Requests using GET should only retrieve data.
Expand Down Expand Up @@ -348,19 +346,72 @@ class PushingTest: E2ETest() {
extra = "Those are not all the methods, there are also..."
)
),
expectedMarkdown = """
@0
S: What are HTTP methods?
* GET - The GET method requests a representation of the specified resource.
Requests using GET should only retrieve data.
* HEAD - The HEAD method asks for a response identical to a GET request,
but without the response body.
* POST - The POST method submits an entity to the specified resource,
often causing a change in state or side effects on the server.
* DELETE
* and others
Extra: Those are not all the methods, there are also...
""".trimIndent()
expectMarkdownHasNotChanged = true
)

@Test
fun listComplex() = testPush(
markdown = """
@1677499984568
L: Interaction Models
* Fire-and-Forget: Fire-and-forget is an optimization of request/response that is useful when a response is not needed. It allows for significant performance optimizations, not just in saved network usage by skipping the response, but also in client and server processing time as no bookkeeping is needed to wait for and associate a response or cancellation request.
```
Future<Void> completionSignalOfSend = socketClient.fireAndForget(message);
```
* Request/Response: Standard request/response semantics are still supported, and still expected to represent the majority of requests over a RSocket connection. These request/response interactions can be considered optimized “streams of only 1 response”, and are asynchronous messages multiplexed over a single connection.
```
Future<Payload> response = socketClient.requestResponse(requestPayload);
```
* Request/Stream: Extending from request/response is request/stream, which allows multiple messages to be streamed back. Think of this as a “collection” or “list” response, but instead of getting back all the data as a single response, each element is streamed back in order.
Use cases could include things like:
fetching a list of videos
fetching products in a catalog
retrieving a file line-by-line
```
Publisher<Payload> response = socketClient.requestStream(requestPayload);
```
* Channel: A channel is bi-directional, with a stream of messages in both directions. An example use case that benefits from this interaction model is: client requests a stream of data that initially bursts the current view of the world deltas/diffs are emitted from server to client as changes occur client updates the subscription over time to add/remove criteria/topics/etc. Without a bi-directional channel, the client would have to cancel the initial request, re-request, and receive all data from scratch, rather than just updating the subscription and efficiently getting just the difference.
```
Publisher<Payload> output = socketClient.requestChannel(Publisher<Payload> input);
```
""".trimIndent(),
expectedApiNotes = listOf(
listApi(
noteId = 1677499984568,
title = "Interaction Models",
items = mapOf(
"Fire-and-Forget" to """
Fire-and-forget is an optimization of request/response that is useful when a response is not needed. It allows for significant performance optimizations, not just in saved network usage by skipping the response, but also in client and server processing time as no bookkeeping is needed to wait for and associate a response or cancellation request.
```
Future<Void> completionSignalOfSend = socketClient.fireAndForget(message);
```
""".trimIndent(),
"Request/Response" to """
Standard request/response semantics are still supported, and still expected to represent the majority of requests over a RSocket connection. These request/response interactions can be considered optimized “streams of only 1 response”, and are asynchronous messages multiplexed over a single connection.
```
Future<Payload> response = socketClient.requestResponse(requestPayload);
```
""".trimIndent(),
"Request/Stream" to """
Extending from request/response is request/stream, which allows multiple messages to be streamed back. Think of this as a “collection” or “list” response, but instead of getting back all the data as a single response, each element is streamed back in order.
Use cases could include things like:
fetching a list of videos
fetching products in a catalog
retrieving a file line-by-line
```
Publisher<Payload> response = socketClient.requestStream(requestPayload);
```
""".trimIndent(),
"Channel" to """
A channel is bi-directional, with a stream of messages in both directions. An example use case that benefits from this interaction model is: client requests a stream of data that initially bursts the current view of the world deltas/diffs are emitted from server to client as changes occur client updates the subscription over time to add/remove criteria/topics/etc. Without a bi-directional channel, the client would have to cancel the initial request, re-request, and receive all data from scratch, rather than just updating the subscription and efficiently getting just the difference.
```
Publisher<Payload> output = socketClient.requestChannel(Publisher<Payload> input);
```
""".trimIndent(),
),
)
),
expectMarkdownHasNotChanged = true,
)

@Test
Expand Down Expand Up @@ -507,6 +558,7 @@ class PushingTest: E2ETest() {
expectedNotes: List<Note>? = null,
expectedApiNotes: List<ApiNote>? = null,
expectedMarkdown: String? = null,
expectMarkdownHasNotChanged: Boolean = false,
) = runTest {
if (expectedNotes != null) {
assertEquals(expectedNotes, DefaultParser.parseNotes(markdown))
Expand All @@ -519,6 +571,9 @@ class PushingTest: E2ETest() {
if (expectedMarkdown != null) {
assertEquals(expectedMarkdown, res.markdown)
}
if (expectMarkdownHasNotChanged) {
assertEquals(markdown, res.markdown)
}
fakeApi.clean()
}
}
2 changes: 1 addition & 1 deletion src/jvmTest/kotlin/WriteTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ a: DDD
@1
L: AAA
* A
* B - Comment
* B: Comment
* C
""".trimIndent()
assertEquals(expected, text)
Expand Down

0 comments on commit 157dfb1

Please sign in to comment.