<commit_before>'use babel';

import { AssertionParser } from '../lib/assertions';
import { parsedLineFixture } from './utils';


function parserFixture(...lines) {
  const iterator = parsedLineFixture('blah.txt', ...lines);
  iterator.header = {
    openToken: '// ',
    closeToken: '',
    source: 'source.c',
  };
  return new AssertionParser(iterator);
}


describe('Assertions', () => {
  describe('AssertionParser', () => {
    it('should only return source lines', () => {
      const parser = parserFixture(
        '#pragma once',
        '// <- punctuation.definition.directive meta.preprocessor.c',
        ' // <- keyword.control.directive.pragma',
        '// ^ keyword.control.directive.pragma'
      );
      expect(
        Array.from(parser).map((item) => item.line)
      ).toEqual([
        '#pragma once',
      ]);
    });

    it('should map assertions onto the source line', () => {
      const parser = parserFixture(
        '#pragma once',
        '// <- punctuation.definition.directive meta.preprocessor.c',
        ' // <- keyword.control.directive.pragma',
        '// ^ keyword.control.directive.pragma'
      );

      const assertions = Array.from(parser)[0].assertions;
      expect(assertions.length).toEqual(3);
    });

    it('should parse <- assertions', () => {
      const parser = parserFixture(
        '#pragma once',
        '// <- punctuation.definition.directive meta.preprocessor.c'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'punctuation.definition.directive',
        'meta.preprocessor.c',
      ]);
      expect(assertion.column).toEqual(1);
    });

    it('should parse <- assertions with leading whitespace', () => {
      const parser = parserFixture(
        '#pragma once',
        ' // <- keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(2);
    });

    it('should parse ^ assertions', () => {
      const parser = parserFixture(
        '#pragma once',
        '// ^ keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(4);
    });

    it('should parse ^ assertions with leading whitespace', () => {
      const parser = parserFixture(
        '#pragma once',
        '  // ^ keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(6);
    });

    it('should parse ^ assertions with prefixed whitespace whitespace', () => {
      const parser = parserFixture(
        '#pragma once',
        '//    ^ keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(7);
    });

    it('should parse ^^+ assertions', () => {
      const parser = parserFixture(
        '#pragma once',
        '// ^^^^ keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(4);
    });
  });
});
<commit_msg>Added failing test for multiple carats in an assertion<commit_after>'use babel';

import { AssertionParser } from '../lib/assertions';
import { parsedLineFixture } from './utils';


function parserFixture(...lines) {
  const iterator = parsedLineFixture('blah.txt', ...lines);
  iterator.header = {
    openToken: '// ',
    closeToken: '',
    source: 'source.c',
  };
  return new AssertionParser(iterator);
}


describe('Assertions', () => {
  describe('AssertionParser', () => {
    it('should only return source lines', () => {
      const parser = parserFixture(
        '#pragma once',
        '// <- punctuation.definition.directive meta.preprocessor.c',
        ' // <- keyword.control.directive.pragma',
        '// ^ keyword.control.directive.pragma'
      );
      expect(
        Array.from(parser).map((item) => item.line)
      ).toEqual([
        '#pragma once',
      ]);
    });

    it('should map assertions onto the source line', () => {
      const parser = parserFixture(
        '#pragma once',
        '// <- punctuation.definition.directive meta.preprocessor.c',
        ' // <- keyword.control.directive.pragma',
        '// ^ keyword.control.directive.pragma'
      );

      const assertions = Array.from(parser)[0].assertions;
      expect(assertions.length).toEqual(3);
    });

    it('should parse <- assertions', () => {
      const parser = parserFixture(
        '#pragma once',
        '// <- punctuation.definition.directive meta.preprocessor.c'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'punctuation.definition.directive',
        'meta.preprocessor.c',
      ]);
      expect(assertion.column).toEqual(1);
    });

    it('should parse <- assertions with leading whitespace', () => {
      const parser = parserFixture(
        '#pragma once',
        ' // <- keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(2);
    });

    it('should parse ^ assertions', () => {
      const parser = parserFixture(
        '#pragma once',
        '// ^ keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(4);
    });

    it('should parse ^ assertions with leading whitespace', () => {
      const parser = parserFixture(
        '#pragma once',
        '  // ^ keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(6);
    });

    it('should parse ^ assertions with prefixed whitespace whitespace', () => {
      const parser = parserFixture(
        '#pragma once',
        '//    ^ keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(7);
    });

    it('should parse ^^+ assertions', () => {
      const parser = parserFixture(
        '#pragma once',
        '// ^^^^ keyword.control.directive.pragma'
      );

      const assertion = Array.from(parser)[0].assertions[0];
      expect(assertion.scopes).toEqual([
        'keyword.control.directive.pragma',
      ]);
      expect(assertion.column).toEqual(4);
    });

    it('should parse multiple carats separated by spaces (^   ^ some.rule)', () => {
      const parser = parserFixture(
        '#pragma once',
        '// ^     ^ some.symbol'
      );

      const assertions = Array.from(parser)[0].assertions;
      expect(assertions.length).toBe(2);
      const [assertion1, assertion2] = assertions;
      expect(assertion1.scopes).toEqual([
        'some.symbol',
      ]);
      expect(assertion1.column).toEqual(4);

      expect(assertion2.scopes).toEqual([
        'some.symbol',
      ]);
      expect(assertion2.column).toEqual(10);
    });
  });
});

{'fraction_non_alphanumeric': 0.16378548895899053, 'fraction_numerical': 0.006435331230283912, 'mean_word_length': 2.4687089715536104, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2096839', 'n_tokens_mistral': 2334, 'n_tokens_neox': 2298, 'n_words': 372}