Commit 7464eef

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-07-30 12:00:45
assert and test toString never used directly
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 1e6af8f
Changed files (4)
app
health_data_store
lib
src
types
test
src
types
app/test/model/export_import/column_test.dart
@@ -43,7 +43,7 @@ void main() {
       for (final c in NativeColumn.allColumns) {
         final txt = c.encode(r.$1, r.$2, r.$3);
         final decoded = c.decode(txt);
-        expect(decoded, isNotNull, reason: 'a real value was encoded: ${c.internalIdentifier}: $r > $txt');
+        expect(decoded, isNotNull, reason: 'a real value was encoded: ${c.internalIdentifier}: ${r.debugToString()} > $txt');
         switch (decoded!.$1) {
           case RowDataFieldType.timestamp:
             expect(decoded.$2, isA<DateTime>().having(
app/test/model/export_import/record_formatter_test.dart
@@ -168,3 +168,15 @@ FullEntry mockEntry({
     (intake == null ? [] : [ intake ]),
   );
 }
+
+extension DebugFormat on FullEntry {
+  String debugToString() => 'FullEntry('
+    'time: $time, '
+    'sys: ${sys?.mmHg}, '
+    'dia: ${dia?.mmHg}, '
+    'pul: $pul, '
+    'note: $note, '
+    'color: $color, '
+    'intakes: $intakes'
+  ')';
+}
health_data_store/lib/src/types/units/pressure.dart
@@ -24,4 +24,11 @@ class Pressure {
 
   @override
   int get hashCode => _valPa.hashCode;
+
+  @override
+  String toString() {
+    assert(false, 'Avoid calling toString on Pressure directly as this may not'
+                  'respect the users preferences.');
+    return mmHg.toString();
+  }
 }
health_data_store/test/src/types/units/pressure_test.dart
@@ -16,4 +16,8 @@ void main() {
     expect(Pressure.kPa(15.9987).mmHg, 120);
     expect(Pressure.kPa(10.0).mmHg, 75);
   });
+
+  test('should attempt to avoid printing', () {
+    expect(() => Pressure.mmHg(120).toString(), throwsA(isA<AssertionError>()));
+  });
 }