开发者

List equality using parser combinators

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())>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