Skip to content

Conversation

@jacob314
Copy link
Contributor

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.
@jacob314 jacob314 requested a review from Hixie June 23, 2017 18:31
///
/// Specifically, this matcher checks that an object's
/// `toStringDeep(prefixLineOne, prefixOtherLines)`:
/// * Does not have leading or trailing whitespace.
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace

Copy link
Contributor Author

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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space before backtick

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not #00000 ?

Copy link
Contributor Author

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
Copy link
Contributor

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...

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma before which

Copy link
Contributor Author

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]
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe equalsIgnoringHashCodes?

Copy link
Contributor Author

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');
Copy link
Contributor

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.
Copy link
Contributor

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@Hixie
Copy link
Contributor

Hixie commented Jun 23, 2017

LGTM

@jacob314 jacob314 merged commit 8f07a58 into flutter:master Jun 23, 2017
@jacob314 jacob314 deleted the test_matchers branch June 23, 2017 21:07
gspencergoog pushed a commit to gspencergoog/flutter that referenced this pull request Jul 1, 2017
…r#10935)

* Add hasAGoodToStringDeep and equalsIgnoringHashCodes methods.

Methods simplify testing of toStringDeep calls and other cases where
methods return strings containing hash codes.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants