// Copyright 2026 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only const rule = require('./enforce-array-buffer'); const RuleTester = require('eslint').RuleTester; // avoid triggering mocha's global leak detection require('@typescript-eslint/parser'); const ruleTester = new RuleTester({ parser: require.resolve('@typescript-eslint/parser'), parserOptions: { ecmaVersion: 2018, sourceType: 'module', }, }); const EXPECTED_ARRAY_ERROR = { message: 'Should be Uint8Array', type: 'TSTypeReference', }; const EXPECTED_BUFFER_ERROR = { message: 'Should be Buffer', type: 'TSTypeReference', }; ruleTester.run('enforce-array-buffer', rule, { valid: [ { code: 'type T = number;' }, { code: 'type T = Uint16Array;' }, { code: 'type T = Uint8Array;' }, { code: 'type T = Uint8Array;' }, { code: 'type T = Uint8Array;' }, { code: 'type T = Uint8Array;' }, { code: 'function f(): Uint8Array {}' }, { code: 'function f(p: Uint8Array) {}' }, { code: 'let v: Uint8Array;' }, { code: 'let v = new Uint8Array();' }, { code: 'let v = new Uint8Array();' }, { code: 'let v = Uint8Array.of();' }, { code: 'let v = Uint8Array.from();' }, { code: 'let v: { p: Uint8Array };' }, { code: 'type T = Buffer;' }, { code: 'type T = Buffer;' }, { code: 'type T = Buffer;' }, { code: 'type T = Buffer;' }, { code: 'let v = new Buffer();' }, { code: 'let v = Buffer.from();' }, ], invalid: [ { code: `type T = Uint8Array`, output: `type T = Uint8Array`, errors: [EXPECTED_ARRAY_ERROR], }, { code: `function f(): Uint8Array {}`, output: `function f(): Uint8Array {}`, errors: [EXPECTED_ARRAY_ERROR], }, { code: `function f(p: Uint8Array) {}`, output: `function f(p: Uint8Array) {}`, errors: [EXPECTED_ARRAY_ERROR], }, { code: `let v: Uint8Array;`, output: `let v: Uint8Array;`, errors: [EXPECTED_ARRAY_ERROR], }, { code: `let v: { p: Uint8Array };`, output: `let v: { p: Uint8Array };`, errors: [EXPECTED_ARRAY_ERROR], }, { code: `type T = Buffer`, output: `type T = Buffer`, errors: [EXPECTED_BUFFER_ERROR], }, ], });