Skip to content

Commit

Permalink
Add tests for flat dictionary, fix dictionaryLiteral (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler authored Mar 20, 2023
1 parent 5cdb391 commit f38a3ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Hummingbird/Utils/FlatDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/// functions will always return the first key found, but if you
/// iterate through the key,value pairs you can access all values
/// for a key
public struct FlatDictionary<Key: Hashable, Value>: Collection {
public struct FlatDictionary<Key: Hashable, Value>: Collection, ExpressibleByDictionaryLiteral {
public typealias Element = (key: Key, value: Value)
public typealias Index = Array<Element>.Index

Expand Down
39 changes: 39 additions & 0 deletions Tests/HummingbirdTests/UtilsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2023 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Hummingbird
import XCTest

class FlatDictionaryTests: XCTestCase {
func testLiteralInit() {
let a: FlatDictionary<String, String> = ["test": "value", "key2": "value2"]
XCTAssertEqual(a["test"], "value")
XCTAssertEqual(a["key2"], "value2")
}

func testKeyGetSet() {
var a: FlatDictionary<String, String> = [:]
a["key"] = "value"
XCTAssertEqual(a["key"], "value")
a["key"] = nil
XCTAssertEqual(a["key2"], nil)
}

func testKeyGetFirst() {
var a: FlatDictionary<String, String> = [:]
a.append(key: "key", value: "value1")
a.append(key: "key", value: "value2")
XCTAssertEqual(a["key"], "value1")
}
}

0 comments on commit f38a3ab

Please sign in to comment.