-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add hasAGoodToStringDeep and normalizeHashCodesEquals methods. #10935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Methods simplify testing of toStringDeep calls and other cases where methods return strings containing hash codes.
| /// | ||
| /// Specifically, this matcher checks that an object's | ||
| /// `toStringDeep(prefixLineOne, prefixOtherLines)`: | ||
| /// * Does not have leading or trailing whitespace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you need a blank line before the first line with a bullet for markdown to handle this well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| /// * The last line has characters other than tree connector characters and | ||
| /// whitespace. For example: the line ` │ ║ ╎` has only tree connector | ||
| /// characters and whitespace. | ||
| /// * Does not contain lines with trailing white. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| /// characters and whitespace. | ||
| /// * Does not contain lines with trailing white. | ||
| /// * Has multiple lines. | ||
| /// * The first line starts with`prefixLineOne` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before backtick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| /// Asserts that two [String]s are equal after normalizing likely hash codes. | ||
| /// | ||
| /// A `#` followed by 5 hexadecimal digits is assumed to be a short hash code | ||
| /// and is normalized to #000. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not #00000 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Purely inertia... When this was normalizing ~9 digit codes truncating to 3 digits made more sense. switched to #00000
This will make some word wrap cases less confusing as previously word wraps weren't occurring where it would make sense due to the truncation.
| /// | ||
| /// See Also: | ||
| /// | ||
| /// * [describeIdentity] method that generates short descriptions of objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flutter style would have this be * [describeIdentity], a method that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| /// with ids that match the pattern #[0-9a-f]{5}. | ||
| /// * [shortHash] method that generates a 5 character long hexadecimal [String] | ||
| /// based on [Object.hashCode]. | ||
| /// * [TreeDiagnosticsMixin.toStringDeep] which returns a [String] typically |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comma before which
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switched all cases to ", a method that"
| /// | ||
| /// * [describeIdentity] method that generates short descriptions of objects | ||
| /// with ids that match the pattern #[0-9a-f]{5}. | ||
| /// * [shortHash] method that generates a 5 character long hexadecimal [String] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
| /// based on [Object.hashCode]. | ||
| /// * [TreeDiagnosticsMixin.toStringDeep] which returns a [String] typically | ||
| /// containing multiple hash codes. | ||
| Matcher normalizeHashCodesEquals(String value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe equalsIgnoringHashCodes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. Done.
| static final Object _mismatchedValueKey = new Object(); | ||
|
|
||
| static String _normalize(String s) { | ||
| return s.replaceAll(new RegExp(r'#[0-9a-f]{5}'), '#000'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe r'#[0-9a-f]{5}\b' so that #123456 doesn't get treated as ok?
| } | ||
| } | ||
|
|
||
| /// Returns `true` if [c] represents a whitespace code unit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put all these inside the class as static methods so that it's all wrapped up together
| /// Example vertical tree connector characters: `│ ║ ╎`. | ||
| /// The last line of a text tree contains only vertical tree connector | ||
| /// characters indicates a poorly formatted tree. | ||
| bool _isAllTreeConnectorCharacters(String str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid abbreviations in variables names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. switched to line. Are you ok with the use of c for character within this method body and for the previous method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If done sparingly and for the main or only argument of a short and very generic method, or in math expressions, single-character variable names are probably ok.
As a general rule I would avoid them, though, unless they actively help readability. So for example, they often help readability when you're expressing physics equations, and i is probably not less readable than index when looping over something.
…r#10935) * Add hasAGoodToStringDeep and equalsIgnoringHashCodes methods. Methods simplify testing of toStringDeep calls and other cases where methods return strings containing hash codes.
Methods simplify testing of toStringDeep calls and other cases where
methods return strings containing hash codes.