<commit_before>import chai, { assert } from 'chai';
import chaiAsPromised from 'chai-as-promised';

import {
  fixture,
  expectRejectedWithCode,
} from './utils';
import * as U from '../src/utils';
import * as ERROR_CODES from '../src/errorCodes';
import { DEFAULT_WORKSPACE_PATH } from '../src/constants';

chai.use(chaiAsPromised);

describe('Utils', () => {
  it('ensureWorkspacePath: resolve path and homedir symbol', () => {
    assert.equal(U.ensureWorkspacePath('/Users/vaso/test'), '/Users/vaso/test');
    assert.equal(U.ensureWorkspacePath('~/xod'), U.resolvePath('~/xod'));
  });
  it('ensureWorkspacePath: fallback to default workspace path', () => {
    assert.equal(U.ensureWorkspacePath(''), U.resolvePath(DEFAULT_WORKSPACE_PATH));
    assert.equal(U.ensureWorkspacePath({}), U.resolvePath(DEFAULT_WORKSPACE_PATH));
    assert.equal(U.ensureWorkspacePath(null), U.resolvePath(DEFAULT_WORKSPACE_PATH));
  });

  it('resolveWorkspacePath: resolve Path for valid value',
    () => assert.eventually.equal(
      U.resolveWorkspacePath(fixture('./workspace')),
      fixture('./workspace')
    )
  );
  it('resolveWorkspacePath: reject INVALID_WORKSPACE_PATH for null value',
    () => expectRejectedWithCode(
      U.resolveWorkspacePath(null),
      ERROR_CODES.INVALID_WORKSPACE_PATH
    )
  );
  it('resolveWorkspacePath: reject INVALID_WORKSPACE_PATH for empty string',
    () => expectRejectedWithCode(
      U.resolveWorkspacePath(''),
      ERROR_CODES.INVALID_WORKSPACE_PATH
    )
  );

  it('isWorkspaceValid: resolve Path for valid workspace',
    () => assert.eventually.equal(
      U.isWorkspaceValid(fixture('./workspace')),
      fixture('./workspace')
    )
  );
  it('isWorkspaceValid: reject WORKSPACE_DIR_NOT_EMPTY for not empty directory',
    () => expectRejectedWithCode(
      U.isWorkspaceValid(fixture('./emptyWorkspace')),
      ERROR_CODES.WORKSPACE_DIR_NOT_EMPTY
    )
  );
  it('isWorkspaceValid: reject WORKSPACE_DIR_NOT_EXIST_OR_EMPTY for non-existent directory',
    () => expectRejectedWithCode(
      U.isWorkspaceValid(fixture('./notExistWorkspace')),
      ERROR_CODES.WORKSPACE_DIR_NOT_EXIST_OR_EMPTY
    )
  );

  it('validateWorkspace: resolve Path for valid workspace',
    () => assert.eventually.equal(
      U.validateWorkspace(fixture('./workspace')),
      fixture('./workspace')
    )
  );
  it('validateWorkspace: reject WORKSPACE_DIR_NOT_EXIST_OR_EMPTY for not existent directory',
    () => expectRejectedWithCode(
      U.validateWorkspace(fixture('./notExistWorkspace')),
      ERROR_CODES.WORKSPACE_DIR_NOT_EXIST_OR_EMPTY
    )
  );
  it('validateWorkspace: reject WORKSPACE_DIR_NOT_EMPTY for not empty directory without workspace file',
    () => expectRejectedWithCode(
      U.validateWorkspace(fixture('.')),
      ERROR_CODES.WORKSPACE_DIR_NOT_EMPTY
    )
  );
});
<commit_msg>test(xod-fs): rephrase test titles<commit_after>import path from 'path';
import chai, { assert } from 'chai';
import chaiAsPromised from 'chai-as-promised';

import {
  fixture,
  expectRejectedWithCode,
} from './utils';
import * as U from '../src/utils';
import * as ERROR_CODES from '../src/errorCodes';
import { DEFAULT_WORKSPACE_PATH } from '../src/constants';

chai.use(chaiAsPromised);

