feat(device): TX/RX 日志附加完整 JSON 字符串
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:kuaishai2/features/device/models/device_state.dart';
|
||||
import 'package:kuaishai2/features/device/services/device_log.dart';
|
||||
import 'package:kuaishai2/features/device/services/device_message.dart';
|
||||
import 'package:kuaishai2/features/device/services/json_protocol.dart';
|
||||
import 'package:kuaishai2/features/device/services/task_payload.dart';
|
||||
@@ -218,4 +219,38 @@ void main() {
|
||||
expect(s.infoStale, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('DeviceLog', () {
|
||||
test('summarizeData 截断长字符串与多余键', () {
|
||||
final data = {
|
||||
'a': 1,
|
||||
'b': 'short',
|
||||
'c': 'x' * 200,
|
||||
'd': [1, 2, 3],
|
||||
'e': true,
|
||||
'f': null,
|
||||
'g': 'extra',
|
||||
'h': 'extra2',
|
||||
'i': 'extra3',
|
||||
};
|
||||
final summary = DeviceLog.summarizeData(data, maxKeys: 4);
|
||||
expect(summary.contains('a=1'), isTrue);
|
||||
expect(summary.contains('b="short"'), isTrue);
|
||||
expect(summary.contains('…'), isTrue); // 长字符串被截断
|
||||
expect(summary.contains('…'), isTrue);
|
||||
expect(summary.contains(', ...'), isTrue); // 多余键被截断
|
||||
});
|
||||
|
||||
test('summarizeData 空 Map / null 友好处理', () {
|
||||
expect(DeviceLog.summarizeData(null), '{}');
|
||||
expect(DeviceLog.summarizeData({}), '{}');
|
||||
});
|
||||
|
||||
test('info / warn / severe 不抛异常', () {
|
||||
// 仅验证调用不抛异常;dart:developer.log 在测试环境无可见输出
|
||||
DeviceLog.info('hello');
|
||||
DeviceLog.warn('warn', error: StateError('x'));
|
||||
DeviceLog.severe('severe', error: 'err');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user