Created
January 30, 2011 03:46
-
-
Save JesseKPhillips/802502 to your computer and use it in GitHub Desktop.
Unittests for csvRange
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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