Skip to content

convert docstring examples to unittests [part 2]#4044

Merged
quickfur merged 1 commit intodlang:masterfrom
wilzbach:examples_to_unittest2
Mar 9, 2016
Merged

convert docstring examples to unittests [part 2]#4044
quickfur merged 1 commit intodlang:masterfrom
wilzbach:examples_to_unittest2

Conversation

@wilzbach
Copy link
Contributor

@wilzbach wilzbach commented Mar 3, 2016

in reference to #4042 more converted examples.

@wilzbach
Copy link
Contributor Author

wilzbach commented Mar 4, 2016

has anyone an idea why the auto tester is failing for dmd?

@wilzbach wilzbach force-pushed the examples_to_unittest2 branch from 3d04c3d to a098957 Compare March 4, 2016 01:32
@wilzbach
Copy link
Contributor Author

wilzbach commented Mar 4, 2016

update: it was most likely due to the change in uni.d -> moved to #4049

@wilzbach
Copy link
Contributor Author

wilzbach commented Mar 8, 2016

I think this is also a trivial addition - it just moves unittests from the docs to code :)

sorted);
}

///
Copy link
Contributor

Choose a reason for hiding this comment

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

The paragraph below the example references the example, but this change moves the example below the text. I think in these cases we need to either leave the example in the doc comment, or restructure the doc text to work with the new layout.

edit:

Historically, before documented unit tests were introduced, we've also left the example in the comment but duplicated the code in a test to make sure it works (and keeps working with future changes). Maybe this approach is still an alternative when examples can't appear at the end of the doc entry. The big disadvantage of this is that it's easy to accidentally edit one but not the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about moving the two explanation lines as comments into the unittest?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, you can also put text in the comment for the unit test and it will appear before the example code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As this edit might be a bit controversial I moved it over to #4066, so it doesn't block this PR ;-)

@JakobOvrum
Copy link
Contributor

As a general rule, an important thing to keep in mind when enacting this kind of change is that the documentation text still makes sense with the new ordering of sections.

@wilzbach wilzbach force-pushed the examples_to_unittest2 branch 2 times, most recently from a09b04f to 78aac0d Compare March 8, 2016 12:49
std/functional.d Outdated
unittest
{
int fun(int a, int b) { return a + b; }
alias partial!(fun, 5) fun5;
Copy link
Member

Choose a reason for hiding this comment

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

Should use new alias syntax alias x = y; instead of old syntax alias y x.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh didn't know that - just copied the old one.
Thanks for the info - updated ;-)

@quickfur
Copy link
Member

quickfur commented Mar 9, 2016

The rest of the changes look OK.

@wilzbach wilzbach force-pushed the examples_to_unittest2 branch from 78aac0d to 66e0dc3 Compare March 9, 2016 19:22
@quickfur
Copy link
Member

quickfur commented Mar 9, 2016

LGTM, thanks!

@quickfur
Copy link
Member

quickfur commented Mar 9, 2016

Auto-merge toggled on

quickfur pushed a commit that referenced this pull request Mar 9, 2016
convert docstring examples to unittests [part 2]
@quickfur quickfur merged commit 04654c0 into dlang:master Mar 9, 2016
@wilzbach wilzbach deleted the examples_to_unittest2 branch March 10, 2016 11:30
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.

3 participants