- Updated LoRa airtime calculations in `lora_airtime_test.dart` to reflect new reference values. - Introduced new tests for LDRO behavior and preamble symbol calculations. - Added `contact_path_width_test.dart` to validate path hash width handling in contacts. - Enhanced `model_changes_test.dart` to ensure legacy data migration works correctly. - Created `remote_node_stats_test.dart` to decode and validate remote node statistics. - Implemented `map_marker_parse_test.dart` for parsing marker text with coordinate validation. - Developed `map_tile_cache_key_test.dart` to ensure API keys are excluded from cache keys. - Added `message_retry_failure_test.dart` to test message retry service behavior on failures. - Extended `path_history_service_test.dart` to preserve learned state across path attempts. - Enhanced `received_image_store_test.dart` to handle concurrent writes and review fixes. - Implemented `repeater_command_service_test.dart` to validate command response handling. - Created `store_tolerant_parsing_test.dart` to ensure stores skip malformed records gracefully. - Cleared untranslated JSON file for localization updates.
76 lines
2.3 KiB
Dart
76 lines
2.3 KiB
Dart
import 'package:flutter/services.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
import 'package:meshcore_open/helpers/utf8_length_limiter.dart';
|
||
|
||
TextEditingValue _value(String text, [int? cursor]) => TextEditingValue(
|
||
text: text,
|
||
selection: TextSelection.collapsed(offset: cursor ?? text.length),
|
||
);
|
||
|
||
void main() {
|
||
const formatter = Utf8LengthLimitingTextInputFormatter(5);
|
||
|
||
test('accepts edits within the limit', () {
|
||
final result = formatter.formatEditUpdate(_value('ab'), _value('abc'));
|
||
expect(result.text, 'abc');
|
||
});
|
||
|
||
test('clips only the inserted text and keeps the end of the draft', () {
|
||
// Paste "XYZ" at the start of "abc" (limit 5 bytes).
|
||
final result = formatter.formatEditUpdate(
|
||
_value('abc', 0),
|
||
_value('XYZabc', 3),
|
||
);
|
||
expect(result.text, 'XYabc');
|
||
expect(result.selection.baseOffset, 2);
|
||
});
|
||
|
||
test('rejects an insertion in the middle when full', () {
|
||
final result = formatter.formatEditUpdate(
|
||
_value('abcde', 2),
|
||
_value('abXcde', 3),
|
||
);
|
||
expect(result.text, 'abcde');
|
||
expect(result.selection.baseOffset, 2);
|
||
});
|
||
|
||
test('does not split a multi-code-point grapheme', () {
|
||
// Family emoji is 18 UTF-8 bytes, so it cannot fit in the 4 bytes left.
|
||
final result = formatter.formatEditUpdate(
|
||
_value('a'),
|
||
_value('a\u{1F468}\u{1F469}\u{1F467}'),
|
||
);
|
||
expect(result.text, 'a');
|
||
});
|
||
|
||
test('keeps whole emoji that fit', () {
|
||
const limiter = Utf8LengthLimitingTextInputFormatter(9);
|
||
final result = limiter.formatEditUpdate(
|
||
_value('a'),
|
||
_value('a\u{1F600}\u{1F601}'),
|
||
);
|
||
expect(result.text, 'a\u{1F600}\u{1F601}');
|
||
final clipped = const Utf8LengthLimitingTextInputFormatter(
|
||
8,
|
||
).formatEditUpdate(_value('a'), _value('a\u{1F600}\u{1F601}'));
|
||
expect(clipped.text, 'a\u{1F600}');
|
||
});
|
||
|
||
test('replacing one emoji with another sharing a surrogate stays valid', () {
|
||
const limiter = Utf8LengthLimitingTextInputFormatter(5);
|
||
final result = limiter.formatEditUpdate(
|
||
_value('a\u{1F600}'),
|
||
_value('a\u{1F601}\u{1F602}'),
|
||
);
|
||
expect(result.text, 'a\u{1F601}');
|
||
});
|
||
|
||
test('allows deletions even when the text is already over the limit', () {
|
||
final result = formatter.formatEditUpdate(
|
||
_value('abcdefg'),
|
||
_value('abcdef'),
|
||
);
|
||
expect(result.text, 'abcdef');
|
||
});
|
||
}
|