1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const string_dir = fs.realpathSync(common.fixturesDir);
const buffer_dir = Buffer.from(string_dir);
const encodings = ['ascii', 'utf8', 'utf16le', 'ucs2',
'base64', 'binary', 'hex'];
const expected = {};
encodings.forEach((encoding) => {
expected[encoding] = buffer_dir.toString(encoding);
});
// test sync version
let encoding;
for (encoding in expected) {
const expected_value = expected[encoding];
let result;
result = fs.realpathSync(string_dir, {encoding: encoding});
assert.strictEqual(result, expected_value);
result = fs.realpathSync(string_dir, encoding);
assert.strictEqual(result, expected_value);
result = fs.realpathSync(buffer_dir, {encoding: encoding});
assert.strictEqual(result, expected_value);
result = fs.realpathSync(buffer_dir, encoding);
assert.strictEqual(result, expected_value);
}
let buffer_result;
buffer_result = fs.realpathSync(string_dir, {encoding: 'buffer'});
assert.deepStrictEqual(buffer_result, buffer_dir);
buffer_result = fs.realpathSync(string_dir, 'buffer');
assert.deepStrictEqual(buffer_result, buffer_dir);
buffer_result = fs.realpathSync(buffer_dir, {encoding: 'buffer'});
assert.deepStrictEqual(buffer_result, buffer_dir);
buffer_result = fs.realpathSync(buffer_dir, 'buffer');
assert.deepStrictEqual(buffer_result, buffer_dir);
// test async version
for (encoding in expected) {
const expected_value = expected[encoding];
fs.realpath(string_dir, {encoding: encoding}, common.mustCall((err, res) => {
assert(!err);
assert.strictEqual(res, expected_value);
}));
fs.realpath(string_dir, encoding, common.mustCall((err, res) => {
assert(!err);
assert.strictEqual(res, expected_value);
}));
fs.realpath(buffer_dir, {encoding: encoding}, common.mustCall((err, res) => {
assert(!err);
assert.strictEqual(res, expected_value);
}));
fs.realpath(buffer_dir, encoding, common.mustCall((err, res) => {
assert(!err);
assert.strictEqual(res, expected_value);
}));
}
fs.realpath(string_dir, {encoding: 'buffer'}, common.mustCall((err, res) => {
assert(!err);
assert.deepStrictEqual(res, buffer_dir);
}));
fs.realpath(string_dir, 'buffer', common.mustCall((err, res) => {
assert(!err);
assert.deepStrictEqual(res, buffer_dir);
}));
fs.realpath(buffer_dir, {encoding: 'buffer'}, common.mustCall((err, res) => {
assert(!err);
assert.deepStrictEqual(res, buffer_dir);
}));
fs.realpath(buffer_dir, 'buffer', common.mustCall((err, res) => {
assert(!err);
assert.deepStrictEqual(res, buffer_dir);
}));
|