11cb0ef41Sopenharmony_ci// Flags: --expose-internals 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst common = require('../common'); 51cb0ef41Sopenharmony_ciconst { getDirents, getDirent } = require('internal/fs/utils'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst { internalBinding } = require('internal/test/binding'); 81cb0ef41Sopenharmony_ciconst { UV_DIRENT_UNKNOWN } = internalBinding('constants').fs; 91cb0ef41Sopenharmony_ciconst fs = require('fs'); 101cb0ef41Sopenharmony_ciconst path = require('path'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 131cb0ef41Sopenharmony_ciconst filename = 'foo'; 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci{ 161cb0ef41Sopenharmony_ci // setup 171cb0ef41Sopenharmony_ci tmpdir.refresh(); 181cb0ef41Sopenharmony_ci fs.writeFileSync(path.join(tmpdir.path, filename), ''); 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ci// getDirents 211cb0ef41Sopenharmony_ci{ 221cb0ef41Sopenharmony_ci // string + string 231cb0ef41Sopenharmony_ci getDirents( 241cb0ef41Sopenharmony_ci tmpdir.path, 251cb0ef41Sopenharmony_ci [[filename], [UV_DIRENT_UNKNOWN]], 261cb0ef41Sopenharmony_ci common.mustCall((err, names) => { 271cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 281cb0ef41Sopenharmony_ci assert.strictEqual(names.length, 1); 291cb0ef41Sopenharmony_ci }, 301cb0ef41Sopenharmony_ci )); 311cb0ef41Sopenharmony_ci} 321cb0ef41Sopenharmony_ci{ 331cb0ef41Sopenharmony_ci // string + Buffer 341cb0ef41Sopenharmony_ci getDirents( 351cb0ef41Sopenharmony_ci tmpdir.path, 361cb0ef41Sopenharmony_ci [[Buffer.from(filename)], [UV_DIRENT_UNKNOWN]], 371cb0ef41Sopenharmony_ci common.mustCall((err, names) => { 381cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 391cb0ef41Sopenharmony_ci assert.strictEqual(names.length, 1); 401cb0ef41Sopenharmony_ci }, 411cb0ef41Sopenharmony_ci )); 421cb0ef41Sopenharmony_ci} 431cb0ef41Sopenharmony_ci{ 441cb0ef41Sopenharmony_ci // Buffer + Buffer 451cb0ef41Sopenharmony_ci getDirents( 461cb0ef41Sopenharmony_ci Buffer.from(tmpdir.path), 471cb0ef41Sopenharmony_ci [[Buffer.from(filename)], [UV_DIRENT_UNKNOWN]], 481cb0ef41Sopenharmony_ci common.mustCall((err, names) => { 491cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 501cb0ef41Sopenharmony_ci assert.strictEqual(names.length, 1); 511cb0ef41Sopenharmony_ci }, 521cb0ef41Sopenharmony_ci )); 531cb0ef41Sopenharmony_ci} 541cb0ef41Sopenharmony_ci{ 551cb0ef41Sopenharmony_ci // wrong combination 561cb0ef41Sopenharmony_ci getDirents( 571cb0ef41Sopenharmony_ci 42, 581cb0ef41Sopenharmony_ci [[Buffer.from(filename)], [UV_DIRENT_UNKNOWN]], 591cb0ef41Sopenharmony_ci common.mustCall((err) => { 601cb0ef41Sopenharmony_ci assert.strictEqual( 611cb0ef41Sopenharmony_ci err.message, 621cb0ef41Sopenharmony_ci [ 631cb0ef41Sopenharmony_ci 'The "path" argument must be of type string or an ' + 641cb0ef41Sopenharmony_ci 'instance of Buffer. Received type number (42)', 651cb0ef41Sopenharmony_ci ].join('')); 661cb0ef41Sopenharmony_ci }, 671cb0ef41Sopenharmony_ci )); 681cb0ef41Sopenharmony_ci} 691cb0ef41Sopenharmony_ci// getDirent 701cb0ef41Sopenharmony_ci{ 711cb0ef41Sopenharmony_ci // string + string 721cb0ef41Sopenharmony_ci getDirent( 731cb0ef41Sopenharmony_ci tmpdir.path, 741cb0ef41Sopenharmony_ci filename, 751cb0ef41Sopenharmony_ci UV_DIRENT_UNKNOWN, 761cb0ef41Sopenharmony_ci common.mustCall((err, dirent) => { 771cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 781cb0ef41Sopenharmony_ci assert.strictEqual(dirent.name, filename); 791cb0ef41Sopenharmony_ci }, 801cb0ef41Sopenharmony_ci )); 811cb0ef41Sopenharmony_ci} 821cb0ef41Sopenharmony_ci{ 831cb0ef41Sopenharmony_ci // string + Buffer 841cb0ef41Sopenharmony_ci const filenameBuffer = Buffer.from(filename); 851cb0ef41Sopenharmony_ci getDirent( 861cb0ef41Sopenharmony_ci tmpdir.path, 871cb0ef41Sopenharmony_ci filenameBuffer, 881cb0ef41Sopenharmony_ci UV_DIRENT_UNKNOWN, 891cb0ef41Sopenharmony_ci common.mustCall((err, dirent) => { 901cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 911cb0ef41Sopenharmony_ci assert.strictEqual(dirent.name, filenameBuffer); 921cb0ef41Sopenharmony_ci }, 931cb0ef41Sopenharmony_ci )); 941cb0ef41Sopenharmony_ci} 951cb0ef41Sopenharmony_ci{ 961cb0ef41Sopenharmony_ci // Buffer + Buffer 971cb0ef41Sopenharmony_ci const filenameBuffer = Buffer.from(filename); 981cb0ef41Sopenharmony_ci getDirent( 991cb0ef41Sopenharmony_ci Buffer.from(tmpdir.path), 1001cb0ef41Sopenharmony_ci filenameBuffer, 1011cb0ef41Sopenharmony_ci UV_DIRENT_UNKNOWN, 1021cb0ef41Sopenharmony_ci common.mustCall((err, dirent) => { 1031cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 1041cb0ef41Sopenharmony_ci assert.strictEqual(dirent.name, filenameBuffer); 1051cb0ef41Sopenharmony_ci }, 1061cb0ef41Sopenharmony_ci )); 1071cb0ef41Sopenharmony_ci} 1081cb0ef41Sopenharmony_ci{ 1091cb0ef41Sopenharmony_ci // wrong combination 1101cb0ef41Sopenharmony_ci getDirent( 1111cb0ef41Sopenharmony_ci 42, 1121cb0ef41Sopenharmony_ci Buffer.from(filename), 1131cb0ef41Sopenharmony_ci UV_DIRENT_UNKNOWN, 1141cb0ef41Sopenharmony_ci common.mustCall((err) => { 1151cb0ef41Sopenharmony_ci assert.strictEqual( 1161cb0ef41Sopenharmony_ci err.message, 1171cb0ef41Sopenharmony_ci [ 1181cb0ef41Sopenharmony_ci 'The "path" argument must be of type string or an ' + 1191cb0ef41Sopenharmony_ci 'instance of Buffer. Received type number (42)', 1201cb0ef41Sopenharmony_ci ].join('')); 1211cb0ef41Sopenharmony_ci }, 1221cb0ef41Sopenharmony_ci )); 1231cb0ef41Sopenharmony_ci} 124