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

Fix the Incorrectly generated attributes for toJsonString of Tree #131

Merged
merged 1 commit into from
Dec 19, 2023
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
4 changes: 4 additions & 0 deletions Sources/Document/Json/JSONTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public struct JSONTreeElementNode: JSONTreeNode {
let attrsString = sortedKeys.compactMap { key in
if let attrs = attributes[key] as? Encodable, let value = attrs.toJSONString {
return "\(key.toJSONString):\(value)"
} else if let value = attributes[key] as? Any, JSONSerialization.isValidJSONObject(value),
let data = try? JSONSerialization.data(withJSONObject: value, options: [.sortedKeys, .withoutEscapingSlashes])
{
return "\(key.toJSONString):\(String(data: data, encoding: .utf8) ?? "null")"
} else if let value = attributes[key] as? Int {
return "\(key.toJSONString):\(value)"
} else if let value = attributes[key] as? Double {
Expand Down
11 changes: 11 additions & 0 deletions Tests/Unit/Document/JONSTreeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ final class JONSTreeTests: XCTestCase {

XCTAssertEqual(textNode.toJSONString, "{\"type\":\"text\",\"value\":\"\\n\"}")
}

func test_json_jsonSerialiaztion() throws {
let attr = RHT()

attr.set(key: "list", value: "{\"@ctype\":\"paragraphListStyle\",\"level\":0,\"type\":\"bullet\"}", executedAt: TimeTicket.initial)

let crdtTreeNode = CRDTTreeNode(id: .initial, type: "listNode", children: nil, attributes: attr)
let jsonTreeNode = crdtTreeNode.toJSONTreeNode

XCTAssertEqual(crdtTreeNode.toJSONString, jsonTreeNode.toJSONString)
}
}
23 changes: 3 additions & 20 deletions docker/docker-compose-ci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
version: '3.3'

services:
envoy:
build:
context: ./
dockerfile: ./envoy.Dockerfile
image: 'grpcweb:envoy'
container_name: 'envoy'
restart: always
ports:
- '8080:8080'
- '9901:9901'
command: ['/etc/envoy/envoy-ci.yaml']
depends_on:
- yorkie
yorkie:
image: 'yorkieteam/yorkie:latest'
container_name: 'yorkie'
command: [
'server',
'--mongo-connection-uri',
'mongodb://mongo:27017',
]
command: ['server', '--mongo-connection-uri', 'mongodb://mongo:27017']
restart: always
ports:
- '11101:11101'
- '11102:11102'
- '8080:8080'
- '8081:8081'
depends_on:
- mongo
mongo:
Expand Down
29 changes: 3 additions & 26 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
version: '3.3'

services:
envoy:
build:
context: ./
dockerfile: ./envoy.Dockerfile
image: 'grpcweb:envoy'
container_name: 'envoy'
restart: always
ports:
- '8080:8080'
- '9901:9901'
command: ['/etc/envoy/envoy.yaml']
depends_on:
- yorkie
# If you're using Mac or Windows, this special domain name("host.docker.internal" which makes containers able to connect to the host)
# is supported by default.
# But if you're using Linux and want an envoy container to communicate with the host,
# it may help to define "host.docker.internal" in extra_hosts.
# (Actually, other hostnames are available, but in that case you should update clusters[].host configurations of envoy.yaml)
extra_hosts:
- "host.docker.internal:host-gateway"
yorkie:
image: 'yorkieteam/yorkie:latest'
container_name: 'yorkie'
command: [
'server',
'--enable-pprof',
]
command: ['server', '--enable-pprof']
restart: always
ports:
- '11101:11101'
- '11102:11102'
- '8080:8080'
- '8081:8081'