Repository: jpsim/Yams (swift)

Issue:
dump failed if there is a nil value
![image](https://user-images.githubusercontent.com/1251192/69246663-10c4bf80-0be4-11ea-9d55-842be8348590.png)
I am using Swift 5.1 and Xcode 11.2.1.

I try to debug the Yams, and it throw a error:
```swift
private func represent(_ value: Any) throws -> Node {
    if let string = value as? String {
        return Node(string)
    } else if let representable = value as? NodeRepresentable {
        return try representable.represented()
    }
    throw YamlError.representer(problem: "Failed to represent \(value)")  // -> print "Failed to represent nil"
}

extension Optional: NodeRepresentable {
    public func represented() throws -> Node {
        switch self {
        case let .some(wrapped):
            return try represent(wrapped)  // <-- The ALIAS's value hit this case, but it is nil. As it is a .some<nil>
        case .none:
            return Node("null", Tag(.null))
        }
    }
}
```

Is it a bug?

Pull request description:
Fixes https://github.com/jpsim/Yams/issues/232

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a22d6a38..87d293ca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,10 @@
 
 ##### Bug Fixes
 
+* Fix `Yams.dump` when object contains a keyed null value.  
+  [JP Simard](https://github.com/jpsim)
+  [#232](https://github.com/jpsim/Yams/issues/232)
+
 * Fix a bug where `YAMLEncoder` would delay `Date`s by 1 second when encoding
   values with a `nanosecond` component greater than 999499997.  
   [Norio Nomura](https://github.com/norio-nomura)
diff --git a/Sources/Yams/Representer.swift b/Sources/Yams/Representer.swift
index 0beec59b..37f96f44 100644
--- a/Sources/Yams/Representer.swift
+++ b/Sources/Yams/Representer.swift
@@ -73,6 +73,13 @@ extension ScalarRepresentable {
     }
 }
 
+extension NSNull: ScalarRepresentable {
+    /// This value's `Node.scalar` representation.
+    public func represented() -> Node.Scalar {
+        return .init("null", Tag(.null))
+    }
+}
+
 extension Bool: ScalarRepresentable {
     /// This value's `Node.scalar` representation.
     public func represented() -> Node.Scalar {


Test patch:
diff --git a/Tests/YamsTests/RepresenterTests.swift b/Tests/YamsTests/RepresenterTests.swift
index 47e553ba..4829b479 100644
--- a/Tests/YamsTests/RepresenterTests.swift
+++ b/Tests/YamsTests/RepresenterTests.swift
@@ -106,7 +106,20 @@ class RepresenterTests: XCTestCase {
     }
 
     func testOptional() throws {
+        // Optional.none
         XCTAssertEqual(try Node(Int?.none), "null")
+
+        // Optional.some(.none)
+        XCTAssertEqual(try Node(Int??.some(nil)), "null")
+
+        // Keyed null - https://github.com/jpsim/Yams/issues/232
+        let keyedNullString = """
+            A: null
+
+            """
+        let keyedNullObject = try Yams.load(yaml: keyedNullString)
+        let keyedNullDump = try Yams.dump(object: keyedNullObject)
+        XCTAssertEqual(keyedNullDump, keyedNullString)
     }
 
     func testArray() throws {