McBopomofo
McBopomofo copied to clipboard
Preferences being a singleton makes it hard to run hermetic tests
I wonder if we should consider making Preferences an instantiable class, and the input method app should instantiate with the user defaults back store, whereas tests can instantiate with an empty dictionary. We now have quite some test code that does this:
let someSavedState = Preferences.someKey
// do the test
Preferences.someKey = someSavedState
PR #293 also needs to do this in Plain BPMF test's setup and teardown due to punctution handling is coupled with keyboard layout. Interestingly, KeyHandler
by default does not depend on it; it only reads from Preferences
when InputMethodController
tells it to sync with the prefs; but punctuaction handllers need to eagerly read the keyboard layout value…
I guess we can extract a DTO from the preferences and then put it into KeyHandlerInput
, so the key handler can just depends on the input data but no other dependencies.
Actually I've already put the flag to use vertical candidate in KeyHandlerInput
.