u
This commit is contained in:
31
test/mouse.test.js
Normal file
31
test/mouse.test.js
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import {
|
||||
wheelDeltaFromInput,
|
||||
containsMouseSequence,
|
||||
stripMouseSequences,
|
||||
} from '../src/ui/mouse.js';
|
||||
|
||||
test('decodes SGR wheel direction', () => {
|
||||
assert.equal(wheelDeltaFromInput('\x1b[<64;88;20M'), -1);
|
||||
assert.equal(wheelDeltaFromInput('[<65;88;20M'), 1);
|
||||
// Some terminals add modifier bits to the button code.
|
||||
assert.equal(wheelDeltaFromInput('[<96;88;20M'), -1);
|
||||
assert.equal(wheelDeltaFromInput('[<97;88;20M'), 1);
|
||||
});
|
||||
|
||||
test('ignores non-wheel and incomplete mouse input', () => {
|
||||
assert.equal(wheelDeltaFromInput('[<0;1;1M'), 0);
|
||||
assert.equal(wheelDeltaFromInput('[<64;1;1'), 0);
|
||||
assert.equal(wheelDeltaFromInput('hello'), 0);
|
||||
});
|
||||
|
||||
test('removes mouse reports without dropping surrounding text', () => {
|
||||
const value = 'before\x1b[<65;88;20Mafter';
|
||||
assert.equal(containsMouseSequence(value), true);
|
||||
assert.equal(stripMouseSequences(value), 'beforeafter');
|
||||
assert.equal(stripMouseSequences('plain text'), 'plain text');
|
||||
});
|
||||
Reference in New Issue
Block a user