twonly-app/test/unit_test.dart

73 lines
2.1 KiB
Dart
Raw Normal View History

2025-07-18 19:59:11 +00:00
import 'dart:typed_data';
2024-12-31 08:50:53 +00:00
import 'package:flutter_test/flutter_test.dart';
2025-10-25 23:14:46 +00:00
import 'package:hashlib/random.dart';
import 'package:twonly/src/utils/misc.dart';
2025-07-18 19:59:11 +00:00
import 'package:twonly/src/utils/pow.dart';
2025-04-21 19:32:18 +00:00
import 'package:twonly/src/views/components/animate_icon.dart';
2024-12-31 08:50:53 +00:00
void main() {
2025-07-18 19:59:11 +00:00
group('testing utils', () {
2025-04-14 19:30:40 +00:00
test('test isEmoji function', () {
2026-01-19 22:15:28 +00:00
expect(isOneEmoji('Hallo'), false);
expect(isOneEmoji('😂'), true);
expect(isOneEmoji('😂😂'), false);
expect(isOneEmoji('Hallo 😂'), false);
2024-12-31 08:50:53 +00:00
});
2025-07-18 19:59:11 +00:00
test('test proof-of-work simple', () async {
2025-11-06 19:50:22 +00:00
// ignore: prefer_single_quotes
expect(await calculatePoW("testing", 10), 783);
2025-07-18 19:59:11 +00:00
});
test('encode hex', () async {
final list1 = Uint8List.fromList([41, 41, 41, 41, 41, 41, 41]);
expect(list1, hexToUint8List(uint8ListToHex(list1)));
});
2025-10-25 23:14:46 +00:00
test('Zero inputs produce all-zero UUID', () {
expect(
getUUIDforDirectChat(0, 0),
'00000000-0000-0000-0000-000000000000',
);
expect(getUUIDforDirectChat(0, 0).length, uuid.v1().length);
});
test('Max int values (0x7fffffff)', () {
const max32 = 0x7fffffff; // 2147483647
expect(
getUUIDforDirectChat(max32, max32),
'00000000-7fff-ffff-0000-00007fffffff',
);
});
test('Bigger goes front', () {
expect(
getUUIDforDirectChat(1, 0),
'00000000-0000-0001-0000-000000000000',
);
expect(
getUUIDforDirectChat(0, 1),
'00000000-0000-0001-0000-000000000000',
);
});
test('Arbitrary within 32-bit range', () {
expect(
getUUIDforDirectChat(0x12345678, 0x0abcdef0),
'00000000-1234-5678-0000-00000abcdef0',
);
});
2025-12-15 18:12:25 +00:00
test('Arbitrary within 32-bit range', () {
expect(
// ignore: avoid_js_rounded_ints
getUUIDforDirectChat(0x7dc8a4f20a75de46, 0x7ffffffffffffff8),
'7fffffff-ffff-fff8-7dc8-a4f20a75de46',
);
2025-10-25 23:14:46 +00:00
});
2025-12-15 18:12:25 +00:00
// test('Reject values > 0x7fffffff', () {
// expect(() => getUUIDforDirectChat(0x80000000, 0), throwsArgumentError);
// });
2024-12-31 08:50:53 +00:00
});
}