-
Notifications
You must be signed in to change notification settings - Fork 21
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
add tuple support #69
Conversation
# Conflicts: # Sources/Core/Formatter/MultilineFormatter.swift
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.
Good works!!
|
||
func testTupleString() { | ||
assert(to: formatter.tupleString).expect([ | ||
when([], then: #"()"#), |
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.
Good 👍
Apply suggestions from code review.
Codecov Report
@@ Coverage Diff @@
## master #69 +/- ##
==========================================
+ Coverage 74.84% 77.53% +2.69%
==========================================
Files 8 8
Lines 318 365 +47
==========================================
+ Hits 238 283 +45
- Misses 80 82 +2
Continue to review full report at Codecov.
|
thanks to Yusuke, I get the image that we can show the merit to support tuple type. A tuple can hold multi type element, which is distinct from Array.
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.
Good works!!
@@ -66,6 +66,35 @@ class MultilineFormatterTests: XCTestCase { | |||
] | |||
""") | |||
} | |||
|
|||
func testTupleString() { | |||
let tupleElements: [(String?, 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.
What time first argument of tuple is nil
?
(Please write to test that passed to nil
if possible)
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 can not find a situation in which the label is nil
.
Example
the tuple is ()
a formatter receives []
.
no label, one element
the tuple is transformed to the inner element instance.
(#""one""#)
becomes "one"
.
no label element and labeled element
(#""one""#, second: 2)
becomes [(".0", "\"\"one\"\""), ("second", "2")]
.
// if the labels of tuples are not specificated, they are like ".1" (not nil). | ||
// Using "." as the first charactor of the label of tuple is prohibited. | ||
let labelValuePairs: [String] = elements.map { label, value in | ||
if let label = label, label.first != "." { |
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 think a better way would be this judge move to Pretty.swift
.
For example:
// Pretty.swift
case .tuple:
let elements: [(String?, String)] = mirror.children.map {
var labelOrNil: String? = nil
if let label = $0.label, label.first != "." {
labelOrNil = label
}
return (label: labelOrNil, value: _string($0.value))
}
return formatter.tupleString(elements: elements)
// Here
let labelValuePairs: [String] = elements.map { label, value in
if let label = label {
...
Formatter should be concentrate styling therefore should not judge property of data.
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.
Thank you for a comment!
This suggestion is so reasonable, I adopt it in b4676ce.
followed @YusukeHosonuma's suggestion Co-Authored-By: Yusuke Hosonuma <tobi462@gmail.com>
along with it, modify test cases of single line formatter because formatters receive proper labels.
Co-Authored-By: Yusuke Hosonuma <tobi462@gmail.com>
# Conflicts: # Sources/Core/Pretty.swift # Tests/Core/PrettyTests.swift
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.
Thank you for your polite works ❤️
Please check last suggestion comment from me :)
That's all!!
Co-Authored-By: Yusuke Hosonuma <tobi462@gmail.com>
Support tuple.
this solves #34.