Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed Aug 11, 2021
2 parents a31164d + ce43461 commit 48b23eb
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sources/DocCArchive/Schema_0_1/Fragment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ extension DocCArchive.DocCSchema_0_1 {
// A generic parameter is the `T` in `Array<T>` (string w/o the `<>`)
case genericParameter(String)

/// An attribute, like `@IBInspectable`
case attribute(String)

// Those carry identifier/preciseIdentifier within declarations, but not in
// fragments (e.g. as part of references).
case typeIdentifier (text: String, identifier: Identifier?,
Expand All @@ -44,6 +47,7 @@ extension DocCArchive.DocCSchema_0_1 {
case .externalParam (let s) : return s
case .internalParam (let s) : return s
case .genericParameter (let s) : return s
case .attribute (let s) : return s
case .typeIdentifier (let s, _, _) : return s
}
}
Expand All @@ -56,6 +60,7 @@ extension DocCArchive.DocCSchema_0_1 {
case .externalParam (let s): return "<ExtPara: \(s)>"
case .internalParam (let s): return "<IntPara: \(s)>"
case .genericParameter (let s): return "<GPara: \(s)>"
case .attribute (let s): return "<Attr: \(s)>"

case .typeIdentifier (let text, .some(let id), .some(let tid)):
return "<TypeIdentifier[\(id)]: “\(text)\(tid)>"
Expand Down Expand Up @@ -89,7 +94,8 @@ extension DocCArchive.DocCSchema_0_1 {
case "externalParam" : self = .externalParam (try text())
case "internalParam" : self = .internalParam (try text())
case "genericParameter" : self = .genericParameter(try text())

case "attribute" : self = .attribute (try text())

case "typeIdentifier":
let id = try container.decodeIfPresent(
Identifier.self, forKey: .identifier)
Expand All @@ -109,7 +115,7 @@ extension DocCArchive.DocCSchema_0_1 {
switch self {
case .keyword(let v), .text(let v), .identifier(let v),
.externalParam(let v), .internalParam(let v),
.genericParameter(let v):
.genericParameter(let v), .attribute(let v):
try container.encode(v, forKey: .text)

case .typeIdentifier(let text, let id, let tid):
Expand All @@ -128,6 +134,7 @@ extension DocCArchive.DocCSchema_0_1 {
case .internalParam : return "internalParam"
case .genericParameter : return "genericParameter"
case .typeIdentifier : return "typeIdentifier"
case .attribute : return "attribute"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/DocCArchive/Schema_0_1/MetaData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ extension DocCArchive.DocCSchema_0_1 {
case structure = "Structure"
case framework = "Framework"
case instanceMethod = "Instance Method"
case typeMethod = "Type Method"
case initializer = "Initializer"
case instanceProperty = "Instance Property"
case enumeration = "Enumeration"
Expand Down
36 changes: 36 additions & 0 deletions Tests/DocCArchiveTests/DocumentDecodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,42 @@ final class DocumentDecodingTests: XCTestCase {
( "testAllDataJSONInSlothCreator" , testAllDataJSONInSlothCreator )
]

func testIssue10FailTypeMethodRoleHeading() throws {
let url = Fixtures.baseURL.appendingPathComponent("Issue10Fail.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)
}
catch {
print("ERROR:", error)
XCTAssert(false, "failed to decode: \(error)")
return
}
XCTAssertEqual(document.schemaVersion, .init(major: 0, minor: 1, patch: 0))
}

func testIssue9FailAttributeFragment() throws {
let url = Fixtures.baseURL.appendingPathComponent("Issue9Fail.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)
}
catch {
print("ERROR:", error)
XCTAssert(false, "failed to decode: \(error)")
return
}
XCTAssertEqual(document.schemaVersion, .init(major: 0, minor: 1, patch: 0))
}

func testIssue7Fail() throws {
let url = Fixtures.baseURL.appendingPathComponent("Issue7Fail.json")
let data = try Data(contentsOf: url)
Expand Down
87 changes: 87 additions & 0 deletions Tests/DocCArchiveTests/Fixtures/Issue10Fail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"primaryContentSections": [],
"schemaVersion": {
"major": 0,
"minor": 1,
"patch": 0
},
"metadata": {
"fragments": [
{
"kind": "keyword",
"text": "class"
},
{
"kind": "text",
"text": " "
},
{
"kind": "keyword",
"text": "func"
},
{
"kind": "text",
"text": " "
},
{
"kind": "identifier",
"text": "getValue"
},
{
"kind": "text",
"text": "("
},
{
"kind": "externalParam",
"text": "key"
},
{
"kind": "text",
"text": ": "
},
{
"kind": "typeIdentifier",
"text": "String",
"preciseIdentifier": "s:SS"
},
{
"kind": "text",
"text": "?) -> "
},
{
"kind": "typeIdentifier",
"text": "UIColor",
"preciseIdentifier": "c:objc(cs)UIColor"
},
{
"kind": "text",
"text": "?"
}
],
"title": "getValue(key:)",
"roleHeading": "Type Method",
"role": "symbol",
"symbolKind": "method",
"externalID": "[reducted]",
"modules": [
{
"name": "[reducted]"
}
]
},
"schemaVersion":{"major":0,"minor":1,"patch":0},
"identifier":{
"url":"doc://ARI/documentation/Fail9",
"interfaceLanguage":"swift"
},
"kind":"symbol",
"metadata": {
"title": "And then she kissed her",
"categoryPathComponent": "Songs",
"role": "project",
"category": "Songs"
},
"hierarchy":{ "paths":[] },
"sections":[],
"references":{}
}
33 changes: 33 additions & 0 deletions Tests/DocCArchiveTests/Fixtures/Issue9Fail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"primaryContentSections": [
{
"kind": "declarations",
"declarations": [
{
"tokens": [
{
"kind": "attribute",
"text": "@IBInspectable"
}
],
"languages":["swift"], "platforms":["macOS"]
}
]
}
],
"schemaVersion":{"major":0,"minor":1,"patch":0},
"identifier":{
"url":"doc://ARI/documentation/Fail9",
"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 48b23eb

Please sign in to comment.