blob: 9a71723d5b5b4fe09be496585fba5fe09495400e [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var fileSyncCmp = require('../');
4
5var assert = require('assert');
6var fs = require('fs');
7
8var tmp = require('tmp');
9tmp.setGracefulCleanup();
10
11var Q = require('q');
12
13var fsWrite = Q.nfbind(fs.write);
14var tmpFile = Q.nfbind(tmp.file);
15
16function write (fd, buf) {
17 return fsWrite(fd, buf, 0, buf.length, null);
18}
19
20
21describe('equalFiles', function () {
22 var pathA, pathB;
23 var fdA, fdB;
24
25 beforeEach(function () {
26 return Q.all([tmpFile(), tmpFile()]).spread(function (a, b) {
27 pathA = a[0];
28 pathB = b[0];
29 fdA = a[1];
30 fdB = b[1];
31 });
32 });
33
34 it('should handle empty files', function () {
35 assert(fileSyncCmp.equalFiles(pathA, pathB));
36 });
37
38 it('should handle equal content', function () {
39 var buf = new Buffer('File content\n');
40 var writes = [write(fdA, buf), write(fdB, buf)];
41 return Q.all(writes).then(function () {
42 assert(fileSyncCmp.equalFiles(pathA, pathB));
43 });
44 });
45
46 it('should handle non-equal content', function () {
47 var bufA = new Buffer('Some text\n');
48 var bufB = new Buffer('Other text\n');
49 var writes = [write(fdA, bufA), write(fdB, bufB)];
50 return Q.all(writes).then(function () {
51 assert(!fileSyncCmp.equalFiles(pathA, pathB));
52 });
53 });
54});