DictionaryTests.swift
1 import Testing 2 @testable import SwiftExtended 3 4 @Test func dictionaryAccess() async throws { 5 var dict = ["a": 1, "b": 2, "c": 3] 6 dict.access(key: "a") { $0 = 42 } 7 dict.access(key: "d") { $0 = 11 } 8 #expect(dict["a"] == 42) 9 #expect(dict["d"] == 11) 10 } 11 12 @Test func dictionarySubscript() async throws { 13 var dict = ["a": 1, "b": 2, "c": 3] 14 #expect(dict["a", insertingDefault: 42] == 1) 15 #expect(dict["d", insertingDefault: 11] == 11) 16 dict["e", insertingDefault: 11] += 1 17 #expect(dict["e", insertingDefault: 11] == 12) 18 #expect(dict == ["a": 1, "b": 2, "c": 3, "d": 11, "e": 12]) 19 }