HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/ubuntu/neovim/.deps/build/src/treesitter/lib/binding_web/test/language-test.js
const {assert} = require('chai');
let JavaScript;

describe('Language', () => {
  before(async () => ({JavaScript} = await require('./helper')));

  describe('.fieldIdForName, .fieldNameForId', () => {
    it('converts between the string and integer representations of fields', () => {
      const nameId = JavaScript.fieldIdForName('name');
      const bodyId = JavaScript.fieldIdForName('body');

      assert.isBelow(nameId, JavaScript.fieldCount);
      assert.isBelow(bodyId, JavaScript.fieldCount);
      assert.equal('name', JavaScript.fieldNameForId(nameId));
      assert.equal('body', JavaScript.fieldNameForId(bodyId));
    });

    it('handles invalid inputs', () => {
      assert.equal(null, JavaScript.fieldIdForName('namezzz'));
      assert.equal(null, JavaScript.fieldNameForId(-1));
      assert.equal(null, JavaScript.fieldNameForId(10000));
    });
  });

  describe('.idForNodeType, .nodeTypeForId, .nodeTypeIsNamed', () => {
    it('converts between the string and integer representations of a node type', () => {
      const exportStatementId = JavaScript.idForNodeType('export_statement', true);
      const starId = JavaScript.idForNodeType('*', false);

      assert.isBelow(exportStatementId, JavaScript.nodeTypeCount);
      assert.isBelow(starId, JavaScript.nodeTypeCount);
      assert.equal(true, JavaScript.nodeTypeIsNamed(exportStatementId));
      assert.equal('export_statement', JavaScript.nodeTypeForId(exportStatementId));
      assert.equal(false, JavaScript.nodeTypeIsNamed(starId));
      assert.equal('*', JavaScript.nodeTypeForId(starId));
    });

    it('handles invalid inputs', () => {
      assert.equal(null, JavaScript.nodeTypeForId(-1));
      assert.equal(null, JavaScript.nodeTypeForId(10000));
      assert.equal(null, JavaScript.idForNodeType('export_statement', false));
    });
  });
});

describe('Lookahead iterator', () => {
  let lookahead;
  let state;
  before(async () => {
    let Parser;
    ({JavaScript, Parser} = await require('./helper'));
    const parser = new Parser().setLanguage(JavaScript);
    const tree = parser.parse('function fn() {}');
    parser.delete();
    const cursor = tree.walk();
    assert(cursor.gotoFirstChild());
    assert(cursor.gotoFirstChild());
    state = cursor.currentNode.nextParseState;
    lookahead = JavaScript.lookaheadIterator(state);
    assert.exists(lookahead);
  });

  after(() => {
    lookahead.delete();
  });

  const expected = ['(', 'identifier', '*', 'formal_parameters', 'html_comment', 'comment'];
  it('should iterate over valid symbols in the state', () => {
    const symbols = Array.from(lookahead);
    assert.includeMembers(symbols, expected);
    assert.lengthOf(symbols, expected.length);
  });

  it('should reset to the initial state', () => {
    assert(lookahead.resetState(state));
    const symbols = Array.from(lookahead);
    assert.includeMembers(symbols, expected);
    assert.lengthOf(symbols, expected.length);
  });

  it('should reset', () => {
    assert(lookahead.reset(JavaScript, state));
    const symbols = Array.from(lookahead);
    assert.includeMembers(symbols, expected);
    assert.lengthOf(symbols, expected.length);
  });
});