-
Notifications
You must be signed in to change notification settings - Fork 965
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
Handling of null, blank and untrimmed collection items #566
Conversation
[Fact] | ||
public void HumanizeHandlesNullItemsWithoutAnException() | ||
{ | ||
new object[] { null, null }.Humanize(); |
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.
Please add check for expected output, and/or that exception is not thrown.
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.
Okay. How do I add a check that an exception is not thrown, other than exactly what I have there?
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.
Assert.DoesNotThrow(()=>...)
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.
Sure, but I find DoesNotThrow
redundant and not in a nice way. The whole premise of its existence flies in the face of how the language itself works.
It's on track to be removed from xunit, and I have to say I agree with the sentiments there: xunit/xunit#188
Other projects like dotnet/roslyn have been removing all usages of DoesNotThrow
. I'd hate to perpetuate it. Do I have to?
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.
Ok. Record.Exception instead of Asser.DoesNotThrow then. I don't care how
it will be implemented, but what I care - is explicitly, that this
particular call to Humanize does not throw
On Tue, 28 Jun 2016 at 9:39 AM, Joseph Musser notifications@github.com
wrote:
In src/Humanizer.Tests.Shared/CollectionHumanizeTests.cs
#566 (comment):@@ -87,5 +88,58 @@ public void HumanizeUsesObjectFormatterWhenSeparatorIsProvided()
var humanized = _testCollection.Humanize(sc => string.Format("SomeObject #{0} - {1}", sc.SomeInt, sc.SomeString), "or");
Assert.Equal("SomeObject #1 - One, SomeObject #2 - Two, or SomeObject #3 - Three", humanized);
}
+
[Fact]
public void HumanizeHandlesNullItemsWithoutAnException()
{
new object[] { null, null }.Humanize();
Sure, but I find DoesNotThrow redundant and not in a nice way. The whole
premise of its existence flies in the face of how the language itself works.It's on track to be removed from xunit, and I have to say I agree with the
sentiments there: xunit/xunit#188
xunit/xunit#188Other projects like dotnet/roslyn have been removing all usages of
DoesNotThrow. I'd hate to perpetuate it. Do I have to?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Humanizr/Humanizer/pull/566/files/7abd8e2ffe497ad51598278bd8b0c8130f928512#r68661345,
or mute the thread
https://github.com/notifications/unsubscribe/AAI1l8HPS53NAPeZ972HBsFt75gKvNeXks5qQEMegaJpZM4I7H4x
.
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.
After reading the xUnit.net's issue, I am in favor to Record.Exception
too. Nice reading by the way :)
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 don't believe either addition improves readability- after all, it's a single line in a method named WithoutAnException
and we all know how the language works- if anything it's subtly misleading, as though errors outside the DoesNotThrow(() => )
/ Record.Exception(() => ) == null
ceremony wouldn't be reported, but I'm happy to do whatever matches the project's style.
I prefer overloads |
I was hoping to keep the API simpler and self-documenting, but I understand the binary compat issue would force that to be a major version update. |
7abd8e2
to
766efb2
Compare
Converted optional params to overloads for minor-version release. Rebased so that you can see, no red in the API. |
Addition of methods to interface is a breaking change (actually any change to an interface is a breaking change): https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/breaking-change-rules.md |
Ah. What are our options then? Extended interface? What would I name it? The extended interface could have optional params. |
If 3.0, would you like to see |
Hey while we're here, I wonder if anyone has an idea for this? Half the time when I use enumerable.Humanize(), I want to use a verb that needs to be pluralized correctly. (Does/do, is/are, isn't/aren't, exists/exist, etc.) It's concise to be able to pass a filtered LINQ query to .Humanize(), but not when you have to repeat the query, check if there are fewer or more than one item, and pick the right verb number. Right now the code look like this: var buffer = enumerable.ToList();
$"{buffer.Humanize()} {(buffer.Count == 1 ? "is" : "are")} ..." Could there be a more idiomatic way of humanizing "{collection} {verb}", similar to |
@jnm2 It will be a lot of work for english, but good luck for i18n. Also you should move this to a new issue. :) |
Checking in here, is this ready? I'd be great to get 2.1 out soon. |
I'm not too keen on releasing a |
Alternatives:
I feel the same about 3.0. I'm thinking |
I'm going to rebase again but remove all public API changes so option 1 is ready if that's what you want to go ahead with for 2.1. This doesn't paint us into a corner, unless someone wants to include redundant commas and bad whitespace which I doubt. |
Done, rebased on newest from dev. |
@hazzik lmk if this PR looks good to merge in for 2.1 and we can add an issue for 3.0 to refactor the interfaces. |
Fixes #555. I'm guessing PublicApiApprovalTest.approve_public_api.approved.txt should be reviewed; are optional params okay or should they be overloads?