From f9e38b1e647e9b2c75c84ee3f6ff86bfbed14360 Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 18:14:19 -0400 Subject: [PATCH 01/12] Implement AccordionRegistration.encode(to:) --- .../Complex Types/AccordionRegistration.swift | 27 ++++++++++--------- .../AccordionRegistrationTests.swift | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Sources/MusicXML/Complex Types/AccordionRegistration.swift b/Sources/MusicXML/Complex Types/AccordionRegistration.swift index dbdd938..5af811d 100644 --- a/Sources/MusicXML/Complex Types/AccordionRegistration.swift +++ b/Sources/MusicXML/Complex Types/AccordionRegistration.swift @@ -27,15 +27,15 @@ public struct AccordionRegistration { // MARK: - Initializers public init( - printStyleAlign: PrintStyleAlign = PrintStyleAlign(), - accordionHigh: Bool = false, - accordionMiddle: AccordionMiddle? = nil, - accordionLow: Bool = false + high: Bool = false, + middle: AccordionMiddle? = nil, + low: Bool = false, + printStyleAlign: PrintStyleAlign = PrintStyleAlign() ) { + self.high = high + self.middle = middle + self.low = low self.printStyleAlign = printStyleAlign - self.high = accordionHigh - self.middle = accordionMiddle - self.low = accordionLow } } @@ -46,11 +46,6 @@ extension AccordionRegistration: Codable { case middle = "accordion-middle" case low = "accordion-low" } - - public func encode(to encoder: Encoder) throws { - fatalError() - } - public init(from decoder: Decoder) throws { self.printStyleAlign = try PrintStyleAlign(from: decoder) let container = try decoder.container(keyedBy: CodingKeys.self) @@ -58,4 +53,12 @@ extension AccordionRegistration: Codable { self.low = container.contains(.low) self.middle = try container.decodeIfPresent(AccordionMiddle.self, forKey: .middle) } + public func encode(to encoder: Encoder) throws { + var singleValueContainer = encoder.singleValueContainer() + try singleValueContainer.encode(printStyleAlign) + var container = encoder.container(keyedBy: CodingKeys.self) + if high { try container.encode(Empty(), forKey: .high) } + if low { try container.encode(Empty(), forKey: .low) } + try container.encodeIfPresent(middle, forKey: .middle) + } } diff --git a/Tests/MusicXMLTests/Complex Types/AccordionRegistrationTests.swift b/Tests/MusicXMLTests/Complex Types/AccordionRegistrationTests.swift index 6567830..d26f7d5 100644 --- a/Tests/MusicXMLTests/Complex Types/AccordionRegistrationTests.swift +++ b/Tests/MusicXMLTests/Complex Types/AccordionRegistrationTests.swift @@ -18,7 +18,7 @@ class AccordionRegistrationTests: XCTestCase { """ let decoded = try XMLDecoder().decode(AccordionRegistration.self, from: xml.data(using: .utf8)!) - let expected = AccordionRegistration(accordionHigh: true, accordionMiddle: 2) + let expected = AccordionRegistration(high: true, middle: 2) XCTAssertEqual(decoded, expected) } } From 92c4b54618376b59e96cd60415c8a0fb1355ac7b Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 18:17:07 -0400 Subject: [PATCH 02/12] Implement Ending.encode(to:) --- Sources/MusicXML/Complex Types/Ending.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/MusicXML/Complex Types/Ending.swift b/Sources/MusicXML/Complex Types/Ending.swift index 5df14dc..2cf4fd7 100644 --- a/Sources/MusicXML/Complex Types/Ending.swift +++ b/Sources/MusicXML/Complex Types/Ending.swift @@ -89,6 +89,15 @@ extension Ending: Codable { } public func encode(to encoder: Encoder) throws { - fatalError("TODO: Ending.encode(to:)") + var singleValueContainer = encoder.singleValueContainer() + try singleValueContainer.encode(printStyle) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(value, forKey: .value) + try container.encode(number, forKey: .number) + try container.encode(type, forKey: .type) + try container.encodeIfPresent(printObject, forKey: .printObject) + try container.encodeIfPresent(endLength, forKey: .endLength) + try container.encodeIfPresent(textX, forKey: .textX) + try container.encodeIfPresent(textY, forKey: .textY) } } From 8410036fe669ad668ce571738b46192a20bd18f0 Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 18:19:28 -0400 Subject: [PATCH 03/12] Implement Fret.encode(to:) --- Sources/MusicXML/Complex Types/Fret.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/MusicXML/Complex Types/Fret.swift b/Sources/MusicXML/Complex Types/Fret.swift index 64a175e..f641e26 100644 --- a/Sources/MusicXML/Complex Types/Fret.swift +++ b/Sources/MusicXML/Complex Types/Fret.swift @@ -38,12 +38,10 @@ public struct Fret { extension Fret: Equatable { } extension Fret: Codable { - private enum CodingKeys: String, CodingKey { case value = "" case color } - public init(from decoder: Decoder) throws { // Decode attribute groups self.font = try Font(from: decoder) @@ -57,9 +55,12 @@ extension Fret: Codable { self.value = 0 } } - public func encode(to encoder: Encoder) throws { - fatalError("TODO: Fret.encode(to:)") + var singleValueContainer = encoder.singleValueContainer() + try singleValueContainer.encode(font) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(value, forKey: .value) + try container.encodeIfPresent(color, forKey: .color) } } From 2a2f97a17074f8a3d823148d8eb9a153c8a93514 Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 18:26:50 -0400 Subject: [PATCH 04/12] Implement Harmonic.encode(to:) --- Sources/MusicXML/Complex Types/Harmonic.swift | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/Sources/MusicXML/Complex Types/Harmonic.swift b/Sources/MusicXML/Complex Types/Harmonic.swift index 6903427..f375f82 100644 --- a/Sources/MusicXML/Complex Types/Harmonic.swift +++ b/Sources/MusicXML/Complex Types/Harmonic.swift @@ -21,10 +21,20 @@ public struct Harmonic { // MARK: - Attributes public var printObject: Bool? - public var printStyle: PrintStyle? + public var placement: AboveBelow? + + // MARK: - Attribute Groups + + public var printStyle: PrintStyle - public init(naturalArtificial: NaturalArtificial? = nil, baseSoundingTouchingPitch: BaseSoundingTouchingPitch? = nil, printObject: Bool? = nil, printStyle: PrintStyle? = nil, placement: AboveBelow? = nil) { + public init( + naturalArtificial: NaturalArtificial? = nil, + baseSoundingTouchingPitch: BaseSoundingTouchingPitch? = nil, + printObject: Bool? = nil, + placement: AboveBelow? = nil, + printStyle: PrintStyle = PrintStyle() + ) { self.naturalArtificial = naturalArtificial self.baseSoundingTouchingPitch = baseSoundingTouchingPitch self.printObject = printObject @@ -74,6 +84,7 @@ extension Harmonic: Codable { } public init(from decoder: Decoder) throws { + self.printStyle = try PrintStyle(from: decoder) let container = try decoder.container(keyedBy: CodingKeys.self) if container.contains(.natural) { self.naturalArtificial = .natural @@ -92,12 +103,33 @@ extension Harmonic: Codable { } self.printObject = try container.decodeIfPresent(Bool.self, forKey: .printObject) - self.printStyle = try container.decodeIfPresent(PrintStyle.self, forKey: .printStyle) self.placement = try container.decodeIfPresent(AboveBelow.self, forKey: .placement) } public func encode(to encoder: Encoder) throws { - fatalError() + var singleValueContainer = encoder.singleValueContainer() + try singleValueContainer.encode(printStyle) + var container = encoder.container(keyedBy: CodingKeys.self) + if let baseSoundingTouchingPitch = self.baseSoundingTouchingPitch { + switch baseSoundingTouchingPitch { + case .base: + try container.encode(Empty(), forKey: .base) + case .sounding: + try container.encode(Empty(), forKey: .sounding) + case .touching: + try container.encode(Empty(), forKey: .touching) + } + } + if let naturalArtificial = self.naturalArtificial { + switch naturalArtificial { + case .natural: + try container.encode(Empty(), forKey: .natural) + case .artificial: + try container.encode(Empty(), forKey: .artificial) + } + } + try container.encodeIfPresent(printObject, forKey: .printObject) + try container.encodeIfPresent(placement, forKey: .placement) } } From 3d00e154d52e7db47e61596956f7f8472d917735 Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 18:28:07 -0400 Subject: [PATCH 05/12] Implement LyricsFont.encode(to:) --- Sources/MusicXML/Complex Types/LyricFont.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/MusicXML/Complex Types/LyricFont.swift b/Sources/MusicXML/Complex Types/LyricFont.swift index 21194e2..db2cfde 100644 --- a/Sources/MusicXML/Complex Types/LyricFont.swift +++ b/Sources/MusicXML/Complex Types/LyricFont.swift @@ -32,6 +32,10 @@ extension LyricFont: Codable { self.name = try container.decodeIfPresent(String.self, forKey: .name) } public func encode(to encoder: Encoder) throws { - fatalError("TODO: LyricFont.encode(to:)") + var singleValueContainer = encoder.singleValueContainer() + try singleValueContainer.encode(font) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(number, forKey: .number) + try container.encodeIfPresent(name, forKey: .name) } } From fb9c3fc532b357fb2490bf597931d7dcddabd740 Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 18:29:38 -0400 Subject: [PATCH 06/12] Implement MeasureNumbering.encode(to:) --- Sources/MusicXML/Complex Types/MeasureNumbering.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/MusicXML/Complex Types/MeasureNumbering.swift b/Sources/MusicXML/Complex Types/MeasureNumbering.swift index 592eaa0..48c95c9 100644 --- a/Sources/MusicXML/Complex Types/MeasureNumbering.swift +++ b/Sources/MusicXML/Complex Types/MeasureNumbering.swift @@ -32,6 +32,9 @@ extension MeasureNumbering: Codable { self.value = try container.decode(MeasureNumberingValue.self, forKey: .value) } public func encode(to encoder: Encoder) throws { - fatalError() + var singleValueContainer = encoder.singleValueContainer() + try singleValueContainer.encode(printStyleAlign) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(value, forKey: .value) } } From f78e19513976db5095108c90b5cd604087b25226 Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 18:31:39 -0400 Subject: [PATCH 07/12] Add AccordionRegistration round trip test --- .../Complex Types/AccordionRegistrationTests.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/MusicXMLTests/Complex Types/AccordionRegistrationTests.swift b/Tests/MusicXMLTests/Complex Types/AccordionRegistrationTests.swift index d26f7d5..4720897 100644 --- a/Tests/MusicXMLTests/Complex Types/AccordionRegistrationTests.swift +++ b/Tests/MusicXMLTests/Complex Types/AccordionRegistrationTests.swift @@ -21,4 +21,8 @@ class AccordionRegistrationTests: XCTestCase { let expected = AccordionRegistration(high: true, middle: 2) XCTAssertEqual(decoded, expected) } + + func testRoundTrip() throws { + try testRoundTrip(AccordionRegistration(high: true, middle: 2)) + } } From 0e23cc5c7c7c6f9015d7b5067e14bd2e306675cd Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 18:55:07 -0400 Subject: [PATCH 08/12] Add Ending round trip test --- Sources/MusicXML/Complex Types/Ending.swift | 20 +++++++++++++---- .../MusicXML/Complex Types/PrintStyle.swift | 15 ++++++++++++- .../MusicXML/Complex Types/Technical.swift | 4 ++++ .../Complex Types/EndingTests.swift | 22 +++++++++++++++++++ .../Complex Types/NotationsTests.swift | 2 +- 5 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 Tests/MusicXMLTests/Complex Types/EndingTests.swift diff --git a/Sources/MusicXML/Complex Types/Ending.swift b/Sources/MusicXML/Complex Types/Ending.swift index 2cf4fd7..cd335ab 100644 --- a/Sources/MusicXML/Complex Types/Ending.swift +++ b/Sources/MusicXML/Complex Types/Ending.swift @@ -36,7 +36,7 @@ public struct Ending { // MARK: Attribute Groups - public let printStyle: PrintStyle? + public let printStyle: PrintStyle // MARK: - Initializers @@ -89,10 +89,9 @@ extension Ending: Codable { } public func encode(to encoder: Encoder) throws { - var singleValueContainer = encoder.singleValueContainer() - try singleValueContainer.encode(printStyle) + try printStyle.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(value, forKey: .value) + try container.encode(value, forKey: .value) try container.encode(number, forKey: .number) try container.encode(type, forKey: .type) try container.encodeIfPresent(printObject, forKey: .printObject) @@ -101,3 +100,16 @@ extension Ending: Codable { try container.encodeIfPresent(textY, forKey: .textY) } } + +import XMLCoder + +extension Ending: DynamicNodeEncoding { + public static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding { + switch key { + case CodingKeys.value: + return .element + default: + return .attribute + } + } +} diff --git a/Sources/MusicXML/Complex Types/PrintStyle.swift b/Sources/MusicXML/Complex Types/PrintStyle.swift index 6c851a5..5f99f93 100644 --- a/Sources/MusicXML/Complex Types/PrintStyle.swift +++ b/Sources/MusicXML/Complex Types/PrintStyle.swift @@ -24,11 +24,24 @@ extension PrintStyle: Codable { private enum CodingKeys: String, CodingKey { case color } - public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.position = try Position(from: decoder) self.font = try Font(from: decoder) self.color = try container.decodeIfPresent(Color.self, forKey: .color) } + public func encode(to encoder: Encoder) throws { + try position.encode(to: encoder) + try font.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(color, forKey: .color) + } +} + +import XMLCoder + +extension PrintStyle: DynamicNodeEncoding { + public static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding { + return .attribute + } } diff --git a/Sources/MusicXML/Complex Types/Technical.swift b/Sources/MusicXML/Complex Types/Technical.swift index 51683e0..66767fd 100644 --- a/Sources/MusicXML/Complex Types/Technical.swift +++ b/Sources/MusicXML/Complex Types/Technical.swift @@ -21,4 +21,8 @@ extension Technical: Codable { let container = try decoder.singleValueContainer() values = try container.decode([Technique].self) } + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(values) + } } diff --git a/Tests/MusicXMLTests/Complex Types/EndingTests.swift b/Tests/MusicXMLTests/Complex Types/EndingTests.swift new file mode 100644 index 0000000..6832116 --- /dev/null +++ b/Tests/MusicXMLTests/Complex Types/EndingTests.swift @@ -0,0 +1,22 @@ +// +// EndingTests.swift +// MusicXMLTests +// +// Created by James Bean on 10/24/19. +// + +import XCTest +import MusicXML + +class EndingTests: XCTestCase { + + func testRoundTrip() throws { + let ending = Ending("1.", + number: "1", + type: .start, + printObject: false, + printStyle: PrintStyle(position: Position(defaultX: 42)) + ) + try testRoundTrip(ending) + } +} diff --git a/Tests/MusicXMLTests/Complex Types/NotationsTests.swift b/Tests/MusicXMLTests/Complex Types/NotationsTests.swift index 11821f0..a9aae5d 100644 --- a/Tests/MusicXMLTests/Complex Types/NotationsTests.swift +++ b/Tests/MusicXMLTests/Complex Types/NotationsTests.swift @@ -287,7 +287,7 @@ class NotationsTests: XCTestCase { } func testFingeringValueRoundTrip() throws { - try testRoundTrip(Technical([.fingering(Fingering("1"))])) + try testRoundTrip(Technical([.fingering(Fingering("1"))]), loggingEncoded: true) } func testFingeringEmptyRoundTrip() throws { From 2f2a6654e927a7915df5fcc755c7053dd1b8e570 Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 19:18:23 -0400 Subject: [PATCH 09/12] Add fret round trip test --- Sources/MusicXML/Complex Types/Font.swift | 7 +++++ Sources/MusicXML/Complex Types/Fret.swift | 22 ++++++++++++---- Sources/MusicXML/Simple Types/Color.swift | 7 +++++ .../Complex Types/FretTests.swift | 20 ++++++++++++++ .../Complex Types/HarmonicTests.swift | 26 +++++++++++++++++++ 5 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 Tests/MusicXMLTests/Complex Types/FretTests.swift create mode 100644 Tests/MusicXMLTests/Complex Types/HarmonicTests.swift diff --git a/Sources/MusicXML/Complex Types/Font.swift b/Sources/MusicXML/Complex Types/Font.swift index a0d5f3c..ebc0e45 100644 --- a/Sources/MusicXML/Complex Types/Font.swift +++ b/Sources/MusicXML/Complex Types/Font.swift @@ -49,4 +49,11 @@ extension Font: Codable { case size = "font-size" case weight = "font-weight" } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(family, forKey: .family) + try container.encodeIfPresent(style, forKey: .style) + try container.encodeIfPresent(size, forKey: .size) + try container.encodeIfPresent(weight, forKey: .weight) + } } diff --git a/Sources/MusicXML/Complex Types/Fret.swift b/Sources/MusicXML/Complex Types/Fret.swift index f641e26..50a297b 100644 --- a/Sources/MusicXML/Complex Types/Fret.swift +++ b/Sources/MusicXML/Complex Types/Fret.swift @@ -36,6 +36,12 @@ public struct Fret { } } +extension Fret: ExpressibleByIntegerLiteral { + public init(integerLiteral value: Int) { + self.init(value) + } +} + extension Fret: Equatable { } extension Fret: Codable { private enum CodingKeys: String, CodingKey { @@ -56,16 +62,22 @@ extension Fret: Codable { } } public func encode(to encoder: Encoder) throws { - var singleValueContainer = encoder.singleValueContainer() - try singleValueContainer.encode(font) + try font.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(value, forKey: .value) try container.encodeIfPresent(color, forKey: .color) } } -extension Fret: ExpressibleByIntegerLiteral { - public init(integerLiteral value: Int) { - self.init(value) +import XMLCoder + +extension Fret: DynamicNodeEncoding { + public static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding { + switch key { + case CodingKeys.value: + return .element + default: + return .attribute + } } } diff --git a/Sources/MusicXML/Simple Types/Color.swift b/Sources/MusicXML/Simple Types/Color.swift index 87a8f19..2e34631 100644 --- a/Sources/MusicXML/Simple Types/Color.swift +++ b/Sources/MusicXML/Simple Types/Color.swift @@ -28,6 +28,9 @@ public struct Color { extension Color: Equatable { } extension Color: Codable { + private enum CodingKeys: String, CodingKey { + case hexValue = "" + } public init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() guard let color = Color.init(hexString: try container.decode(String.self)) else { @@ -41,6 +44,10 @@ extension Color: Codable { } self = color } + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(String(hexValue, radix: 16, uppercase: true)) + } } extension String { diff --git a/Tests/MusicXMLTests/Complex Types/FretTests.swift b/Tests/MusicXMLTests/Complex Types/FretTests.swift new file mode 100644 index 0000000..71c1d86 --- /dev/null +++ b/Tests/MusicXMLTests/Complex Types/FretTests.swift @@ -0,0 +1,20 @@ +// +// FretTests.swift +// MusicXMLTests +// +// Created by James Bean on 10/24/19. +// + +import XCTest +import MusicXML + +class FretTests: XCTestCase { + + func testRoundTrip() throws { + let fret = Fret(3, + color: Color(hexValue: 0xFFFFFF), + font: Font(style: .italic, weight: .bold) + ) + try testRoundTrip(fret, loggingEncoded: true) + } +} diff --git a/Tests/MusicXMLTests/Complex Types/HarmonicTests.swift b/Tests/MusicXMLTests/Complex Types/HarmonicTests.swift new file mode 100644 index 0000000..7b98400 --- /dev/null +++ b/Tests/MusicXMLTests/Complex Types/HarmonicTests.swift @@ -0,0 +1,26 @@ +// +// HarmonicTests.swift +// MusicXMLTests +// +// Created by James Bean on 10/24/19. +// + +import XCTest +import MusicXML + +class HarmonicTests: XCTestCase { + + func testRoundTrip() throws { + let harmonic = Harmonic( + naturalArtificial: .natural, + baseSoundingTouchingPitch: .base, + printObject: true, + placement: .above, + printStyle: PrintStyle( + position: Position(relativeY: -30), + color: Color(hexValue: 0x000000) + ) + ) + try testRoundTrip(harmonic) + } +} From f4454ac7dcccc0cb43663a094cbf28e7bc48daf7 Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 19:23:12 -0400 Subject: [PATCH 10/12] Add LyricFont round trip test --- .../Complex Types/LyricFontTests.swift | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Tests/MusicXMLTests/Complex Types/LyricFontTests.swift diff --git a/Tests/MusicXMLTests/Complex Types/LyricFontTests.swift b/Tests/MusicXMLTests/Complex Types/LyricFontTests.swift new file mode 100644 index 0000000..1533d63 --- /dev/null +++ b/Tests/MusicXMLTests/Complex Types/LyricFontTests.swift @@ -0,0 +1,21 @@ +// +// LyricFontTests.swift +// MusicXMLTests +// +// Created by James Bean on 10/24/19. +// + +import XCTest +import MusicXML + +class LyricFontTests: XCTestCase { + + func testRoundTrip() throws { + let lyricFont = LyricFont( + Font(family: "Helvetica", style: .italic, size: 42, weight: .bold), + number: 13, + name: "Recitative" + ) + try testRoundTrip(lyricFont) + } +} From 1f76d96d2dfb6785399a432d232348d05c1e16f3 Mon Sep 17 00:00:00 2001 From: James Bean Date: Thu, 24 Oct 2019 19:28:08 -0400 Subject: [PATCH 11/12] Add MeasureNumbering round trip test --- .../Complex Types/MeasureNumbering.swift | 16 ++++++++-- .../Complex Types/MeasureNumberingTests.swift | 31 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Tests/MusicXMLTests/Complex Types/MeasureNumberingTests.swift diff --git a/Sources/MusicXML/Complex Types/MeasureNumbering.swift b/Sources/MusicXML/Complex Types/MeasureNumbering.swift index 48c95c9..50fe240 100644 --- a/Sources/MusicXML/Complex Types/MeasureNumbering.swift +++ b/Sources/MusicXML/Complex Types/MeasureNumbering.swift @@ -32,9 +32,21 @@ extension MeasureNumbering: Codable { self.value = try container.decode(MeasureNumberingValue.self, forKey: .value) } public func encode(to encoder: Encoder) throws { - var singleValueContainer = encoder.singleValueContainer() - try singleValueContainer.encode(printStyleAlign) + try printStyleAlign.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(value, forKey: .value) } } + +import XMLCoder + +extension MeasureNumbering: DynamicNodeEncoding { + public static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding { + switch key { + case CodingKeys.value: + return .element + default: + return .attribute + } + } +} diff --git a/Tests/MusicXMLTests/Complex Types/MeasureNumberingTests.swift b/Tests/MusicXMLTests/Complex Types/MeasureNumberingTests.swift new file mode 100644 index 0000000..8d290a0 --- /dev/null +++ b/Tests/MusicXMLTests/Complex Types/MeasureNumberingTests.swift @@ -0,0 +1,31 @@ +// +// MeasureNumberingTests.swift +// MusicXMLTests +// +// Created by James Bean on 10/24/19. +// + +import XCTest +import MusicXML + +class MeasureNumberingTests: XCTestCase { + + func testRoundTrip() throws { + let numbering = MeasureNumbering(.system, + printStyleAlign: PrintStyleAlign( + printStyle: PrintStyle( + position: Position( + defaultX: 100, + defaultY: -100, + relativeX: 25, + relativeY: -25 + ), + font: Font(weight: .bold), + color: Color(hexValue: 0x000000)), + hAlign: .left, + vAlign: .bottom + ) + ) + try testRoundTrip(numbering) + } +} From 8f04daad3e6a1ff74f3207208dece67e9d470abe Mon Sep 17 00:00:00 2001 From: James Bean Date: Fri, 25 Oct 2019 11:56:36 -0700 Subject: [PATCH 12/12] Update Linux tests --- Tests/MusicXMLTests/XCTestManifests.swift | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Tests/MusicXMLTests/XCTestManifests.swift b/Tests/MusicXMLTests/XCTestManifests.swift index 6768b23..eb16544 100644 --- a/Tests/MusicXMLTests/XCTestManifests.swift +++ b/Tests/MusicXMLTests/XCTestManifests.swift @@ -18,6 +18,7 @@ extension AccordionRegistrationTests { // to regenerate. static let __allTests__AccordionRegistrationTests = [ ("testDecoding", testDecoding), + ("testRoundTrip", testRoundTrip), ] } @@ -139,6 +140,33 @@ extension DirectionsTests { ] } +extension EndingTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__EndingTests = [ + ("testRoundTrip", testRoundTrip), + ] +} + +extension FretTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__FretTests = [ + ("testRoundTrip", testRoundTrip), + ] +} + +extension HarmonicTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__HarmonicTests = [ + ("testRoundTrip", testRoundTrip), + ] +} + extension HarmonyTests { // DO NOT MODIFY: This is autogenerated, use: // `swift test --generate-linuxmain` @@ -194,6 +222,15 @@ extension LilyPondTests { ] } +extension LyricFontTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__LyricFontTests = [ + ("testRoundTrip", testRoundTrip), + ] +} + extension MIDIDeviceTests { // DO NOT MODIFY: This is autogenerated, use: // `swift test --generate-linuxmain` @@ -214,6 +251,15 @@ extension MIDIInstrumentTests { ] } +extension MeasureNumberingTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__MeasureNumberingTests = [ + ("testRoundTrip", testRoundTrip), + ] +} + extension MeasureStyleTests { // DO NOT MODIFY: This is autogenerated, use: // `swift test --generate-linuxmain` @@ -573,13 +619,18 @@ public func __allTests() -> [XCTestCaseEntry] { testCase(CreatorTests.__allTests__CreatorTests), testCase(DirectionTests.__allTests__DirectionTests), testCase(DirectionsTests.__allTests__DirectionsTests), + testCase(EndingTests.__allTests__EndingTests), + testCase(FretTests.__allTests__FretTests), + testCase(HarmonicTests.__allTests__HarmonicTests), testCase(HarmonyTests.__allTests__HarmonyTests), testCase(HelloWorld.__allTests__HelloWorld), testCase(IdentificationTests.__allTests__IdentificationTests), testCase(KeyTests.__allTests__KeyTests), testCase(LilyPondTests.__allTests__LilyPondTests), + testCase(LyricFontTests.__allTests__LyricFontTests), testCase(MIDIDeviceTests.__allTests__MIDIDeviceTests), testCase(MIDIInstrumentTests.__allTests__MIDIInstrumentTests), + testCase(MeasureNumberingTests.__allTests__MeasureNumberingTests), testCase(MeasureStyleTests.__allTests__MeasureStyleTests), testCase(MetronomeTests.__allTests__MetronomeTests), testCase(MidmeasureClefTests.__allTests__MidmeasureClefTests),