Swift edition
Optionals
Operators that change how an optional is unwrapped: its default, or a chain through it. Where the Java edition has Optional, Swift has these.
| Operator | Changes | Set |
|---|---|---|
optional/no-default | a ?? b to a! | stronger |
optional/always-default | a ?? b to the default alone | stronger |
swift/chain-nil | an optional chain to nil | extended |
The mutants each makes, on samples/operators/Sources/Operators/Options.swift:
mutastic mutants samples/operators --at=Sources/Operators/Options.swift:1-99 --operators=optional/no-default,optional/always-default,swift/chain-nilm6bf25672 Sources/Operators/Options.swift:23:21 optional/always-default customer.nickname ?? "friend" becomes nil ?? "friend" in displayNamem09d157d2 Sources/Operators/Options.swift:23:21 optional/no-default customer.nickname ?? "friend" becomes customer.nickname! in displayNamem8933c593 Sources/Operators/Options.swift:28:14 swift/chain-nil customer?.address?.city becomes nil in citym343ad6e8 Sources/Operators/Options.swift:29:15 optional/always-default city ?? "unknown" becomes nil ?? "unknown" in citym508dfb59 Sources/Operators/Options.swift:29:15 optional/no-default city ?? "unknown" becomes city! in cityno estimate: no run is recorded here yet; run once to get estimates, or add --estimate5 mutantsNo default
Section titled “No default”optional/no-default, in stronger. The default is taken away, so a nil crashes instead. It asks for a test where the value is nil.
Always default
Section titled “Always default”optional/always-default, in stronger. The value is taken as nil, so the default is always used. It asks for a test where the value is there.
Chain nil
Section titled “Chain nil”swift/chain-nil, in extended and all, not in the defaults or stronger. Swift’s own. An optional chain whose value is used, customer?.address?.city, gives nil, as if a link in it were missing.
- Every operator, in one table.