<commit_before>/** @jsx createElement */
/* eslint-env mocha */

import { createElement, Phrase } from 'lacona-phrase'
import { expect } from 'chai'
import { text } from './_util'
import { DateDuration } from '..'
import { Parser } from 'lacona'

describe('date-duration', () => {
  let parser

  beforeEach(() => {
    parser = new Parser()
    parser.grammar = <DateDuration />
  })

  it('1 day', () => {
    const data = parser.parseArray('1 day')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('1 day')
    expect(data[0].result).to.eql({days: 1})
  })

  it('x days', () => {
    const data = parser.parseArray('3 days')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('3 days')
    expect(data[0].result).to.eql({days: 3})
  })

  it('1 week', () => {
    const data = parser.parseArray('1 week')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('1 week')
    expect(data[0].result).to.eql({days: 7})
  })

  it('x weeks', () => {
    const data = parser.parseArray('3 weeks')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('3 weeks')
    expect(data[0].result).to.eql({days: 21})
  })

  it('1 year', () => {
    const data = parser.parseArray('1 year')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('1 year')
    expect(data[0].result).to.eql({years: 1})
  })

  it('x days', () => {
    const data = parser.parseArray('3 years')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('3 years')
    expect(data[0].result).to.eql({years: 3})
  })

  it('1 year', () => {
    const data = parser.parseArray('1 month')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('1 month')
    expect(data[0].result).to.eql({months: 1})
  })

  it('x days', () => {
    const data = parser.parseArray('3 months')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('3 months')
    expect(data[0].result).to.eql({months: 3})
  })

  it('x years and 1 month', () => {
    const data = parser.parseArray('2 years and 1 month')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('2 years and 1 month')
    expect(data[0].result).to.eql({years: 2, months: 1})
  })

  it('1 year and x days', () => {
    const data = parser.parseArray('1 year and 11 months')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('1 year and 11 months')
    expect(data[0].result).to.eql({years: 1, months: 11})
  })

  it('x years, x months, and 1 day', () => {
    const data = parser.parseArray('2 years, 6 months, and 1 day')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('2 years, 6 months, and 1 day')
    expect(data[0].result).to.eql({years: 2, months: 6, days: 1})
  })

  it('x years, x months, and x weeks', () => {
    const data = parser.parseArray('2 years, 6 months, and 2 weeks')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('2 years, 6 months, and 2 weeks')
    expect(data[0].result).to.eql({years: 2, months: 6, days: 14})
  })

  it('x weeks and x days', () => {
    const data = parser.parseArray('3 weeks and 4 days')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('3 weeks and 4 days')
    expect(data[0].result).to.eql({days: 25})
  })

  it('x weeks and x years', () => {
    const data = parser.parseArray('2 weeks and 3 years')
    expect(data).to.have.length(2)
    expect(text(data[0])).to.equal('2 weeks and 3 years')
    expect(data[0].result).to.eql({years: 3, days: 14})
  })

  it('x years and x years', () => {
    const data = parser.parseArray('2 years and 3 years')
    expect(data).to.have.length(0)
  })
})<commit_msg>Refactor date duration tests<commit_after>/** @jsx createElement */
/* eslint-env mocha */

import _ from 'lodash'
import { createElement, Phrase } from 'lacona-phrase'
import { expect } from 'chai'
import { text } from './_util'
import { DateDuration } from '..'
import { Parser } from 'lacona'

describe('date-duration', () => {
  let parser

  beforeEach(() => {
    parser = new Parser()
    parser.grammar = <DateDuration />
  })

  const testCases = [
    {input: '1 day', output: {days: 1}},
    {input: '3 days', output: {days: 3}},
    {input: '1 week', output: {days: 7}},
    {input: '3 weeks', output: {days: 21}},
    {input: '1 year', output: {years: 1}},
    {input: '3 years', output: {years: 3}},
    {input: '1 month', output: {months: 1}},
    {input: '3 months', output: {months: 3}},
    {input: '2 years and 1 month', output: {years: 2, months: 1}},
    {input: '1 year and 11 months', output: {years: 1, months: 11}},
    {input: '2 years, 6 months, and 1 day', output: {years: 2, months: 6, days: 1}},
    {input: '2 years, 6 months, and 2 weeks', output: {years: 2, months: 6, days: 14}},
    {input: '3 weeks and 4 days', output: {days: 25}},
    {input: '2 weeks and 3 years', output: {years: 3, days: 14}},
    {input: '2 years and 3 years', length: 0}
  ]

  _.forEach(testCases, ({input, output, length = 1 }) => {
    it(input, () => {
      const data = _.filter(parser.parseArray(input), output => !_.some(output.words, 'placeholder'))
      expect(data).to.have.length(length)
      if (length > 1) {
        expect(text(data[0])).to.equal(input)
        expect(data[0].result).to.equalDate(output)
      }
    })
  })
})
{'fraction_non_alphanumeric': 0.20798358515202386, 'fraction_numerical': 0.03357582540570789, 'mean_word_length': 3.3346806790622474, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6682092', 'n_tokens_mistral': 2057, 'n_tokens_neox': 1926, 'n_words': 469}