<commit_before>mocha = require 'mocha'
chai = require 'chai'
expect = chai.expect
minim = require '../src/primitives'

describe 'Minim Primitives', ->
  describe 'convertToType', ->
    typeCheck = (name, val) ->
      returnedType = undefined

      context 'when given '+name, ->
        before ->
          returnedType = minim.convertToType(val)

        it 'returns '+name, ->
          expect(returnedType.elementType()).to.equal name

    typeCheck('null', null)
    typeCheck('string', 'foobar')
    typeCheck('number', 1)
    typeCheck('boolean', true)
    typeCheck('array', [1, 2, 3])
    typeCheck('object', { foo: 'bar' })

  describe 'convertFromType', ->
    typeCheck = (name, el) ->
      context 'when given '+name, ->
        returnedType = undefined

        before ->
          returnedType = minim.convertFromDom el

        it 'returns '+name+' element', ->
          expect(returnedType.elementType()).to.equal name

        it 'has the correct value', ->
          expect(returnedType.toValue()).to.equal el.content

    typeCheck 'null',
      element: 'null'
      attributes: {}
      content: null

    typeCheck 'string',
      element: 'string'
      attributes: {}
      content: 'foo'

    typeCheck 'number',
      element: 'number'
      attributes: {}
      content: 4

    typeCheck 'boolean',
      element: 'boolean'
      attributes: {}
      content: true

    context 'when give property', ->
      returnedType = undefined
      el = undefined

      # { foo: 'bar' }
      el =
        element: 'property'
        attributes:
          name: 'foo'
        content:
          element: 'string'
          attributes: {}
          content: 'bar'

      before ->
        returnedType = minim.convertFromDom el

      it 'returns property element', ->
        expect(returnedType.elementType()).to.equal 'property'

      it 'has the correct value', ->
        expect(returnedType.toValue()).to.equal el.content.content

      it 'has the right attributes', ->
        expect(returnedType.attributes).to.deep.equal el.attributes

    context 'when give array', ->
      returnedType = undefined
      el = undefined

      # [1, 2]
      el =
        element: 'array'
        attributes: {}
        content: [
          element: 'number'
          attributes: {}
          content: 1
        ,
          element: 'number'
          attributes: {}
          content: 2
         ]

      before ->
        returnedType = minim.convertFromDom el

      it 'returns array element', ->
        expect(returnedType.elementType()).to.equal 'array'

      it 'has the correct values', ->
        expect(returnedType.toValue()).to.deep.equal [ 1, 2 ]

    context 'when give array', ->
      returnedType = undefined
      el = undefined

      # { foo: 'bar', z: 2 }
      el =
        element: 'object'
        attributes: {}
        content: [
          element: 'property'
          attributes:
            name: 'foo'
          content:
            element: 'string'
            attributes: {}
            content: 'bar'
        ,
          element: 'property'
          attributes:
            name: 'z'
          content:
            element: 'number'
            attributes: {}
            content: 2
         ]

      before ->
        returnedType = minim.convertFromDom el

      it 'returns array element', ->
        expect(returnedType.elementType()).to.equal 'object'

      it 'has the correct values', -><commit_msg>Fix wording on tests<commit_after>mocha = require 'mocha'
chai = require 'chai'
expect = chai.expect
minim = require '../src/primitives'

describe 'Minim Primitives', ->
  describe 'convertToType', ->
    typeCheck = (name, val) ->
      returnedType = undefined

      context 'when given '+name, ->
        before ->
          returnedType = minim.convertToType(val)

        it 'returns '+name, ->
          expect(returnedType.elementType()).to.equal name

    typeCheck('null', null)
    typeCheck('string', 'foobar')
    typeCheck('number', 1)
    typeCheck('boolean', true)
    typeCheck('array', [1, 2, 3])
    typeCheck('object', { foo: 'bar' })

  describe 'convertFromType', ->
    typeCheck = (name, el) ->
      context 'when given '+name, ->
        returnedType = undefined

        before ->
          returnedType = minim.convertFromDom el

        it 'returns '+name+' element', ->
          expect(returnedType.elementType()).to.equal name

        it 'has the correct value', ->
          expect(returnedType.toValue()).to.equal el.content

    typeCheck 'null',
      element: 'null'
      attributes: {}
      content: null

    typeCheck 'string',
      element: 'string'
      attributes: {}
      content: 'foo'

    typeCheck 'number',
      element: 'number'
      attributes: {}
      content: 4

    typeCheck 'boolean',
      element: 'boolean'
      attributes: {}
      content: true

    context 'when give property', ->
      returnedType = undefined
      el = undefined

      # { foo: 'bar' }
      el =
        element: 'property'
        attributes:
          name: 'foo'
        content:
          element: 'string'
          attributes: {}
          content: 'bar'

      before ->
        returnedType = minim.convertFromDom el

      it 'returns property element', ->
        expect(returnedType.elementType()).to.equal 'property'

      it 'has the correct value', ->
        expect(returnedType.toValue()).to.equal el.content.content

      it 'has the right attributes', ->
        expect(returnedType.attributes).to.deep.equal el.attributes

    context 'when given array', ->
      returnedType = undefined
      el = undefined

      # [1, 2]
      el =
        element: 'array'
        attributes: {}
        content: [
          element: 'number'
          attributes: {}
          content: 1
        ,
          element: 'number'
          attributes: {}
          content: 2
         ]

      before ->
        returnedType = minim.convertFromDom el

      it 'returns array element', ->
        expect(returnedType.elementType()).to.equal 'array'

      it 'has the correct values', ->
        expect(returnedType.toValue()).to.deep.equal [ 1, 2 ]

    context 'when given object', ->
      returnedType = undefined
      el = undefined

      # { foo: 'bar', z: 2 }
      el =
        element: 'object'
        attributes: {}
        content: [
          element: 'property'
          attributes:
            name: 'foo'
          content:
            element: 'string'
            attributes: {}
            content: 'bar'
        ,
          element: 'property'
          attributes:
            name: 'z'
          content:
            element: 'number'
            attributes: {}
            content: 2
         ]

      before ->
        returnedType = minim.convertFromDom el

      it 'returns object element', ->
        expect(returnedType.elementType()).to.equal 'object'

      it 'has the correct values', ->
{'fraction_non_alphanumeric': 0.12105490704712495, 'fraction_numerical': 0.003746937599077677, 'mean_word_length': 1.80517380759903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, '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': '7458500', 'n_tokens_mistral': 1947, 'n_tokens_neox': 1871, 'n_words': 497}