mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 01:43:00 +00:00

The require('constants') module is currently undocumented and mashes together unrelated constants. This refactors the require('constants') in favor of distinct os.constants, fs.constants, and crypto.constants that are specific to the modules for which they are relevant. The next step is to document those within the specific modules. PR-URL: https://github.com/nodejs/node/pull/6534 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Robert Lindstaedt <robert.lindstaedt@gmail.com>
51 lines
1.8 KiB
JavaScript
51 lines
1.8 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
|
|
var fs = require('fs');
|
|
|
|
var O_APPEND = fs.constants.O_APPEND || 0;
|
|
var O_CREAT = fs.constants.O_CREAT || 0;
|
|
var O_EXCL = fs.constants.O_EXCL || 0;
|
|
var O_RDONLY = fs.constants.O_RDONLY || 0;
|
|
var O_RDWR = fs.constants.O_RDWR || 0;
|
|
var O_TRUNC = fs.constants.O_TRUNC || 0;
|
|
var O_WRONLY = fs.constants.O_WRONLY || 0;
|
|
|
|
assert.equal(fs._stringToFlags('r'), O_RDONLY);
|
|
assert.equal(fs._stringToFlags('r+'), O_RDWR);
|
|
assert.equal(fs._stringToFlags('w'), O_TRUNC | O_CREAT | O_WRONLY);
|
|
assert.equal(fs._stringToFlags('w+'), O_TRUNC | O_CREAT | O_RDWR);
|
|
assert.equal(fs._stringToFlags('a'), O_APPEND | O_CREAT | O_WRONLY);
|
|
assert.equal(fs._stringToFlags('a+'), O_APPEND | O_CREAT | O_RDWR);
|
|
|
|
assert.equal(fs._stringToFlags('wx'), O_TRUNC | O_CREAT | O_WRONLY | O_EXCL);
|
|
assert.equal(fs._stringToFlags('xw'), O_TRUNC | O_CREAT | O_WRONLY | O_EXCL);
|
|
assert.equal(fs._stringToFlags('wx+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL);
|
|
assert.equal(fs._stringToFlags('xw+'), O_TRUNC | O_CREAT | O_RDWR | O_EXCL);
|
|
assert.equal(fs._stringToFlags('ax'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL);
|
|
assert.equal(fs._stringToFlags('xa'), O_APPEND | O_CREAT | O_WRONLY | O_EXCL);
|
|
assert.equal(fs._stringToFlags('ax+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
|
|
assert.equal(fs._stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
|
|
|
|
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
|
|
.split(' ')
|
|
.forEach(function(flags) {
|
|
assert.throws(function() { fs._stringToFlags(flags); });
|
|
});
|
|
|
|
assert.throws(
|
|
() => fs._stringToFlags({}),
|
|
/Unknown file open flag: \[object Object\]/
|
|
);
|
|
|
|
assert.throws(
|
|
() => fs._stringToFlags(true),
|
|
/Unknown file open flag: true/
|
|
);
|
|
|
|
assert.throws(
|
|
() => fs._stringToFlags(null),
|
|
/Unknown file open flag: null/
|
|
);
|