refactor: medium repository context helpers (#28311)

* refactor: medium repository context helpers

* test: add regress test for 26723

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
shenlong
2026-05-09 20:19:31 +07:00
committed by GitHub
parent 5ba3efafd8
commit faab9e620d
4 changed files with 194 additions and 112 deletions
+12
View File
@@ -1,10 +1,22 @@
import 'dart:math';
import 'package:uuid/uuid.dart';
class TestUtils {
static final _random = Random();
static String uuid([String? id]) => id ?? const Uuid().v4();
static DateTime date([DateTime? date]) => date ?? DateTime.now();
static DateTime now() => DateTime.now();
static DateTime yesterday() => DateTime.now().subtract(const Duration(days: 1));
static DateTime tomorrow() => DateTime.now().add(const Duration(days: 1));
static T randElement<T>(List<T> list) => list[_random.nextInt(list.length)];
static int randInt([int? max]) => max != null ? _random.nextInt(max) : _random.nextInt(1 << 32);
static double randDouble([int? max, int? min]) {
final minValue = min ?? 0;
final maxValue = max ?? 1;
return minValue + _random.nextDouble() * (maxValue - minValue);
}
}