Unverified Commit 72828d66 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Include raw value in Diagnostics json for basic types (#34417)

parent 1c6cda9a
......@@ -2551,6 +2551,8 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
json['defaultLevel'] = describeEnum(_defaultLevel);
if (value is Diagnosticable || value is DiagnosticsNode)
json['isDiagnosticableValue'] = true;
if (value is num || value is String || value is bool || value == null)
json['value'] = value;
return json;
}
......
......@@ -2098,4 +2098,41 @@ void main() {
)
);
});
test('DiagnosticsProperty for basic types has value in json', () {
DiagnosticsProperty<int> intProperty = DiagnosticsProperty<int>('int1', 10);
Map<String, Object> json = simulateJsonSerialization(intProperty);
expect(json['name'], 'int1');
expect(json['value'], 10);
intProperty = IntProperty('int2', 20);
json = simulateJsonSerialization(intProperty);
expect(json['name'], 'int2');
expect(json['value'], 20);
DiagnosticsProperty<double> doubleProperty = DiagnosticsProperty<double>('double', 33.3);
json = simulateJsonSerialization(doubleProperty);
expect(json['name'], 'double');
expect(json['value'], 33.3);
doubleProperty = DoubleProperty('double2', 33.3);
json = simulateJsonSerialization(doubleProperty);
expect(json['name'], 'double2');
expect(json['value'], 33.3);
final DiagnosticsProperty<bool> boolProperty = DiagnosticsProperty<bool>('bool', true);
json = simulateJsonSerialization(boolProperty);
expect(json['name'], 'bool');
expect(json['value'], true);
DiagnosticsProperty<String> stringProperty = DiagnosticsProperty<String>('string1', 'hello');
json = simulateJsonSerialization(stringProperty);
expect(json['name'], 'string1');
expect(json['value'], 'hello');
stringProperty = StringProperty('string2', 'world');
json = simulateJsonSerialization(stringProperty);
expect(json['name'], 'string2');
expect(json['value'], 'world');
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment