<commit_before>import * as Util from '../../src/util'
import shallowEqual from '../../src/util/shallow-equal'
import nextTick from '../../src/util/next-tick'
import SimpleMap from '../../src/util/simple-map'

describe('Util', () => {
  const Proto = () => ({})
  Proto.prototype.b = 'b'

  it('types', () => {
    const a = 1
    const b = 'b'
    const c = () => {}
    const d = {}
    const f = [1, 2, 3]
    const h = false

    expect(Util.isNumber(a)).toBeTruthy()
    expect(Util.isString(b)).toBeTruthy()
    expect(Util.isFunction(c)).toBeTruthy()
    expect(Util.isObject(d)).toBeTruthy()
    expect(Util.isArray(f)).toBeTruthy()
    expect(Util.isBoolean(h)).toBeTruthy()
  })

  it('isEmptyObject', () => {
    expect(Util.isEmptyObject({a: 1})).not.toBeTruthy()
    expect(Util.isEmptyObject({})).toBeTruthy()
    expect(Util.isEmptyObject(null)).toBeTruthy()
    expect(Util.isEmptyObject(undefined)).toBeTruthy()
  })

  it('isNative', () => {
    function a () {}
    expect(Util.isNative(a)).not.toBeTruthy()
    expect(Util.isNative(Array)).toBeTruthy()
  })

  it('extend && clone', () => {
    const a = { a: 1, b: 2 }
    Util.extend(a, { c: 1 })
    expect(a.a).toBe(1)
    expect(a.b).toBe(2)
    expect(a.c).toBe(1)
    expect(a.d).not.toBeDefined()

    Util.extend(a, { a: 2 })
    expect(a).toEqual({a: 2, b: 2, c: 1})

    Util.extend(a, { a: { aa: 1, bb: 2 } })
    expect(a).toEqual({a: { aa: 1, bb: 2 }, b: 2, c: 1})

    const b = Util.clone(a)
    expect(b).toEqual({a: { aa: 1, bb: 2 }, b: 2, c: 1})
    b.b = 10
    expect(b.b).toBe(10)
    expect(a.b).toBe(2)
    const f = new Proto()
    Util.extend({}, f)
    expect(f.b).not.toBeDefined()
  })

  it('shallowEqual', () => {
    const a = {a: 1}
    const b = {a: 2}
    const c = {a: 1}
    const d = {a: 1, v: []}
    const e = {a: 1, v: []}
    const arr1 = []
    const f = {a: 1, v: arr1}
    const g = {a: 1, v: arr1}
    expect(shallowEqual(a, b)).not.toBeTruthy()
    expect(shallowEqual(null, 110)).toBeFalsy()
    expect(shallowEqual(+0, -0)).toBeTruthy()
    expect(shallowEqual([], [1])).toBeFalsy()
    expect(shallowEqual(a, c)).toBeTruthy()
    expect(shallowEqual(d, e)).not.toBeTruthy()
    expect(shallowEqual(f, g)).toBeTruthy()
  })

  describe('nextTick', () => {
    const canUsePromise = (() => {
      return 'Promise' in window && isNative(Promise)
    })()
    function isNative (Ctor) {
      return typeof ctor === 'function' && /native code/.test(Ctor.toString())
    }
    it('accepts a callback', done => {
      nextTick(done)
    })

    it('returns a Promise when provided no callback', done => {
      if (!canUsePromise) {
        done()
      }
      nextTick().then(done)
    })

    it('throw error in callback can carry on', done => {
      nextTick(() => {
        throw new Error('e')
      })
      done()
    })
  })

  describe('simpleMap', () => {
    const map = new SimpleMap()<commit_msg>test: dont use promise in IE<commit_after>import * as Util from '../../src/util'
import shallowEqual from '../../src/util/shallow-equal'
import nextTick from '../../src/util/next-tick'
import SimpleMap from '../../src/util/simple-map'

describe('Util', () => {
  const Proto = () => ({})
  Proto.prototype.b = 'b'

  it('types', () => {
    const a = 1
    const b = 'b'
    const c = () => {}
    const d = {}
    const f = [1, 2, 3]
    const h = false

    expect(Util.isNumber(a)).toBeTruthy()
    expect(Util.isString(b)).toBeTruthy()
    expect(Util.isFunction(c)).toBeTruthy()
    expect(Util.isObject(d)).toBeTruthy()
    expect(Util.isArray(f)).toBeTruthy()
    expect(Util.isBoolean(h)).toBeTruthy()
  })

  it('isEmptyObject', () => {
    expect(Util.isEmptyObject({a: 1})).not.toBeTruthy()
    expect(Util.isEmptyObject({})).toBeTruthy()
    expect(Util.isEmptyObject(null)).toBeTruthy()
    expect(Util.isEmptyObject(undefined)).toBeTruthy()
  })

  it('isNative', () => {
    function a () {}
    expect(Util.isNative(a)).not.toBeTruthy()
    expect(Util.isNative(Array)).toBeTruthy()
  })

  it('extend && clone', () => {
    const a = { a: 1, b: 2 }
    Util.extend(a, { c: 1 })
    expect(a.a).toBe(1)
    expect(a.b).toBe(2)
    expect(a.c).toBe(1)
    expect(a.d).not.toBeDefined()

    Util.extend(a, { a: 2 })
    expect(a).toEqual({a: 2, b: 2, c: 1})

    Util.extend(a, { a: { aa: 1, bb: 2 } })
    expect(a).toEqual({a: { aa: 1, bb: 2 }, b: 2, c: 1})

    const b = Util.clone(a)
    expect(b).toEqual({a: { aa: 1, bb: 2 }, b: 2, c: 1})
    b.b = 10
    expect(b.b).toBe(10)
    expect(a.b).toBe(2)
    const f = new Proto()
    Util.extend({}, f)
    expect(f.b).not.toBeDefined()
  })

  it('shallowEqual', () => {
    const a = {a: 1}
    const b = {a: 2}
    const c = {a: 1}
    const d = {a: 1, v: []}
    const e = {a: 1, v: []}
    const arr1 = []
    const f = {a: 1, v: arr1}
    const g = {a: 1, v: arr1}
    expect(shallowEqual(a, b)).not.toBeTruthy()
    expect(shallowEqual(null, 110)).toBeFalsy()
    expect(shallowEqual(+0, -0)).toBeTruthy()
    expect(shallowEqual([], [1])).toBeFalsy()
    expect(shallowEqual(a, c)).toBeTruthy()
    expect(shallowEqual(d, e)).not.toBeTruthy()
    expect(shallowEqual(f, g)).toBeTruthy()
  })

  describe('nextTick', () => {
    const canUsePromise = (() => {
      return 'Promise' in window && isNative(Promise)
    })()
    function isNative (Ctor) {
      return typeof ctor === 'function' && /native code/.test(Ctor.toString())
    }
    it('accepts a callback', done => {
      nextTick(done)
    })

    it('returns a Promise when provided no callback', done => {
      const ua = navigator.userAgent.match(/MSIE (\d+)/)
      if (!canUsePromise || ua !== null) {
        done()
      }
      nextTick().then(done)
    })

    it('throw error in callback can carry on', done => {
      nextTick(() => {
        throw new Error('e')
      })
      done()
    })
  })

  describe('simpleMap', () => {
    const map = new SimpleMap()
{'fraction_non_alphanumeric': 0.20862097996295673, 'fraction_numerical': 0.015490823370937868, 'mean_word_length': 2.684863523573201, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '2101633', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2222, 'n_words': 456}