(#17260) Warn when variables contain hyphens
Previously the deprecation warnings for hyphens in variables
incorrectly warned even when there were no hyphens in the variable.
There was also no warning about hypens in variable interpolations when
the bare-word form of interpolation was used, e.g. "${foo-bar}".
This commit causes those two cases to warn correctly and also cleans up
the tests to be more directed to just the lexing of specific tokens.
This also removes some duplication that crept in around checking and
issuing the warning.
Paired-with: henrik.lindberg@cloudsmith.com