import { describe, test, expect } from 'vitest'
import StringUtils from '~/services/utils/stringUtils'

describe('normalize', () => {
  test('simple cases', () => {
    const assertEqual = (input: string, expected: string) => {
      expect(StringUtils.normalize(input)).toBe(expected)
    }

    assertEqual('abc', 'abc')
    assertEqual('ABC', 'abc')
    assertEqual('éçï', 'eci')
    assertEqual('éèẽëê-ç-îïĩ-àã-öôõ-ûüũ', 'eeeee c iii aa ooo uuu')
    assertEqual('  abc   ', 'abc')
  })
})

describe('parseInt', () => {
  test('simple cases', () => {
    expect(StringUtils.parseInt(6)).toBe(6)
    expect(StringUtils.parseInt('6')).toBe(6)
  })
})

describe('hash', () => {
  test('simple cases', async () => {
    expect(await StringUtils.hash('azerty')).toBe(
      'f2d81a260dea8a100dd517984e53c56a7523d96942a834b9cdc249bd4e8c7aa9',
    )
    expect(await StringUtils.hash('azerty', 'SHA-1')).toBe(
      '9cf95dacd226dcf43da376cdb6cbba7035218921',
    )
  })
})
