Skip to content

Commit

Permalink
feat: add parent property with tests
Browse files Browse the repository at this point in the history
chore: bump to Swift 5.9

# Conflicts:
#	Dockerfile
#	Package.swift
#	SWXMLHash.xcodeproj/project.pbxproj
#	SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash OSX.xcscheme
#	SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash iOS.xcscheme
#	SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash tvOS.xcscheme
#	SWXMLHash.xcodeproj/xcshareddata/xcschemes/SWXMLHash watchOS.xcscheme

feat: add initial parent test
  • Loading branch information
drmohundro committed Sep 27, 2024
1 parent 615f044 commit 3cbf1a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM swiftlang/swift:nightly-6.0-focal
FROM swift:6.0

ENV APP_HOME ./app
RUN mkdir $APP_HOME
Expand Down
3 changes: 3 additions & 0 deletions Source/XMLElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class XMLElement: XMLContent {
/// The name of the element
public let name: String

public private(set) var parent: XMLElement?

/// Whether the element is case insensitive or not
public var caseInsensitive: Bool {
options.caseInsensitive
Expand Down Expand Up @@ -116,6 +118,7 @@ public class XMLElement: XMLContent {

func addElement(_ name: String, withAttributes attributes: [String: String], caseInsensitive: Bool) -> XMLElement {
let element = XMLElement(name: name, index: count, options: options)
element.parent = self
count += 1

children.append(element)
Expand Down
7 changes: 7 additions & 0 deletions Tests/SWXMLHashTests/XMLParsingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ struct XMLParsingTests {
#expect(xml!["root"]["catalog"]["book"][1]["author"].element?.text == "Ralls, Kim")
}

@Test
func shouldBeAbleToGetParent() {
#expect(xml!["root"]["catalog"]["book"][1]["author"].element?.parent != nil)
#expect(xml!["root"]["catalog"]["book"][1]["author"].element?.parent?.name == "book")
#expect(xml!["root"]["catalog"]["book"][1]["author"].element?.parent?.attribute(by: "id")?.text == "bk102")
}

@Test
func shouldBeAbleToParseElementGroupsByIndex() {
// swiftlint:disable:next force_try
Expand Down

0 comments on commit 3cbf1a4

Please sign in to comment.