<commit_before>
const utils = require('../')
const sanitize = utils.sanitize
const transformContextIntoSedString = utils.transformContextIntoSedString
const execPromise = utils.execPromise
const logger = utils.logger
// const installDependencies = utils.installDependencies
// const getGlobalDependencies = utils.getGlobalDependencies
// const transformContextIntoSedString = utils.transformContextIntoSedString
const replaceAll = utils.replaceAll

describe('sanitize', () => {
  it('remove slashes | name', () => {
    const result = sanitize('name')
    expect(result).toBe('name')
  })
  it('remove slashes | /name', () => {
    const result = sanitize('/name')
    expect(result).toBe('name')
  })
  it('remove slashes | /name/', () => {
    const result = sanitize('/name/')
    expect(result).toBe('name')
  })
  it('remove slashes | undefined', () => {
    const result = sanitize()
    expect(result).toBe('')
  })
})

describe('transformContextIntoSedString', () => {
  it('convert object into sed string', () => {
    const result = transformContextIntoSedString({ name: 'test', port: 8080 })
    expect(result).toBe(' | sed s.#{name}.test.g | sed s.#{port}.8080.g')
  })
  it('convert object into sed string | escape dots', () => {
    const result = transformContextIntoSedString({ host: '127.0.0.1' })
    expect(result).toBe(' | sed s.#{host}.127\\\\.0\\\\.0\\\\.1.g')
  })

  it('return empty strings | {}', () => {
    const result = transformContextIntoSedString({})
    expect(result).toBe('')
  })

  it('return empty strings | undefined', () => {
    const result = transformContextIntoSedString()
    expect(result).toBe('')
  })

  it('return empty strings | wrong input', () => {
    const result = transformContextIntoSedString('wrong')
    expect(result).toBe('')
  })
})

describe('execPromise', () => {
  it('return a promise with command', () => {
    execPromise('ls -al').then(cmd => {
      expect(cmd).toBe('ls -al')
    })
  })
})

describe('logger', () => {
  it('info | split arguments with newline', () => {
    const args = logger.info('first message', 'second message')
    expect(args).toBe('first message\n  second message')
  })

  it('info | pritn 2 times', () => {
    let counter = 0
    global.console.log = jest.fn(() => counter++)
    logger.info('first message', 'second message')
    expect(console.log).toHaveBeenCalled()
    expect(counter).toBe(2)
  })

  it('error | print 7 times and exit process', () => {
    let counter = 0
    let exited = false
    global.console.error = jest.fn(() => counter++)
    global.process.exit = jest.fn(() => { exited = true })
    logger.error(new Error('message'), 1)
    expect(console.log).toHaveBeenCalled()
    expect(counter).toBe(7)
    expect(exited).toBe(true)
  })

  /**
   * Unable to mock process.env.YAGG_DEBUG for ONLY this test
   * It changes for all tests :(
   */
  it('error | print 8 when isVerboseEnabled', () => {
    let counter = 0
    let exited = false
    // global.process.env.YAGG_DEBUG = 'verbose'
    global.console.error = jest.fn(() => counter++)
    global.process.exit = jest.fn(() => { exited = true })
    logger.error(new Error('message'), 1)
    expect(console.log).toHaveBeenCalled()
    expect(counter).toBe(7) // this should be 10?
    expect(exited).toBe(true)
    // global.process.env.YAGG_DEBUG = ''
  })
})

describe('getGlobalDependencies', () => {
  it('todo: write test', () => {
  })
})

describe('installDependencies', () => {
  it('todo: write test', () => {
  })
})

describe('transformContextIntoSedString', () => {
  it('todo: write test', () => {
  })
})

describe('replaceAll', () => {
  it('replace token with hello', () => {
    const result = replaceAll('#{token} world', '#{token}', 'hello')
    expect(result).toBe('hello world')
  })
})
<commit_msg>todo: tests<commit_after>
const utils = require('../')
const sanitize = utils.sanitize
const transformContextIntoSedString = utils.transformContextIntoSedString
const execPromise = utils.execPromise
const logger = utils.logger
// const installDependencies = utils.installDependencies
// const getGlobalDependencies = utils.getGlobalDependencies
// const transformContextIntoSedString = utils.transformContextIntoSedString
const replaceAll = utils.replaceAll

