source: node_modules/rw/test/encoding-async

Last change on this file was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#!/usr/bin/env node
2
3var fs = require("fs"),
4 queue = require("d3-queue").queue,
5 rw = require("../");
6
7var code = 0;
8
9queue(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
20function 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
28function 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
39function done(error) {
40 if (error) throw error;
41 process.exit(code);
42}
Note: See TracBrowser for help on using the repository browser.