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())>
Community
  • 1
  • 1
waterlooalex
  • 13,642
  • 16
  • 78
  • 99

1 Answers1

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.

paradigmatic
  • 40,153
  • 18
  • 88
  • 147
  • 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. – waterlooalex Jul 14 '11 at 20:12
  • I don't (yet) understand how/why the REPL shows different output than toString. – waterlooalex Jul 14 '11 at 20:18