PowerShell v2+, 59 58 5252 51 bytes
param($n)(($n+'\/'[$n[-1]-eq92])," $n","$n/","$n\")[$n[['.\/'.IndexOf($n[-1]-eq46])]
Takes input $n
, dumps it into a pseudo-ternary (indexing into a dynamican array) index operation. We select the element of the array based on the index [$n[['.\/'.IndexOf($n[-1]-eq46])
(i-- i.e., if the last character is ASCII 46, a period). If it is a period, the indexing selects the second element, the " $n"
, which just prepends a space.
Otherwise, it selects the first element. Here we take $n
and append the result of a string slice against '\/'
, this time selecting the appropriate slash based on the last elementcharacter of the input string (by comparing against 92$n
, i.e., ASCII \
). The Booleanthis will result of -eq
is implicitly converted toin 0
or, 1
, so this slices theor '\/'2
. That corresponds to the appropriate string appropriatelyof the array.
In eitherany case, the resulting string is left on the pipeline and printing is implicit.
Test cases
PS C:\Tools\Scripts\golfing> 0..7|%{' '*$_+'.'}|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
. => .
. => .
. => .
. => .
. => .
. => .
. => .
. => .
PS C:\Tools\Scripts\golfing> '/,\,/\,\/,/\/,\/\,/\/\,\/\/'-split','|%{"$_ => "+(.\wave-particle-duality.ps1 "$_")}
/ => /\
\ => \/
/\ => /\/
\/ => \/\
/\/ => /\/\
\/\ => \/\/
/\/\ => /\/\/
\/\/ => \/\/\