describe('sanitize', () => {
  it('remove slashes | name', () => {
    const result = sanitize('name')
    expect(result).toBe('name')
  })
  it('remove slashes | /name', () => {
    const result = sanitize('/name')
    expect(result).toBe('name')
  })
  it('remove slashes | /name/', () => {
    const result = sanitize('/name/')
    expect(result).toBe('name')
  })
  it('remove slashes | undefined', () => {
    const result = sanitize()
    expect(result).toBe('')
  })
})

describe('transformContextIntoSedString', () => {
  it('convert object into sed string', () => {
    const result = transformContextIntoSedString({ name: 'test', port: 8080 })
    expect(result).toBe(' | sed s.#{name}.test.g | sed s.#{port}.8080.g')
  })
  it('convert object into sed string | escape dots', () => {
    const result = transformContextIntoSedString({ host: '127.0.0.1' })
    expect(result).toBe(' | sed s.#{host}.127\\\\.0\\\\.0\\\\.1.g')
  })

  it('return empty strings | {}', () => {
    const result = transformContextIntoSedString({})
    expect(result).toBe('')
  })

  it('return empty strings | undefined', () => {
    const result = transformContextIntoSedString()
    expect(result).toBe('')
  })

  it('return empty strings | wrong input', () => {
    const result = transformContextIntoSedString('wrong')
    expect(result).toBe('')
  })
})

describe('execPromise', () => {
  it('return a promise with command', () => {
    execPromise('ls -al').then(cmd => {
      expect(cmd).toBe('ls -al')
    })
  })
})

describe('logger', () => {
  it('info | split arguments with newline', () => {
    const args = logger.info('first message', 'second message')
    expect(args).toBe('first message\n  second message')
  })

  it('info | pritn 2 times', () => {
    let counter = 0
    global.console.log = jest.fn(() => counter++)
    logger.info('first message', 'second message')
    expect(console.log).toHaveBeenCalled()
    expect(counter).toBe(2)
  })

  it('error | print 7 times and exit process', () => {
    let counter = 0
    let exited = false
    global.console.error = jest.fn(() => counter++)
    global.process.exit = jest.fn(() => { exited = true })
    logger.error(new Error('message'), 1)
    expect(console.log).toHaveBeenCalled()
    expect(counter).toBe(7)
    expect(exited).toBe(true)
  })

  it('warning | todo: write test', () => {
  })
  it('success | todo: write test', () => {
  })

  /**
   * Unable to mock process.env.YAGG_DEBUG for ONLY this test
   * It changes for all tests :(
   */
  it('error | print 8 when isVerboseEnabled', () => {
    let counter = 0
    let exited = false
    // global.process.env.YAGG_DEBUG = 'verbose'
    global.console.error = jest.fn(() => counter++)
    global.process.exit = jest.fn(() => { exited = true })
    logger.error(new Error('message'), 1)
    expect(console.log).toHaveBeenCalled()
    expect(counter).toBe(7) // this should be 10?
    expect(exited).toBe(true)
    // global.process.env.YAGG_DEBUG = ''
  })
})

describe('getGlobalDependencies', () => {
  it('todo: write test', () => {
  })
})

describe('installDependencies', () => {
  it('todo: write test', () => {
  })
})

describe('transformContextIntoSedString', () => {
  it('todo: write test', () => {
  })
})

describe('replaceAll', () => {
  it('replace token with hello', () => {
    const result = replaceAll('#{token} world', '#{token}', 'hello')
    expect(result).toBe('hello world')
  })
})

{'fraction_non_alphanumeric': 0.1900246785296792, 'fraction_numerical': 0.008572541888556955, 'mean_word_length': 3.5320776927604474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2626906', 'n_tokens_mistral': 2489, 'n_tokens_neox': 2417, 'n_words': 511}