1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/*
This source file is part of the Swift.org open source project
Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
import XCTest
@testable import SwiftDocC
import Markdown
class VolumeTests: XCTestCase {
func testEmpty() throws {
let source = """
@Volume
"""
let document = Document(parsing: source, options: .parseBlockDirectives)
let directive = document.child(at: 0)! as! BlockDirective
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
var problems = [Problem]()
let volume = Volume(from: directive, source: nil, for: bundle, in: context, problems: &problems)
XCTAssertNil(volume)
XCTAssertEqual(4, problems.count)
XCTAssertEqual([
"org.swift.docc.HasArgument.name",
"org.swift.docc.HasExactlyOne<\(Volume.self), \(ImageMedia.self)>.Missing",
"org.swift.docc.HasAtLeastOne<\(Volume.self), \(Chapter.self)>",
"org.swift.docc.Volume.HasContent",
], problems.map { $0.diagnostic.identifier })
}
func testValid() throws {
let name = "Always Be Voluming"
let expectedContent = "Here is some content explaining what this volume is."
let source = """
@Volume(name: "\(name)") {
\(expectedContent)
@Image(source: "figure1.png", alt: "whatever")
@Chapter(name: "Chapter 1") {
This is Chapter 1.
@Image(source: test.png, alt: test)
@TutorialReference(tutorial: Tutorial1)
}
}
"""
let document = Document(parsing: source, options: .parseBlockDirectives)
let directive = document.child(at: 0)! as! BlockDirective
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
var problems = [Problem]()
let volume = Volume(from: directive, source: nil, for: bundle, in: context, problems: &problems)
XCTAssertNotNil(volume)
XCTAssertTrue(problems.isEmpty)
volume.map { volume in
XCTAssertEqual(name, volume.name)
XCTAssertEqual(expectedContent, volume.content?.mapFirst { $0.detachedFromParent.format() })
}
}
func testChapterWithSameName() throws {
let name = "Always Be Voluming"
let (_, bundle, context) = try testBundleAndContext(copying: "TestBundle") { root in
let overviewURL = root.appendingPathComponent("TestOverview.tutorial")
let text = """
@Tutorials(name: "Technology X") {
@Intro(title: "Technology X") {
You'll learn all about Technology X.
@Video(source: introvideo.mp4, poster: introposter.png)
@Image(source: intro.png, alt: intro)
}
@Volume(name: "\(name)") {
This is a `Volume`.
@Image(source: figure1.png, alt: "Figure 1")
@Chapter(name: "\(name)") {
This is a `Chapter`.
@Image(source: figure1.png, alt: "Figure 1")
@TutorialReference(tutorial: "doc:TestTutorial")
}
}
@Resources {}
}
"""
try text.write(to: overviewURL, atomically: true, encoding: .utf8)
}
let node = try context.entity(
with: ResolvedTopicReference(
bundleIdentifier: bundle.identifier,
path: "/tutorials/TestOverview",
sourceLanguage: .swift))
let tutorial = try XCTUnwrap(node.semantic as? Technology)
let volume = tutorial.volumes.first
XCTAssertNotNil(volume)
XCTAssertEqual(volume?.name, volume?.chapters.first?.name)
}
}
|