Unverified Commit ed54868c authored by Jacob Richman's avatar Jacob Richman Committed by GitHub

Change enum properties to use camel case instead of dash separated names

Make regular Alignment values look more like enumProperties while
leaving more complex AlignmentDirectional values unchanged.
parent 0350c9ec
...@@ -1510,8 +1510,8 @@ class IterableProperty<T> extends DiagnosticsProperty<Iterable<T>> { ...@@ -1510,8 +1510,8 @@ class IterableProperty<T> extends DiagnosticsProperty<Iterable<T>> {
/// An property than displays enum values tersely. /// An property than displays enum values tersely.
/// ///
/// The enum value is converted to a hyphen-separated string. For example: /// The enum value is displayed with the class name stripped. For example:
/// [HitTestBehavior.deferToChild] is shown as `defer-to-child`. /// [HitTestBehavior.deferToChild] is shown as `deferToChild`.
/// ///
/// See also: /// See also:
/// ///
...@@ -1536,7 +1536,7 @@ class EnumProperty<T> extends DiagnosticsProperty<T> { ...@@ -1536,7 +1536,7 @@ class EnumProperty<T> extends DiagnosticsProperty<T> {
String valueToString({ TextTreeConfiguration parentConfiguration }) { String valueToString({ TextTreeConfiguration parentConfiguration }) {
if (value == null) if (value == null)
return value.toString(); return value.toString();
return camelCaseToHyphenatedName(describeEnum(value)); return describeEnum(value);
} }
} }
...@@ -2056,32 +2056,6 @@ String describeEnum(Object enumEntry) { ...@@ -2056,32 +2056,6 @@ String describeEnum(Object enumEntry) {
return description.substring(indexOfDot + 1); return description.substring(indexOfDot + 1);
} }
/// Returns a lowercase hyphen-separated version of a camel case name.
///
/// ## Sample code
///
/// ```dart
/// validateCamelCaseToHyphenatedName() {
/// assert(camelCaseToHyphenatedName('deferToChild') == 'defer-to-child');
/// assert(camelCaseToHyphenatedName('Monday') == 'monday');
/// assert(camelCaseToHyphenatedName('monday') == 'monday');
/// }
/// ```
String camelCaseToHyphenatedName(String word) {
final String lowerWord = word.toLowerCase();
if (word == lowerWord)
return word;
final StringBuffer buffer = new StringBuffer();
for (int i = 0; i < word.length; i++) {
final String lower = lowerWord[i];
if (word[i] != lower && i > 0)
buffer.write('-');
buffer.write(lower);
}
return buffer.toString();
}
/// Builder to accumulate properties and configuration used to assemble a /// Builder to accumulate properties and configuration used to assemble a
/// [DiagnosticsNode] from a [Diagnosticable] object. /// [DiagnosticsNode] from a [Diagnosticable] object.
class DiagnosticPropertiesBuilder { class DiagnosticPropertiesBuilder {
......
...@@ -335,23 +335,23 @@ class Alignment extends AlignmentGeometry { ...@@ -335,23 +335,23 @@ class Alignment extends AlignmentGeometry {
static String _stringify(double x, double y) { static String _stringify(double x, double y) {
if (x == -1.0 && y == -1.0) if (x == -1.0 && y == -1.0)
return 'Alignment.topLeft'; return 'topLeft';
if (x == 0.0 && y == -1.0) if (x == 0.0 && y == -1.0)
return 'Alignment.topCenter'; return 'topCenter';
if (x == 1.0 && y == -1.0) if (x == 1.0 && y == -1.0)
return 'Alignment.topRight'; return 'topRight';
if (x == -1.0 && y == 0.0) if (x == -1.0 && y == 0.0)
return 'Alignment.centerLeft'; return 'centerLeft';
if (x == 0.0 && y == 0.0) if (x == 0.0 && y == 0.0)
return 'Alignment.center'; return 'center';
if (x == 1.0 && y == 0.0) if (x == 1.0 && y == 0.0)
return 'Alignment.centerRight'; return 'centerRight';
if (x == -1.0 && y == 1.0) if (x == -1.0 && y == 1.0)
return 'Alignment.bottomLeft'; return 'bottomLeft';
if (x == 0.0 && y == 1.0) if (x == 0.0 && y == 1.0)
return 'Alignment.bottomCenter'; return 'bottomCenter';
if (x == 1.0 && y == 1.0) if (x == 1.0 && y == 1.0)
return 'Alignment.bottomRight'; return 'bottomRight';
return 'Alignment(${x.toStringAsFixed(1)}, ' return 'Alignment(${x.toStringAsFixed(1)}, '
'${y.toStringAsFixed(1)})'; '${y.toStringAsFixed(1)})';
} }
......
...@@ -670,16 +670,6 @@ void main() { ...@@ -670,16 +670,6 @@ void main() {
expect(describeEnum(ExampleEnum.deferToChild), equals('deferToChild')); expect(describeEnum(ExampleEnum.deferToChild), equals('deferToChild'));
}); });
test('toHyphenedName test', () {
expect(camelCaseToHyphenatedName(''), equals(''));
expect(camelCaseToHyphenatedName('hello'), equals('hello'));
expect(camelCaseToHyphenatedName('Hello'), equals('hello'));
expect(camelCaseToHyphenatedName('HELLO'), equals('h-e-l-l-o'));
expect(camelCaseToHyphenatedName('deferToChild'), equals('defer-to-child'));
expect(camelCaseToHyphenatedName('DeferToChild'), equals('defer-to-child'));
expect(camelCaseToHyphenatedName('helloWorld'), equals('hello-world'));
});
test('string property test', () { test('string property test', () {
expect( expect(
new StringProperty('name', 'value', quoted: false).toString(), new StringProperty('name', 'value', quoted: false).toString(),
...@@ -1087,7 +1077,7 @@ void main() { ...@@ -1087,7 +1077,7 @@ void main() {
expect(deferToChild.level, equals(DiagnosticLevel.info)); expect(deferToChild.level, equals(DiagnosticLevel.info));
expect(deferToChild.value, equals(ExampleEnum.deferToChild)); expect(deferToChild.value, equals(ExampleEnum.deferToChild));
expect(deferToChild.toString(), equals('name: defer-to-child')); expect(deferToChild.toString(), equals('name: deferToChild'));
validatePropertyJsonSerialization(deferToChild); validatePropertyJsonSerialization(deferToChild);
expect(nullEnum.level, equals(DiagnosticLevel.info)); expect(nullEnum.level, equals(DiagnosticLevel.info));
......
...@@ -213,10 +213,10 @@ void main() { ...@@ -213,10 +213,10 @@ void main() {
test('AlignmentGeometry toString', () { test('AlignmentGeometry toString', () {
expect(const Alignment(1.0001, 2.0001).toString(), 'Alignment(1.0, 2.0)'); expect(const Alignment(1.0001, 2.0001).toString(), 'Alignment(1.0, 2.0)');
expect(const Alignment(0.0, 0.0).toString(), 'Alignment.center'); expect(const Alignment(0.0, 0.0).toString(), 'center');
expect(const Alignment(-1.0, 1.0).add(const AlignmentDirectional(1.0, 0.0)).toString(), 'Alignment.bottomLeft + AlignmentDirectional.centerEnd'); expect(const Alignment(-1.0, 1.0).add(const AlignmentDirectional(1.0, 0.0)).toString(), 'bottomLeft + AlignmentDirectional.centerEnd');
expect(const Alignment(0.0001, 0.0001).toString(), 'Alignment(0.0, 0.0)'); expect(const Alignment(0.0001, 0.0001).toString(), 'Alignment(0.0, 0.0)');
expect(const Alignment(0.0, 0.0).toString(), 'Alignment.center'); expect(const Alignment(0.0, 0.0).toString(), 'center');
expect(const AlignmentDirectional(0.0, 0.0).toString(), 'AlignmentDirectional.center'); expect(const AlignmentDirectional(0.0, 0.0).toString(), 'AlignmentDirectional.center');
expect(const Alignment(1.0, 1.0).add(const AlignmentDirectional(1.0, 1.0)).toString(), 'Alignment(1.0, 2.0) + AlignmentDirectional.centerEnd'); expect(const Alignment(1.0, 1.0).add(const AlignmentDirectional(1.0, 1.0)).toString(), 'Alignment(1.0, 2.0) + AlignmentDirectional.centerEnd');
}); });
......
...@@ -69,7 +69,7 @@ void main() { ...@@ -69,7 +69,7 @@ void main() {
], ],
).toString(), ).toString(),
equals( equals(
'LinearGradient(Alignment.topLeft, Alignment.bottomLeft, [Color(0x33333333), Color(0x66666666)], null, TileMode.clamp)', 'LinearGradient(topLeft, bottomLeft, [Color(0x33333333), Color(0x66666666)], null, TileMode.clamp)',
), ),
); );
}); });
......
...@@ -202,7 +202,7 @@ void main() { ...@@ -202,7 +202,7 @@ void main() {
' parentData: MISSING\n' ' parentData: MISSING\n'
' constraints: MISSING\n' ' constraints: MISSING\n'
' size: MISSING\n' ' size: MISSING\n'
' alignment: Alignment.center\n' ' alignment: center\n'
' textDirection: ltr\n'), ' textDirection: ltr\n'),
); );
}); });
......
...@@ -74,7 +74,7 @@ void main() { ...@@ -74,7 +74,7 @@ void main() {
' constraints: BoxConstraints(25.0<=w<=100.0, 25.0<=h<=100.0)\n' ' constraints: BoxConstraints(25.0<=w<=100.0, 25.0<=h<=100.0)\n'
' size: Size(25.0, 25.0)\n' ' size: Size(25.0, 25.0)\n'
' image: [10×10]\n' ' image: [10×10]\n'
' alignment: Alignment.center\n' ' alignment: center\n'
), ),
); );
......
...@@ -36,7 +36,7 @@ void main() { ...@@ -36,7 +36,7 @@ void main() {
' │ parentData: <none>\n' ' │ parentData: <none>\n'
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ size: Size(800.0, 600.0)\n' ' │ size: Size(800.0, 600.0)\n'
' │ alignment: Alignment.center\n' ' │ alignment: center\n'
' │ minWidth: 0.0\n' ' │ minWidth: 0.0\n'
' │ maxWidth: Infinity\n' ' │ maxWidth: Infinity\n'
' │ minHeight: 0.0\n' ' │ minHeight: 0.0\n'
...@@ -122,7 +122,7 @@ void main() { ...@@ -122,7 +122,7 @@ void main() {
' │ parentData: <none>\n' ' │ parentData: <none>\n'
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ size: Size(800.0, 600.0)\n' ' │ size: Size(800.0, 600.0)\n'
' │ alignment: Alignment.center\n' ' │ alignment: center\n'
' │ minWidth: 10.0\n' ' │ minWidth: 10.0\n'
' │ maxWidth: 500.0\n' ' │ maxWidth: 500.0\n'
' │ minHeight: 0.0\n' ' │ minHeight: 0.0\n'
...@@ -158,7 +158,7 @@ void main() { ...@@ -158,7 +158,7 @@ void main() {
' │ parentData: <none>\n' ' │ parentData: <none>\n'
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ size: Size(800.0, 600.0)\n' ' │ size: Size(800.0, 600.0)\n'
' │ alignment: Alignment.center\n' ' │ alignment: center\n'
' │ minWidth: 10.0\n' ' │ minWidth: 10.0\n'
' │ maxWidth: use parent maxWidth constraint\n' ' │ maxWidth: use parent maxWidth constraint\n'
' │ minHeight: use parent minHeight constraint\n' ' │ minHeight: use parent minHeight constraint\n'
......
...@@ -96,7 +96,7 @@ void main() { ...@@ -96,7 +96,7 @@ void main() {
' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n' ' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
' │ constraints: BoxConstraints(w=39.0, h=64.0)\n' ' │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
' │ size: Size(39.0, 64.0)\n' ' │ size: Size(39.0, 64.0)\n'
' │ alignment: Alignment.bottomRight\n' ' │ alignment: bottomRight\n'
' │ widthFactor: expand\n' ' │ widthFactor: expand\n'
' │ heightFactor: expand\n' ' │ heightFactor: expand\n'
' │\n' ' │\n'
...@@ -173,7 +173,7 @@ void main() { ...@@ -173,7 +173,7 @@ void main() {
' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n' ' │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
' │ constraints: BoxConstraints(w=39.0, h=64.0)\n' ' │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
' │ size: Size(39.0, 64.0)\n' ' │ size: Size(39.0, 64.0)\n'
' │ alignment: Alignment.bottomRight\n' ' │ alignment: bottomRight\n'
' │ widthFactor: expand\n' ' │ widthFactor: expand\n'
' │ heightFactor: expand\n' ' │ heightFactor: expand\n'
' │\n' ' │\n'
...@@ -281,7 +281,7 @@ void main() { ...@@ -281,7 +281,7 @@ void main() {
' │ layer: null\n' ' │ layer: null\n'
' │ semantics node: null\n' ' │ semantics node: null\n'
' │ size: Size(39.0, 64.0)\n' ' │ size: Size(39.0, 64.0)\n'
' │ alignment: Alignment.bottomRight\n' ' │ alignment: bottomRight\n'
' │ textDirection: null\n' ' │ textDirection: null\n'
' │ widthFactor: expand\n' ' │ widthFactor: expand\n'
' │ heightFactor: expand\n' ' │ heightFactor: expand\n'
...@@ -412,7 +412,7 @@ void main() { ...@@ -412,7 +412,7 @@ void main() {
' │ isBlockingSemanticsOfPreviouslyPaintedNodes: false\n' ' │ isBlockingSemanticsOfPreviouslyPaintedNodes: false\n'
' │ isSemanticBoundary: false\n' ' │ isSemanticBoundary: false\n'
' │ size: Size(39.0, 64.0)\n' ' │ size: Size(39.0, 64.0)\n'
' │ alignment: Alignment.bottomRight\n' ' │ alignment: bottomRight\n'
' │ textDirection: null\n' ' │ textDirection: null\n'
' │ widthFactor: expand\n' ' │ widthFactor: expand\n'
' │ heightFactor: expand\n' ' │ heightFactor: expand\n'
......
...@@ -42,7 +42,7 @@ void main() { ...@@ -42,7 +42,7 @@ void main() {
.where((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info)) .where((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode n) => n.toString()).toList(); .map((DiagnosticsNode n) => n.toString()).toList();
expect(description, <String>[ expect(description, <String>[
'alignment: Alignment.center', 'alignment: center',
'minWidth: 1.0', 'minWidth: 1.0',
'maxWidth: 2.0', 'maxWidth: 2.0',
'minHeight: 3.0', 'minHeight: 3.0',
......
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