From b0c827a46edea131cf86778a63a7d795537dcf59 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Tue, 19 Feb 2019 14:46:25 -0500 Subject: [PATCH] Fix summary and legend tags (#42) * Fix summary and legend tags * Require as first element * Fix * More tests --- Sources/Html/Elements.swift | 51 +++++++++++++++++-- .../HtmlSnapshotTestingTests.swift | 22 ++++++-- .../XCTestManifests.swift | 14 ++--- .../testSnapshots.1.html | 28 ++++++++++ Tests/HtmlTests/XCTestManifests.swift | 36 ++++++------- 5 files changed, 117 insertions(+), 34 deletions(-) diff --git a/Sources/Html/Elements.swift b/Sources/Html/Elements.swift index 0989f96..2d84368 100644 --- a/Sources/Html/Elements.swift +++ b/Sources/Html/Elements.swift @@ -157,14 +157,34 @@ extension Node { return .element("del", attributes: attributes, .fragment(content)) } - // TODO: required first child element "summary" /// The `
` element represents a disclosure widget from which the user can obtain additional information or controls. /// /// - Parameters: /// - attributes: Attributes. + /// - summary: A summary. /// - content: Child nodes. - public static func details(attributes: [Attribute] = [], _ content: Node...) -> Node { - return .element("details", attributes: attributes, .fragment(content)) + public static func details( + attributes: [Attribute] = [], + _ summary: ChildOf, + _ content: Node... + ) + -> Node { + + return details(attributes: attributes, summary.rawValue, .fragment(content)) + } + + /// The `
` element represents a disclosure widget from which the user can obtain additional information or controls. + /// + /// - Parameters: + /// - attributes: Attributes. + /// - content: Child nodes. + public static func details( + attributes: [Attribute] = [], + _ content: Node... + ) + -> Node { + + return .element("details", attributes: attributes, .fragment(content)) } /// The `` element represents the defining instance of a term. The term-description group, `

`, `

  • ` or `
    ` element that is the nearest ancestor of the `` element must also contain the definition(s) for the term given by the `` element. @@ -214,9 +234,30 @@ extension Node { /// /// - Parameters: /// - attributes: Attributes. + /// - legend: A legend. /// - content: Child nodes. - public static func fieldset(attributes: [Attribute] = [], _ content: Node...) -> Node { - return .element("fieldset", attributes: attributes, .fragment(content)) + public static func fieldset( + attributes: [Attribute] = [], + _ legend: ChildOf, + _ content: Node... + ) + -> Node { + + return .fieldset(attributes: attributes, legend.rawValue, .fragment(content)) + } + + /// The `
    ` element represents a set of form controls optionally grouped under a common name. + /// + /// - Parameters: + /// - attributes: Attributes. + /// - content: Child nodes. + public static func fieldset( + attributes: [Attribute] = [], + _ content: Node... + ) + -> Node { + + return .element("fieldset", attributes: attributes, .fragment(content)) } /// The `
    ` element represents some flow content, optionally with a caption, that is self-contained (like a complete sentence) and is typically referenced as a single unit from the main flow of the document. diff --git a/Tests/HtmlSnapshotTestingTests/HtmlSnapshotTestingTests.swift b/Tests/HtmlSnapshotTestingTests/HtmlSnapshotTestingTests.swift index 15aad00..d084025 100644 --- a/Tests/HtmlSnapshotTestingTests/HtmlSnapshotTestingTests.swift +++ b/Tests/HtmlSnapshotTestingTests/HtmlSnapshotTestingTests.swift @@ -444,9 +444,16 @@ final class SnapshotTestingTests: SnapshotTestCase { .cite(), .code(), .del(), + .details(), .details( -// TODO: `summary` returns ChildOf
    but `details` only wants Node. is that correct? -// .summary(), + .summary() + ), + .details( + .summary(), + .div() + ), + .details( + .div() ), .dfn(), .div(), @@ -456,9 +463,16 @@ final class SnapshotTestingTests: SnapshotTestCase { ), .em(), .embed(), + .fieldset(), + .fieldset( + .legend() + ), + .fieldset( + .legend(), + .div() + ), .fieldset( -// TODO: `legend` returns ChildOf
    but `fieldset` only wants Node. is that correct? -// .legend(), + .div() ), .figure( .figcaption() diff --git a/Tests/HtmlSnapshotTestingTests/XCTestManifests.swift b/Tests/HtmlSnapshotTestingTests/XCTestManifests.swift index 3642462..901cc6a 100644 --- a/Tests/HtmlSnapshotTestingTests/XCTestManifests.swift +++ b/Tests/HtmlSnapshotTestingTests/XCTestManifests.swift @@ -1,16 +1,16 @@ import XCTest extension SnapshotTestingTests { - static let __allTests = [ - ("testComplexHtml", testComplexHtml), - ("testSnapshots", testSnapshots), + static let __allTests = [ + ("testComplexHtml", testComplexHtml), + ("testSnapshots", testSnapshots), ] } -#if !os(macOS) +#if os(Linux) public func __allTests() -> [XCTestCaseEntry] { - return [ - testCase(SnapshotTestingTests.__allTests), - ] + return [ + testCase(SnapshotTestingTests.__allTests), + ] } #endif diff --git a/Tests/HtmlSnapshotTestingTests/__Snapshots__/HtmlSnapshotTestingTests/testSnapshots.1.html b/Tests/HtmlSnapshotTestingTests/__Snapshots__/HtmlSnapshotTestingTests/testSnapshots.1.html index 1b0d5a4..25b7c9b 100644 --- a/Tests/HtmlSnapshotTestingTests/__Snapshots__/HtmlSnapshotTestingTests/testSnapshots.1.html +++ b/Tests/HtmlSnapshotTestingTests/__Snapshots__/HtmlSnapshotTestingTests/testSnapshots.1.html @@ -37,6 +37,20 @@
    +
    + + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    @@ -52,6 +66,20 @@
    +
    + + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    diff --git a/Tests/HtmlTests/XCTestManifests.swift b/Tests/HtmlTests/XCTestManifests.swift index 2184a61..4a28075 100644 --- a/Tests/HtmlTests/XCTestManifests.swift +++ b/Tests/HtmlTests/XCTestManifests.swift @@ -1,43 +1,43 @@ import XCTest extension AriaTests { - static let __allTests = [ - ("testAriaAttributes", testAriaAttributes), + static let __allTests = [ + ("testAriaAttributes", testAriaAttributes), ] } extension AttributesTests { - static let __allTests = [ - ("testAttributes", testAttributes), + static let __allTests = [ + ("testAttributes", testAttributes), ] } extension ElementsTests { - static let __allTests = [ - ("testBase64Snapshot", testBase64Snapshot), + static let __allTests = [ + ("testBase64Snapshot", testBase64Snapshot), ] } extension EventsTests { - static let __allTests = [ - ("testEventsSnapshot", testEventsSnapshot), + static let __allTests = [ + ("testEventsSnapshot", testEventsSnapshot), ] } extension MediaTypeTests { - static let __allTests = [ - ("testMediaType", testMediaType), + static let __allTests = [ + ("testMediaType", testMediaType), ] } -#if !os(macOS) +#if os(Linux) public func __allTests() -> [XCTestCaseEntry] { - return [ - testCase(AriaTests.__allTests), - testCase(AttributesTests.__allTests), - testCase(ElementsTests.__allTests), - testCase(EventsTests.__allTests), - testCase(MediaTypeTests.__allTests), - ] + return [ + testCase(AriaTests.__allTests), + testCase(AttributesTests.__allTests), + testCase(ElementsTests.__allTests), + testCase(EventsTests.__allTests), + testCase(MediaTypeTests.__allTests), + ] } #endif