<commit_before>'use strict'

const assert = require('assert')
const cd = require('../../../src/commands/cd')
const createBuffer = require('../../buffer')
const filesystem = require('../../../src/reducers/filesystem')
const createStore = require('redux').createStore
const initialState = require('../../initialState')

describe('#cd (change filesystem)', () => {
  it('should change the current working filesystem', () => {
    const store = createStore(filesystem, initialState.simple())
    const buffer = createBuffer()
    const newPath = '/usr/local/'
    cd(newPath, buffer, store)
    const output = buffer.get()
    const result = store.getState().workingDir
    const expect = ['usr', 'local']
    assert(output === '')
    assert.deepEqual(result, expect)
  })

  it('should change the current working filesystem, even if input is "dirty"', () => {
    const store = createStore(filesystem, initialState.simple())
    const buffer = createBuffer()
    const newPath = '////usr///local//'
    cd(newPath, buffer, store)
    const output = buffer.get()
    const result = store.getState().workingDir
    const expect = ['usr', 'local']
    assert(output === '')
    assert.deepEqual(result, expect)
  })

  it('should not change the current working filesystem, if target does not exist', () => {
    const store = createStore(filesystem, initialState.simple())
    const buffer = createBuffer()
    const newPath = '/path/that/does/not/exist'
    cd(newPath, buffer, store)
    const output = buffer.get()
    assert.deepEqual(store.getState().workingDir, [])
  })

  it('should not change the current working filesystem, if target is a file', () => {
    const store = createStore(filesystem, initialState.simple())
    const buffer = createBuffer()
    const newPath = '/etc/hosts'
    cd(newPath, buffer, store)
    assert.deepEqual(store.getState().workingDir, [])
  })
})<commit_msg>Test for error output<commit_after>'use strict'

const assert = require('assert')
const cd = require('../../../src/commands/cd')
const createBuffer = require('../../buffer')
const filesystem = require('../../../src/reducers/filesystem')
const createStore = require('redux').createStore
const initialState = require('../../initialState')

describe('#cd (change filesystem)', () => {
  it('should change the current working filesystem', () => {
    const store = createStore(filesystem, initialState.simple())
    const buffer = createBuffer()
    const newPath = '/usr/local/'
    cd(newPath, buffer, store)
    const output = buffer.get()
    const result = store.getState().workingDir
    const expect = ['usr', 'local']
    assert(output === '')
    assert.deepEqual(result, expect)
  })

  it('should change the current working filesystem, even if input is "dirty"', () => {
    const store = createStore(filesystem, initialState.simple())
    const buffer = createBuffer()
    const newPath = '////usr///local//'
    cd(newPath, buffer, store)
    const output = buffer.get()
    const result = store.getState().workingDir
    const expect = ['usr', 'local']
    assert(output === '')
    assert.deepEqual(result, expect)
  })

  it('should not change the current working filesystem, if target does not exist', () => {
    const store = createStore(filesystem, initialState.simple())
    const buffer = createBuffer()
    const newPath = '/path/that/does/not/exist'
    cd(newPath, buffer, store)
    const output = buffer.get()
    assert(/No such file or directory/.test(output))
    assert.deepEqual(store.getState().workingDir, [])
  })

  it('should not change the current working filesystem, if target is a file', () => {
    const store = createStore(filesystem, initialState.simple())
    const buffer = createBuffer()
    const newPath = '/etc/hosts'
    cd(newPath, buffer, store)
    const output = buffer.get()
    assert(/Not a directory/.test(output))
    assert.deepEqual(store.getState().workingDir, [])
  })
})
{'fraction_non_alphanumeric': 0.15741212429954152, 'fraction_numerical': 0.0, 'mean_word_length': 3.625441696113074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3280622', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1082, 'n_words': 308}