I noticed the Ask method on BasicUi type uses bufio.Reader.ReadString() whereas the Ask method on MockUi uses fmt.Fscanln for reading from Reader input. This causes two problems:
When using BasicUi, one can enter a string with spaces. However, in tests when using MockUi, reading a string with spaces only returns the first word.
When using BasicUi, one can press Enter key and get a empty string back without any error, while using MockUi in tests returns an unexpected newline error.
This discrepancy between the actual implementation of Ask and the mocked implementation of Ask makes testing of the two cases mentioned above very hard.
This PR addresses this issue and make the actual and mocked implementation working the same way.
I noticed the
Ask
method onBasicUi
type usesbufio.Reader.ReadString()
whereas theAsk
method onMockUi
usesfmt.Fscanln
for reading fromReader
input. This causes two problems:When using
BasicUi
, one can enter a string with spaces. However, in tests when usingMockUi
, reading a string with spaces only returns the first word. When usingBasicUi
, one can pressEnter
key and get a empty string back without any error, while usingMockUi
in tests returns anunexpected newline
error.This discrepancy between the actual implementation of
Ask
and the mocked implementation ofAsk
makes testing of the two cases mentioned above very hard.This PR addresses this issue and make the actual and mocked implementation working the same way.