11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_cirequire('../common');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst { validateOneOf } = require('internal/validators');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci{
91cb0ef41Sopenharmony_ci  // validateOneOf number incorrect.
101cb0ef41Sopenharmony_ci  const allowed = [2, 3];
111cb0ef41Sopenharmony_ci  assert.throws(() => validateOneOf(1, 'name', allowed), {
121cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_VALUE',
131cb0ef41Sopenharmony_ci    // eslint-disable-next-line quotes
141cb0ef41Sopenharmony_ci    message: `The argument 'name' must be one of: 2, 3. Received 1`
151cb0ef41Sopenharmony_ci  });
161cb0ef41Sopenharmony_ci}
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci{
191cb0ef41Sopenharmony_ci  // validateOneOf number correct.
201cb0ef41Sopenharmony_ci  validateOneOf(2, 'name', [1, 2]);
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci{
241cb0ef41Sopenharmony_ci  // validateOneOf string incorrect.
251cb0ef41Sopenharmony_ci  const allowed = ['b', 'c'];
261cb0ef41Sopenharmony_ci  assert.throws(() => validateOneOf('a', 'name', allowed), {
271cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_VALUE',
281cb0ef41Sopenharmony_ci    // eslint-disable-next-line quotes
291cb0ef41Sopenharmony_ci    message: `The argument 'name' must be one of: 'b', 'c'. Received 'a'`
301cb0ef41Sopenharmony_ci  });
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci{
341cb0ef41Sopenharmony_ci  // validateOneOf string correct.
351cb0ef41Sopenharmony_ci  validateOneOf('two', 'name', ['one', 'two']);
361cb0ef41Sopenharmony_ci}
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci{
391cb0ef41Sopenharmony_ci  // validateOneOf Symbol incorrect.
401cb0ef41Sopenharmony_ci  const allowed = [Symbol.for('b'), Symbol.for('c')];
411cb0ef41Sopenharmony_ci  assert.throws(() => validateOneOf(Symbol.for('a'), 'name', allowed), {
421cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_VALUE',
431cb0ef41Sopenharmony_ci    // eslint-disable-next-line quotes
441cb0ef41Sopenharmony_ci    message: `The argument 'name' must be one of: Symbol(b), Symbol(c). ` +
451cb0ef41Sopenharmony_ci      'Received Symbol(a)'
461cb0ef41Sopenharmony_ci  });
471cb0ef41Sopenharmony_ci}
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci{
501cb0ef41Sopenharmony_ci  // validateOneOf Symbol correct.
511cb0ef41Sopenharmony_ci  const allowed = [Symbol.for('b'), Symbol.for('c')];
521cb0ef41Sopenharmony_ci  validateOneOf(Symbol.for('b'), 'name', allowed);
531cb0ef41Sopenharmony_ci}
54