| [e4c61dd] | 1 | #!/usr/bin/env node
|
|---|
| 2 |
|
|---|
| 3 | var fs = require("fs"),
|
|---|
| 4 | queue = require("d3-queue").queue,
|
|---|
| 5 | rw = require("../");
|
|---|
| 6 |
|
|---|
| 7 | var code = 0;
|
|---|
| 8 |
|
|---|
| 9 | queue(1)
|
|---|
| 10 | .defer(testRead, "utf8", "gréén\n")
|
|---|
| 11 | .defer(testRead, {encoding: "utf8"}, "gréén\n")
|
|---|
| 12 | .defer(testRead, "ascii", "grC)C)n\n")
|
|---|
| 13 | .defer(testRead, {encoding: "ascii"}, "grC)C)n\n")
|
|---|
| 14 | .defer(testWrite, "utf8", "gréén\n")
|
|---|
| 15 | .defer(testWrite, {encoding: "utf8"}, "gréén\n")
|
|---|
| 16 | .defer(testWrite, "ascii", "gr��n\n")
|
|---|
| 17 | .defer(testWrite, {encoding: "ascii"}, "gr��n\n")
|
|---|
| 18 | .await(done);
|
|---|
| 19 |
|
|---|
| 20 | function testRead(options, expected, callback) {
|
|---|
| 21 | rw.readFile("test/utf8.txt", options, function(error, actual) {
|
|---|
| 22 | if (error) return void callback(error);
|
|---|
| 23 | if (actual !== expected) console.warn(actual + " !== " + expected), code = 1;
|
|---|
| 24 | callback(null);
|
|---|
| 25 | });
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | function testWrite(options, expected, callback) {
|
|---|
| 29 | rw.writeFile("test/encoding-async.out", "gréén\n", options, function(error) {
|
|---|
| 30 | if (error) return void callback(error);
|
|---|
| 31 | fs.readFile("test/encoding-async.out", "utf8", function(error, actual) {
|
|---|
| 32 | if (error) return void callback(error);
|
|---|
| 33 | if (actual !== expected) console.warn(actual + " !== " + expected), code = 1;
|
|---|
| 34 | callback(null);
|
|---|
| 35 | });
|
|---|
| 36 | });
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | function done(error) {
|
|---|
| 40 | if (error) throw error;
|
|---|
| 41 | process.exit(code);
|
|---|
| 42 | }
|
|---|