2

I've grabbed some Scala CSV parsing code from here:

Use Scala parser combinator to parse CSV files

And then I tried to write a basic test for it:

assertEquals(List(List()), CSV.parse(""))

And this fails, with message:

java.lang.AssertionError: expected: scala.collection.immutable.$colon$colon but was: scala.collection.immutable.$colon$colon

Any ideas? The output from CSV.parse is an empty List[List[String]] but seems to have a different hashCode than List(Nil) or ListList[String] etc. I can't seem to find any way to compose a list which is equal to the output of CSV.parse("").

UPDATE:

Here is the failure using REPL:

scala> assertEquals(List(Nil), CSV.parse("")) 
java.lang.AssertionError: expected: scala.collection.immutable.$colon$colon<List(List())> but was: scala.collection.immutable.$colon$colon<List(List())>

1 Answer 1

2

Edited: I tried the parser you supplied in the link:

scala> CSV.parse("")
res7: List[List[String]] = List(List(""))

So apparently, it doesn't return a List with an empty List, but a List with a List with the empty string. So your test should fail.

Sign up to request clarification or add additional context in comments.

2 Comments

Good catch, thanks, thats it. What confused me is that println(List(List("")) and println(List[List[String]](Nil)) have the same output, so in my println calls, and in the JUnit failures I seemed to be getting the same values on either side.
I don't (yet) understand how/why the REPL shows different output than toString.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.