11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif ((!common.hasCrypto) || (!common.hasIntl)) {
51cb0ef41Sopenharmony_ci  common.skip('ESLint tests require crypto and Intl');
61cb0ef41Sopenharmony_ci}
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cicommon.skipIfEslintMissing();
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst RuleTester = require('../../tools/node_modules/eslint').RuleTester;
111cb0ef41Sopenharmony_ciconst rule = require('../../tools/eslint-rules/prefer-common-mustsucceed');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst msg1 = 'Please use common.mustSucceed instead of ' +
141cb0ef41Sopenharmony_ci             'common.mustCall(assert.ifError).';
151cb0ef41Sopenharmony_ciconst msg2 = 'Please use common.mustSucceed instead of ' +
161cb0ef41Sopenharmony_ci             'common.mustCall with assert.ifError.';
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cinew RuleTester({
191cb0ef41Sopenharmony_ci  parserOptions: { ecmaVersion: 2015 }
201cb0ef41Sopenharmony_ci}).run('prefer-common-mustsucceed', rule, {
211cb0ef41Sopenharmony_ci  valid: [
221cb0ef41Sopenharmony_ci    'foo((err) => assert.ifError(err))',
231cb0ef41Sopenharmony_ci    'foo(function(err) { assert.ifError(err) })',
241cb0ef41Sopenharmony_ci    'foo(assert.ifError)',
251cb0ef41Sopenharmony_ci    'common.mustCall((err) => err)',
261cb0ef41Sopenharmony_ci  ],
271cb0ef41Sopenharmony_ci  invalid: [
281cb0ef41Sopenharmony_ci    {
291cb0ef41Sopenharmony_ci      code: 'common.mustCall(assert.ifError)',
301cb0ef41Sopenharmony_ci      errors: [{ message: msg1 }]
311cb0ef41Sopenharmony_ci    },
321cb0ef41Sopenharmony_ci    {
331cb0ef41Sopenharmony_ci      code: 'common.mustCall((err) => assert.ifError(err))',
341cb0ef41Sopenharmony_ci      errors: [{ message: msg2 }]
351cb0ef41Sopenharmony_ci    },
361cb0ef41Sopenharmony_ci    {
371cb0ef41Sopenharmony_ci      code: 'common.mustCall((e) => assert.ifError(e))',
381cb0ef41Sopenharmony_ci      errors: [{ message: msg2 }]
391cb0ef41Sopenharmony_ci    },
401cb0ef41Sopenharmony_ci    {
411cb0ef41Sopenharmony_ci      code: 'common.mustCall(function(e) { assert.ifError(e); })',
421cb0ef41Sopenharmony_ci      errors: [{ message: msg2 }]
431cb0ef41Sopenharmony_ci    },
441cb0ef41Sopenharmony_ci    {
451cb0ef41Sopenharmony_ci      code: 'common.mustCall(function(e) { return assert.ifError(e); })',
461cb0ef41Sopenharmony_ci      errors: [{ message: msg2 }]
471cb0ef41Sopenharmony_ci    },
481cb0ef41Sopenharmony_ci    {
491cb0ef41Sopenharmony_ci      code: 'common.mustCall(function(e) {{ assert.ifError(e); }})',
501cb0ef41Sopenharmony_ci      errors: [{ message: msg2 }]
511cb0ef41Sopenharmony_ci    },
521cb0ef41Sopenharmony_ci  ]
531cb0ef41Sopenharmony_ci});
54