describe('Utils', () => {
  it('ensureWorkspacePath: if path correct, just resolves path', () => {
    assert.equal(U.ensureWorkspacePath('/Users/vaso/test'), '/Users/vaso/test');
    assert.equal(U.ensureWorkspacePath('a/b/c'), path.resolve('a/b/c'));
  });
  it('ensureWorkspacePath: if path begins with homedir symbol, resolves path to homedir', () => {
    assert.equal(U.ensureWorkspacePath('~/xod'), U.resolvePath('~/xod'));
  });
  it('ensureWorkspacePath: if path is empty or incorrect, fallbacks to default workspace path', () => {
    assert.equal(U.ensureWorkspacePath(''), U.resolvePath(DEFAULT_WORKSPACE_PATH));
    assert.equal(U.ensureWorkspacePath({}), U.resolvePath(DEFAULT_WORKSPACE_PATH));
    assert.equal(U.ensureWorkspacePath(null), U.resolvePath(DEFAULT_WORKSPACE_PATH));
  });

  it('resolveWorkspacePath: if path correct, just resolves path',
    () => assert.eventually.equal(
      U.resolveWorkspacePath(fixture('./workspace')),
      fixture('./workspace')
    )
  );
  it('resolveWorkspacePath: if path is incorrect, rejects with error code INVALID_WORKSPACE_PATH',
    () => Promise.all([
      expectRejectedWithCode(
        U.resolveWorkspacePath(null),
        ERROR_CODES.INVALID_WORKSPACE_PATH
      ),
      expectRejectedWithCode(
        U.resolveWorkspacePath(''),
        ERROR_CODES.INVALID_WORKSPACE_PATH
      ),
    ])
  );

  it('isWorkspaceValid: if workspace in specified path is valid, resolves path',
    () => assert.eventually.equal(
      U.isWorkspaceValid(fixture('./workspace')),
      fixture('./workspace')
    )
  );
  it('isWorkspaceValid: if specified directory is not empty, rejects with error code WORKSPACE_DIR_NOT_EMPTY',
    () => expectRejectedWithCode(
      U.isWorkspaceValid(fixture('./emptyWorkspace')),
      ERROR_CODES.WORKSPACE_DIR_NOT_EMPTY
    )
  );
  it('isWorkspaceValid: if specified directory is not exist or empty, rejects with error code WORKSPACE_DIR_NOT_EXIST_OR_EMPTY',
    () => expectRejectedWithCode(
      U.isWorkspaceValid(fixture('./notExistWorkspace')),
      ERROR_CODES.WORKSPACE_DIR_NOT_EXIST_OR_EMPTY
    )
  );

  it('validateWorkspace: if workspace in specified path is valid, resolves path',
    () => assert.eventually.equal(
      U.validateWorkspace(fixture('./workspace')),
      fixture('./workspace')
    )
  );
  it('validateWorkspace: if specified path is incorrect, rejects with error code INVALID_WORKSPACE_PATH',
    () => expectRejectedWithCode(
      U.validateWorkspace(null),
      ERROR_CODES.INVALID_WORKSPACE_PATH
    )
  );
  it('validateWorkspace: if specified directory is not empty, rejects with error code WORKSPACE_DIR_NOT_EMPTY',
    () => expectRejectedWithCode(
      U.validateWorkspace(fixture('.')),
      ERROR_CODES.WORKSPACE_DIR_NOT_EMPTY
    )
  );
  it('validateWorkspace: if specified directory is not exist or empty, rejects with error code WORKSPACE_DIR_NOT_EXIST_OR_EMPTY',
    () => expectRejectedWithCode(
      U.validateWorkspace(fixture('./notExistWorkspace')),
      ERROR_CODES.WORKSPACE_DIR_NOT_EXIST_OR_EMPTY
    )
  );
});

{'fraction_non_alphanumeric': 0.1339243311698591, 'fraction_numerical': 0.0, 'mean_word_length': 4.273789649415693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '5376382', 'n_tokens_mistral': 1949, 'n_tokens_neox': 2041, 'n_words': 349}