import { describe, expect, it } from 'vitest'
import { hashSource } from './hash.js'

describe('hashSource', () => {
  it('returns the same hex output for the same input', async () => {
    const a = await hashSource('hello world')
    const b = await hashSource('hello world')
    expect(a).toBe(b)
    expect(a).toMatch(/^[0-9a-f]{64}$/)
  })

  it('returns different hashes for different text', async () => {
    const a = await hashSource('hello')
    const b = await hashSource('world')
    expect(a).not.toBe(b)
  })

  it('treats NFC-equivalent strings as the same hash', async () => {
    const composed = 'e\u0301' // e + combining acute
    const precomposed = '\u00e9' // é
    expect(await hashSource(composed)).toBe(await hashSource(precomposed))
  })

  it('treats trim-equivalent strings as the same hash', async () => {
    expect(await hashSource('  hello  ')).toBe(await hashSource('hello'))
  })
})
