Conversation
src/dshould/package.d
Outdated
{ | ||
if (got != value) | ||
{ | ||
stringCmpError(gotString, valueString, false, file, line); |
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.
consider replacing false
with No.quoted
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
should.terminateChain; | ||
|
||
auto got = should.got(); | ||
const gotString = got.to!string.prettyprint; |
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.
Usually, we do .to!(string[])
in this case. Is .to!string
safe?
Or is it possible, that the string representation of one array element contains an unmatched parenthesis that results in an unwanted parse tree of the 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.
In the case of an unmatched parenthesis, the parse tree will fail to be constructed and we will fall back to ordinary string comparison.
src/dshould/stringcmp.d
Outdated
should.addWord!"equal".stringCmp(expected, file, line); | ||
if (got != expected) | ||
{ | ||
stringCmpError(got, expected, true, file, line); |
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.
Yes.quoted
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
src/dshould/prettyprint.d
Outdated
|
||
/** | ||
* This function takes the input text and returns a pretty-printed, multiline, indented version. | ||
* It assumes that the input text is the output of toString and forms a valid comma separated paren tree. |
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.
Add hint like "the output of a structured toString"?
Our toString style is idiosyncratic and this function best suits this style:
- more machine-readable
__repr__
than human-readable__str__
- one-liner (for better
grep
results) rather than preformatted
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.
example added
src/dshould/prettyprint.d
Outdated
|
||
prettyprint("Foo()").should.equal("Foo()"); | ||
prettyprint("Foo(Bar(Baz()), Baq())", 16).should.equal( | ||
"Foo( |
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.
Consider using correct code indentation and fixing it with outdent
.
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
src/dshould/prettyprint.d
Outdated
return; | ||
} | ||
|
||
result ~= tree.prefix.stripLeft; |
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.
Move this up before the if
?
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
src/dshould/prettyprint.d
Outdated
result ~= ","; | ||
} | ||
result ~= "\n"; | ||
(level + 1).iota.each!((_) { result ~= indent; }); |
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 repeat
? Comment?
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.
repeat
and join
force an extra allocation.
src/dshould/prettyprint.d
Outdated
Appender!string result; | ||
|
||
// skip prefix so caller can decide whether or not to strip | ||
void walkOneLine(const Tree tree) |
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.
Newspaper style: put this below walk
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.
Nested functions aren't reorderable. (And can't be, because they close over scopes.)
src/dshould/prettyprint.d
Outdated
tree.children.enumerate.each!((index, child) { | ||
if (index > 0) | ||
{ | ||
result ~= ","; |
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.
Isn't it ", "
- with space after comma?
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.
Spacing is as in the original string.
src/dshould/prettyprint.d
Outdated
result ~= tree.parenType.get.closing; | ||
} | ||
|
||
void walk(size_t level, const Tree tree) |
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.
"walk" suggests how the function is implemented - "traverse" would be a similar bad name, that's only appropriate for a template where the what is a template parameter.
A specific function, however, should better be named for the *what and not for the how: something like render
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.
renamed
db5eb36
to
84ab585
Compare
Moved to an external package. |
112f29d
to
ced2800
Compare
@linkrope ping