Skip to content

Instantly share code, notes, and snippets.

@JesseKPhillips
Created January 30, 2011 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JesseKPhillips/802502 to your computer and use it in GitHub Desktop.
Save JesseKPhillips/802502 to your computer and use it in GitHub Desktop.
Unittests for csvRange
import csvRange;
import std.stdio;
void main() {
}
unittest {
string str = "Hello,65,63.63\nWorld,123,3673.562";
auto a = csvFile(str, ',');
auto line = a.front;
assert(line.front == "Hello");
line.popFront();
assert(line.front == "65");
line.popFront();
assert(line.front == "63.63");
a.popFront();
line = a.front;
assert(line.front == "World");
line.popFront();
assert(line.front == "123");
line.popFront();
assert(line.front == "3673.562");
}
// Test quoted tokens
unittest {
string str = `Hello,World,"Hi ""There""","",` ~ "\"It is\nme\"\nNot here";
auto a = csvFile(str, ',');
auto line = a.front;
assert(line.front == "Hello");
line.popFront();
assert(line.front == "World");
line.popFront();
assert(line.front == "Hi \"There\"");
line.popFront();
assert(line.front == "");
line.popFront();
assert(line.front == "It is\nme");
}
// Test empty data is pulled at start of record.
unittest {
string str = ",Hello";
auto a = csvFile(str, ',');
auto line = a.front;
assert(line.front == "");
line.popFront();
assert(line.front == "Hello");
}
// Test empty data is pulled at end of record.
unittest {
string str = "Hello,";
auto a = csvFile(str, ',');
auto line = a.front;
assert(line.front == "Hello");
line.popFront();
assert(line.front == "");
}
// Test Windows CSV files
unittest {
string str = `Hello,World,"Hi ""There""","",` ~ "\"It is\r\nme\"\r\nNot here";
auto a = csvFile(str, ',');
auto line = a.front;
assert(line.front == "Hello");
line.popFront();
assert(line.front == "World");
line.popFront();
assert(line.front == "Hi \"There\"");
line.popFront();
assert(line.front == "");
line.popFront();
assert(line.front == "It is\r\nme");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment