Remove dead code

The nested `switch` statement created two unreachable code paths and
negatively impacted code clarity. By expressing the same logic with a
single `if` statement (containing an early return), all paths are
reachable.
Add test for uncovered code path

Ensure the behavior of `val` when invoked on an empty selection.