Skip to content
mutastic

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.

OperatorChangesSet
optional/no-defaulta ?? b to a!stronger
optional/always-defaulta ?? b to the default alonestronger
swift/chain-nilan optional chain to nilextended

The mutants each makes, on samples/operators/Sources/Operators/Options.swift:

Terminal window
mutastic mutants samples/operators --at=Sources/Operators/Options.swift:1-99 --operators=optional/no-default,optional/always-default,swift/chain-nil
Terminal window
m6bf25672 Sources/Operators/Options.swift:23:21 optional/always-default customer.nickname ?? "friend" becomes nil ?? "friend" in displayName
m09d157d2 Sources/Operators/Options.swift:23:21 optional/no-default customer.nickname ?? "friend" becomes customer.nickname! in displayName
m8933c593 Sources/Operators/Options.swift:28:14 swift/chain-nil customer?.address?.city becomes nil in city
m343ad6e8 Sources/Operators/Options.swift:29:15 optional/always-default city ?? "unknown" becomes nil ?? "unknown" in city
m508dfb59 Sources/Operators/Options.swift:29:15 optional/no-default city ?? "unknown" becomes city! in city
no estimate: no run is recorded here yet; run once to get estimates, or add --estimate
5 mutants

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.

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.

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.