Skip to content

JUnit migration #7

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 4 commits into from
Oct 28, 2013
Merged

JUnit migration #7

merged 4 commits into from
Oct 28, 2013

Conversation

gkossakowski
Copy link
Contributor

I've migrated more than half of all parser-combinators tests to JUnit.

Apart from 0e40547, the whole migration was straightforward because tests were already written in JUnit style.

I'm submitting progress on JUnit migration before I run out of steam.

@gkossakowski
Copy link
Contributor Author

Review by @adriaanm.

Most of the migration is straightforward. One exception is packrat3
(migrated to `test3` method). I simplified returned result by getting
rid of useless Unit by changing this rule:

  repMany1(a,b) ~ not(b)

into this rule:

  repMany1(a,b) <~ not(b)

Also, I made all rules to be type safe.

When constructing expected results, I decided to use scala.Symbol that
allows us to use a bit more concise syntax for construction of one
character strings. See `threeLists` method for details.
@adriaanm
Copy link
Contributor

LGTM -- will be a lot easier to add more tests along these lines!

parseFailure("3start", 1)
parseFailure("-start", 1)
parseFailure("with-s", 5)
parseFailure("we♥scala", 3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to pass the enoding? I'm afraid relying on the default encoding can break tests on other platforms.

Copy link
Member

Choose a reason for hiding this comment

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

You could use a unicode escape in the source here.

The unicode strings has been escaped using

  native2ascii -encoding utf8 a.txt b.txt

command.
Extract common code that parses strings and extracts results
into helper methods.

In test1 and test2 I named the helper method `check` because it checks
if expression-evaluating parser calculates the correct result.

In test3, we are interested in parsing result (Success or Failure) thus
helper methods are named `assertSuccess` and `assertFailure`.
@gkossakowski
Copy link
Contributor Author

@dragos: non-ascii characters has been escaped in 9828c47.

@retronym: code duplication has been reduced in 9402f2a.

@dragos
Copy link
Contributor

dragos commented Oct 28, 2013

@gkossakowski It's good, but I think it's valuable to test non-ASCII characters as well, (iff parser combinators support different encodings, of course). Anyway, you addressed my initial comment (platform-dependent test), so LGTM.

@retronym
Copy link
Member

Parser combinators will still be tested with non-ASCII characters as the Scala scanner will decode the unicode escapes.

@retronym
Copy link
Member

LGTM

@retronym
Copy link
Member

I manually verified that tests pass under:

sbt -J-Dfile.encoding=cp1252 test
sbt -J-Dfile.encoding=UTF-8 test

@retronym
Copy link
Member

Merging, look forward to the rest of the tests!

retronym added a commit that referenced this pull request Oct 28, 2013
@retronym retronym merged commit d2fcadb into scala:master Oct 28, 2013
@gkossakowski
Copy link
Contributor Author

@retronym: haha! Good point! :-)

I usually get it right when I write tests myself but I must admit migrating somebody's else code in such quantity is rather thankless job.

@gkossakowski gkossakowski deleted the junit-migration branch October 28, 2013 11:23
@retronym
Copy link
Member

I suppose this way saves on compile time :)

@dragos
Copy link
Contributor

dragos commented Oct 28, 2013

@retronym I don't think it's the same thing, what I was aiming for is to test encoding support in parser combinators. I agree it's not straight-forward, nor a blocker for this PR.

@retronym
Copy link
Member

but I must admit migrating somebody's else code in such quantity is rather thankless job.

Indeed the studies have shown that being a Test Migrator is far inferior to being Harvey Weinstein, or God when it comes to gratitude. 😦

But let me be the one to say it: thank you!

@adriaanm
Copy link
Contributor

Hear, hear -- thanks, @gkossakowski!

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.

4 participants