Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed Oct 2, 2021
2 parents 9b78fd5 + c39b426 commit eae73fe
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Sources/DocCArchive/Schema_0_1/Content/CodeListing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
extension DocCArchive.DocCSchema_0_1.Content {

public struct CodeListing: Equatable, CustomStringConvertible, Codable {
public var syntax : String
public var syntax : String?
public var code : [ String ]

public var description: String {
return syntax.isEmpty ? "<Code #\(code.count)>"
: "<Code[\(syntax)]: #\(code.count)>"
guard let syntax = syntax, !syntax.isEmpty else {
return "<Code #\(code.count)>"
}
return "<Code[\(syntax)]: #\(code.count)>"
}
}
}
4 changes: 4 additions & 0 deletions Sources/DocCArchive/Schema_0_1/Content/Content.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ extension DocCArchive.DocCSchema_0_1 {

public enum Style: String, Codable {
case note
case warning
case important
case tip
case experiment
}

public struct Item: Equatable, Codable {
Expand Down
8 changes: 8 additions & 0 deletions Sources/DocCArchive/Schema_0_1/InlineContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extension DocCArchive.DocCSchema_0_1 {
overridingTitleInlineContent : [ InlineContent ]?)
case image (identifier: String)
case emphasis ([ InlineContent ])
case strong ([ InlineContent ])
case codeVoice(code: String)

public var description: String {
Expand All @@ -27,6 +28,7 @@ extension DocCArchive.DocCSchema_0_1 {
return "\(id)\(isActive ? "" : "-inactive")"
case .image (let id) : return "<img \(id)>"
case .emphasis (let content) : return "*\(content)*"
case .strong (let content) : return "**\(content)**"
case .codeVoice(let code) : return "`\(code)`"
}
}
Expand Down Expand Up @@ -54,6 +56,9 @@ extension DocCArchive.DocCSchema_0_1 {
case "emphasis":
self = .emphasis(try container.decode([ InlineContent ].self,
forKey: .inlineContent))
case "strong":
self = .strong(try container.decode([ InlineContent ].self,
forKey: .inlineContent))
case "reference":
self = .reference(
identifier:
Expand Down Expand Up @@ -90,6 +95,9 @@ extension DocCArchive.DocCSchema_0_1 {
case .emphasis(let content):
try container.encode("emphasis" , forKey: .type)
try container.encode(content , forKey: .inlineContent)
case .strong(let content):
try container.encode("strong" , forKey: .type)
try container.encode(content , forKey: .inlineContent)
case .reference(let identifier, let isActive, let ot, let otc):
try container.encode("reference" , forKey: .type)
try container.encode(identifier , forKey: .identifier)
Expand Down
35 changes: 33 additions & 2 deletions Tests/DocCArchiveTests/DocumentDecodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,40 @@ final class DocumentDecodingTests: XCTestCase {
( "testIssue10FailTypeMethodRoleHeading",
testIssue10FailTypeMethodRoleHeading ),
( "testIssue11FailUnorderedList" , testIssue11FailUnorderedList ),
( "testAllDataJSONInSlothCreator" , testAllDataJSONInSlothCreator )
( "testAllDataJSONInSlothCreator" , testAllDataJSONInSlothCreator ),
( "testIssue12FailAsideWarningStyle", testIssue12FailAsideWarningStyle )
]


func testIssue12FailAsideWarningStyle() throws {
let url = Fixtures.baseURL.appendingPathComponent("Issue12Fail.json")
let data = try Data(contentsOf: url)

let document : DocCArchive.Document

print("Decoding:", url.path)
do {
document = try JSONDecoder().decode(DocCArchive.Document.self, from: data)

guard let section = document.primaryContentSections?.first else {
XCTAssert(false, "did not find primary content section"); return
}
guard case .content(let contents) = section.kind else {
XCTAssert(false, "did not find content section"); return
}
guard case .aside(style: let style, content: let asideContents) = contents.dropFirst().first else {
XCTAssert(false, "did not find aside"); return
}
XCTAssertEqual(style, .warning, "expected to find warning")
XCTAssert(asideContents.count == 1)
}
catch {
print("ERROR:", error)
XCTAssert(false, "failed to decode: \(error)")
return
}
XCTAssertEqual(document.schemaVersion, .init(major: 0, minor: 1, patch: 0))
}

func testIssue11FailUnorderedList() throws {
let url = Fixtures.baseURL.appendingPathComponent("Issue11Fail.json")
let data = try Data(contentsOf: url)
Expand Down
61 changes: 61 additions & 0 deletions Tests/DocCArchiveTests/Fixtures/Issue12Fail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"primaryContentSections": [
{
"kind": "content",
"content": [
{
"anchor": "discussion",
"level": 2,
"type": "heading",
"text": "Discussion"
},
{
"type": "aside",
"style": "warning",
"content": [
{
"type": "paragraph",
"inlineContent": [
{
"type": "text",
"text": "Values above "
},
{
"type": "codeVoice",
"code": "99"
},
{
"type": "text",
"text": " will be shown as "
},
{
"type": "codeVoice",
"code": "99+"
},
{
"type": "text",
"text": "."
}
]
}
]
}
]
}
],
"schemaVersion":{"major":0,"minor":1,"patch":0},
"identifier":{
"url":"doc://ARI/documentation/Fail12",
"interfaceLanguage":"swift"
},
"kind":"symbol",
"metadata": {
"title": "And then she kissed her",
"categoryPathComponent": "Songs",
"role": "project",
"category": "Songs"
},
"hierarchy":{ "paths":[] },
"sections":[],
"references":{}
}

0 comments on commit eae73fe

Please sign in to comment.