require File.join(File.dirname(__FILE__), "test_helper") require 'lib/eeml/csv_parser_v2.rb' class TestCsvParserV2 < Test::Unit::TestCase test "should raise exception if line breaks have dodgy characters" do csv = "20,305\\n30,1305" exception = assert_raises CsvEncodingError do CsvParserV2.make_environment_from_csv(csv) end assert_equal "CSV is invalid. Double check you are properly encoding line breaks.", exception.message end test "should raise exception if too many fields" do csv = "20,54,305\n30,1305" exception = assert_raises CsvEncodingError do CsvParserV2.make_environment_from_csv(csv) end assert_equal "CSV is invalid. Incorrect number of fields.", exception.message end test "should parse and return Environment object with datastreams" do csv = "20,10\n5,6" environment = CsvParserV2.make_environment_from_csv(csv) assert_equal 2, environment.datastreams.length assert_equal "20", environment.datastreams.first.identifier assert_equal "10", environment.datastreams.first.value assert_equal "5", environment.datastreams.last.identifier assert_equal "6", environment.datastreams.last.value end end