mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:32:15 +00:00

A number of test files use IIFEs to separate distinct tests from each other in the same file. The project has been moving toward using block scopes and let/const in favor of IIFEs. This commit moves IIFE tests to block scopes. Some additional cleanup such as use of strictEqual() and common.mustCall() is also included. PR-URL: https://github.com/nodejs/node/pull/7694 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
27 lines
736 B
JavaScript
27 lines
736 B
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
var fs = require('fs');
|
|
|
|
var filename = common.tmpDir + '/truncate-file.txt';
|
|
|
|
common.refreshTmpDir();
|
|
|
|
// Synchronous test.
|
|
{
|
|
fs.writeFileSync(filename, '0123456789');
|
|
assert.strictEqual(fs.readFileSync(filename).toString(), '0123456789');
|
|
fs.truncateSync(filename, 5);
|
|
assert.strictEqual(fs.readFileSync(filename).toString(), '01234');
|
|
}
|
|
|
|
// Asynchronous test.
|
|
{
|
|
fs.writeFileSync(filename, '0123456789');
|
|
assert.strictEqual(fs.readFileSync(filename).toString(), '0123456789');
|
|
fs.truncate(filename, 5, common.mustCall(function(err) {
|
|
assert.ifError(err);
|
|
assert.strictEqual(fs.readFileSync(filename).toString(), '01234');
|
|
}));
|
|
}
|