Skip to content

[PlaygroundLogger] Use prefix and suffix when getting the first and last n children for structured log entries. #26

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

Merged
merged 2 commits into from
Jul 6, 2018

Conversation

cwakamo
Copy link
Member

@cwakamo cwakamo commented Jul 6, 2018

Offsetting indices only works for collections which implement BidirectionalCollection, while suffix(_:) is available for all collections.
This prevent crashes when e.g. generating a LogEntry for instances of Set.

This addresses rdar://problem/39791397.

@cwakamo
Copy link
Member Author

cwakamo commented Jul 6, 2018

@swift-ci Please test

Copy link

@griotspeak griotspeak left a comment

Choose a reason for hiding this comment

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

It seems fine overall. The two comments aren't blockers.

}

XCTAssertEqual(name, "set")
XCTAssertEqual(totalChildrenCount, 1000)

Choose a reason for hiding this comment

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

How do we expect 1000 and 101 here. (and 81st item being a gap)
I searched for nilIUO and the only spot it showed up wasn't very clarifying.

Copy link
Member Author

Choose a reason for hiding this comment

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

We expect 1000 here because we create a set with 1000 elements above, and that's what we log. (I'm not sure where nilIUO is coming into play in this test because it's the variable for the previous test; set is what's being logged here.)

101 is a bit of a magic number because it's what the default logging policy would create. I'll add a comment to explain why I got that.

XCTAssertEqual(children.count, 101)

for (index, childEntry) in children.enumerated() {
if index == 80 {

Choose a reason for hiding this comment

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

Did you consider switching over the index and the entry instead of these guards and ifs?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did, but since there was only one case to handle specially (index == 80), it felt like it made more sense to just do an if/else. (And it's easier for me to reason about childEntry and the assertions I'm making about it by using a guard to unwrap it instead of trying to unwrap it in a switch.

cwakamo added 2 commits July 6, 2018 10:50
Offsetting indices only works for collections which implement `BidirectionalCollection`, while `suffix(_:)` is available for all collections.
This prevent crashes when e.g. generating a `LogEntry` for instances of `Set`.

This addresses <rdar://problem/39791397>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants