@SuppressLint("SetTextI18n") @Test public void cursorPosition() { MaskFormatWatcher watcher = new MaskFormatWatcher(MaskImpl.createTerminated(PredefinedSlots.RUS_PHONE_NUMBER)); assertEquals(0, watcher.getCursorPosition()); TextView textView = new TextView(RuntimeEnvironment.application); watcher.installOn(textView); textView.setText("9"); // +7_(9 assertEquals(5, watcher.getCursorPosition()); textView.setText(null); assertEquals(0, watcher.getCursorPosition()); textView.setText("999"); // +7_(999)_ assertEquals(9, watcher.getCursorPosition()); textView.setText("999876"); // +7_(999)_876- assertEquals(13, watcher.getCursorPosition()); textView.setText("9998765432111111111"); // +7_(999)_876-54-32 assertEquals(18, watcher.getCursorPosition()); textView.setText("7"); // +7_( assertEquals(4, watcher.getCursorPosition()); }
@Test public void forbidCursorMoving() { MaskFormatWatcher watcher = new MaskFormatWatcher(new MaskImpl(new PhoneNumberUnderscoreSlotsParser().parseSlots("+7 (___) ___-__-__"), true)); assertEquals(0, watcher.getCursorPosition()); TextView textView = new TextView(RuntimeEnvironment.application); watcher.installOn(textView); textView.setText("9"); // +7_(9 assertEquals(5, watcher.getCursorPosition()); textView.setText(null); assertEquals(0, watcher.getCursorPosition()); textView.setText("999"); // +7_(999)_ assertEquals(9, watcher.getCursorPosition()); textView.setText("999876"); // +7_(999)_876- assertEquals(13, watcher.getCursorPosition()); textView.setText("9998765432111111111"); // +7_(999)_876-54-32 assertEquals(18, watcher.getCursorPosition()); textView.setText("7"); // +7_( assertEquals(4, watcher.getCursorPosition()); } }