UNPKG

1.63 kBJavaScriptView Raw
1'use strict';
2
3var chai = require('chai');
4
5
6/** @type {boolean} */
7chai.Assertion.includeStack = true;
8
9
10/**
11 * Chai's assert function configured to include stacks on failure.
12 * @type {function}
13 */
14exports.assert = chai.assert;
15
16
17var constants = process.binding('constants');
18
19
20/**
21 * Convert a string to flags for fs.open.
22 * @param {string} str String.
23 * @return {number} Flags.
24 */
25exports.flags = function(str) {
26 switch (str) {
27 case 'r' :
28 return constants.O_RDONLY;
29 case 'rs' :
30 return constants.O_RDONLY | constants.O_SYNC;
31 case 'r+' :
32 return constants.O_RDWR;
33 case 'rs+' :
34 return constants.O_RDWR | constants.O_SYNC;
35
36 case 'w' :
37 return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY;
38 case 'wx' : // fall through
39 case 'xw' :
40 return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY |
41 constants.O_EXCL;
42
43 case 'w+' :
44 return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR;
45 case 'wx+': // fall through
46 case 'xw+':
47 return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR |
48 constants.O_EXCL;
49
50 case 'a' :
51 return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY;
52 case 'ax' : // fall through
53 case 'xa' :
54 return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY |
55 constants.O_EXCL;
56
57 case 'a+' :
58 return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR;
59 case 'ax+': // fall through
60 case 'xa+':
61 return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR |
62 constants.O_EXCL;
63 }
64};