Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

implemented parsing in scala and removed the opencsv dependency

  • Loading branch information...
commit d4d38c496d7bcb49c3328e6aead4841fdf3b4de6 1 parent 0c1d4e5
Mirko Nasato authored April 15, 2012
46  src/test/scala/com/encodedknowledge/traversable/csv/CSVDataTest.scala
... ...
@@ -0,0 +1,46 @@
  1
+package com.encodedknowledge.traversable.csv
  2
+
  3
+//import org.junit.runner.RunWith
  4
+import org.scalatest.FunSuite
  5
+import org.scalatest.junit.JUnitRunner
  6
+import org.scalatest.matchers.ShouldMatchers
  7
+
  8
+//@RunWith(classOf[JUnitRunner])
  9
+class CSVDataTest extends FunSuite with ShouldMatchers {
  10
+
  11
+  test("read comma-separated") {
  12
+    val data = new CSVData("src/test/resources/test.csv")
  13
+    val rows = data.toList
  14
+    rows.size should equal(5)
  15
+    rows(0) should equal(Array[String]("1", "one", "plain"))
  16
+    rows(2)(2) should equal("quote: \" escaped")
  17
+    rows(3)(2) should equal("escape: \\ escaped")
  18
+    rows(4) should equal(Array[String]("5", "five", "plain"))
  19
+  }
  20
+
  21
+  test("read tab-separated") {
  22
+    val data = new CSVData("src/test/resources/test.tsv", separator = '\t', quote = '\'')
  23
+    val rows = data.toList
  24
+    rows.size should equal(5)
  25
+    rows(0) should equal(Array[String]("1", "one", "plain"))
  26
+    rows(2)(2) should equal("quote: ' escaped")
  27
+    rows(3)(2) should equal("escape: \\ escaped")
  28
+    rows(4) should equal(Array[String]("5", "five", "plain"))
  29
+  }
  30
+
  31
+  test("skip first line") {
  32
+    val data = new CSVData("src/test/resources/test.csv", skipFirst = true)
  33
+    val rows = data.toList
  34
+    rows.size should equal(4)
  35
+    rows(0)(0) should equal("2")
  36
+  }
  37
+
  38
+  test("to map") {
  39
+    val data = new CSVData("src/test/resources/test.csv")
  40
+    val numbers = data.toMap(row => row(1) -> row(0).toInt)
  41
+    numbers.size should equal(5)
  42
+    numbers("one") should equal(1)
  43
+    numbers("five") should equal(5)
  44
+  }
  45
+
  46
+}

0 notes on commit d4d38c4

Please sign in to comment.
Something went wrong with that request. Please try again.