     
     func testEncodingTopLevelEmptyClass() {
         _testRoundTrip(of: EmptyClass(), expected: [:])
+    }
+    
+    // MARK: - Encoding Top-Level Single-Value Types
+    func testEncodingTopLevelSingleValueEnum() {
+        let s1 = Switch.off
+        _testEncodeFailure(of: s1)
+        _testRoundTrip(of: TopLevelWrapper(s1))
+        
+        let s2 = Switch.on
+        _testEncodeFailure(of: s2)
+        _testRoundTrip(of: TopLevelWrapper(s2))
+    }
+    
+    func testEncodingTopLevelSingleValueStruct() {
+        let t = Timestamp(3141592653)
+        _testEncodeFailure(of: t)
+        _testRoundTrip(of: TopLevelWrapper(t))
+    }
+    
+    func testEncodingTopLevelSingleValueClass() {
+        let c = Counter()
+        _testEncodeFailure(of: c)
+        _testRoundTrip(of: TopLevelWrapper(c))
     }
     
     func testTypeCoercion() {

        _testRoundTripTypeCoercionFailure(of: [0.0, 1.0] as [Double], as: [Bool].self)
    }
    
    private func _testRoundTripTypeCoercionFailure<T,U>(of value: T, as type: U.Type) where T : Codable, U : Codable {
        do {
            let data = try FirestoreEncoder().encode(value)

    static var testValue: Mapping {
        return Mapping(values: ["Apple": URL(string: "http://apple.com")!,
                                "localhost": URL(string: "http://127.0.0.1")!])
    }
}

/// Wraps a type T so that it can be encoded at the top level of a payload.
fileprivate struct TopLevelWrapper<T> : Codable, Equatable where T : Codable, T : Equatable {
    let value: T
    
    init(_ value: T) {
        self.value = value
    }
    
    static func ==(_ lhs: TopLevelWrapper<T>, _ rhs: TopLevelWrapper<T>) -> Bool {
        return lhs.value == rhs.value
    }
}

