1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-19 19:51:35 +03:00
vimr/Commons/Tests/CommonsTests/DictionaryCommonsTest.swift

45 lines
680 B
Swift
Raw Normal View History

2017-05-02 23:18:09 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Nimble
2020-09-18 17:01:55 +03:00
import XCTest
2017-05-02 23:18:09 +03:00
class DictionaryCommonsTest: XCTestCase {
func testMapToDict() {
let dict = [
1: "a",
2: "b",
2020-09-18 17:01:55 +03:00
3: "c",
2017-05-02 23:18:09 +03:00
]
2020-09-18 17:01:55 +03:00
expect(dict.mapToDict { k, v in (v, "\(k)-\(v)") }).to(equal(
2017-05-02 23:18:09 +03:00
[
"a": "1-a",
"b": "2-b",
2020-09-18 17:01:55 +03:00
"c": "3-c",
2017-05-02 23:18:09 +03:00
]
))
}
func testFlatMapToDict() {
let dict = [
1: "a",
2: "b",
2020-09-18 17:01:55 +03:00
3: "c",
2017-05-02 23:18:09 +03:00
]
2020-09-18 17:01:55 +03:00
expect(dict.flatMapToDict { k, v in
2017-05-02 23:18:09 +03:00
if k == 2 {
return nil
}
return (v, "\(k)-\(v)")
}).to(equal(
[
"a": "1-a",
2020-09-18 17:01:55 +03:00
"c": "3-c",
2017-05-02 23:18:09 +03:00
]
))
}
}