<commit_before>'use babel';

import tempy from 'tempy';
import path from 'path';

import CodeContext from '../lib/code-context';

describe('CodeContext', () => {
  const testFile = 'test.txt';
  let testFilePath;

  beforeEach(() => {
    testFilePath = path.join(tempy.directory(), testFile);
    this.codeContext = new CodeContext(testFile, testFilePath, null);
    // TODO: Test using an actual editor or a selection?
    this.dummyTextSource = {};
    this.dummyTextSource.getText = () => "print 'hello world!'";
  });

  describe('fileColonLine when lineNumber is not set', () => {
    it('returns the full filepath when fullPath is truthy', () => {
      expect(this.codeContext.fileColonLine()).toEqual(testFilePath);
      expect(this.codeContext.fileColonLine(true)).toEqual(testFilePath);
    });

    it('returns only the filename and line number when fullPath is falsy', () => {
      expect(this.codeContext.fileColonLine(false)).toEqual(testFile);
    });
  });

  describe('fileColonLine when lineNumber is set', () => {
    it('returns the full filepath when fullPath is truthy', () => {
      this.codeContext.lineNumber = 42;
      expect(this.codeContext.fileColonLine()).toMatch(testFilePath);
      expect(this.codeContext.fileColonLine(true)).toMatch(testFilePath);
    });

    it('returns only the filename and line number when fullPath is falsy', () => {
      this.codeContext.lineNumber = 42;
      expect(this.codeContext.fileColonLine(false)).toMatch(testFile);
    });
  });

  describe('getCode', () => {
    it('returns undefined if no textSource is available', () => {
      expect(this.codeContext.getCode()).toBe(null);
    });

    it('returns a string prepended with newlines when prependNewlines is truthy', () => {
      this.codeContext.textSource = this.dummyTextSource;
      this.codeContext.lineNumber = 3;

      const code = this.codeContext.getCode(true);
      expect(typeof code).toEqual('string');
      // Since Array#join will create newlines for one less than the the number
      // of elements line number 3 means there should be two newlines
      expect(code).toMatch("\n\nprint 'hello world!'");<commit_msg>tests: fix fileColonLine test<commit_after>'use babel';

import tempy from 'tempy';
import path from 'path';

import CodeContext from '../lib/code-context';

describe('CodeContext', () => {
  const testFile = 'test.txt';
  let testFilePath;

  beforeEach(() => {
    testFilePath = path.join(tempy.directory(), testFile);
    this.codeContext = new CodeContext(testFile, testFilePath, null);
    // TODO: Test using an actual editor or a selection?
    this.dummyTextSource = {};
    this.dummyTextSource.getText = () => "print 'hello world!'";
  });

  describe('fileColonLine when lineNumber is not set', () => {
    it('returns the full filepath when fullPath is truthy', () => {
      expect(this.codeContext.fileColonLine()).toEqual(testFilePath);
      expect(this.codeContext.fileColonLine(true)).toEqual(testFilePath);
    });

    it('returns only the filename and line number when fullPath is falsy', () => {
      expect(this.codeContext.fileColonLine(false)).toEqual(testFile);
    });
  });

  describe('fileColonLine when lineNumber is set', () => {
    it('returns the full filepath when fullPath is truthy', () => {
      this.codeContext.lineNumber = 42;
      expect(this.codeContext.fileColonLine()).toEqual(`${testFilePath}:42`);
      expect(this.codeContext.fileColonLine(true)).toEqual(`${testFilePath}:42`);
    });

    it('returns only the filename and line number when fullPath is falsy', () => {
      this.codeContext.lineNumber = 42;
      expect(this.codeContext.fileColonLine(false)).toEqual(`${testFile}:42`);
    });
  });

  describe('getCode', () => {
    it('returns undefined if no textSource is available', () => {
      expect(this.codeContext.getCode()).toBe(null);
    });

    it('returns a string prepended with newlines when prependNewlines is truthy', () => {
      this.codeContext.textSource = this.dummyTextSource;
      this.codeContext.lineNumber = 3;

      const code = this.codeContext.getCode(true);
      expect(typeof code).toEqual('string');
      // Since Array#join will create newlines for one less than the the number
      // of elements line number 3 means there should be two newlines
      expect(code).toMatch("\n\nprint 'hello world!'");
{'fraction_non_alphanumeric': 0.14302059496567507, 'fraction_numerical': 0.004118993135011442, 'mean_word_length': 3.7927631578947367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '4195436', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1259, 'n_words': 314}