import { describe, expect, test } from 'bun:test'
import { readFileSync } from 'node:fs'
import { crop, decodePng, encodePng, pixelHex, zoom } from '../tools/bench/png'
const img = { width: 3, height: 2, data: new Uint8Array([
255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255,
1, 2, 3, 255, 10, 20, 30, 128, 250, 251, 252, 0,
]) }
describe('png', () => {
test('encode then decode round-trips RGBA', () => {
const back = decodePng(encodePng(img))
expect(back.width).toBe(3)
expect(back.height).toBe(2)
expect([...back.data]).toEqual([...img.data])
})
test('crop, zoom and hex', () => {
const c = crop(img, 1, 0, 2, 2)
expect(pixelHex(c, 0, 0)).toBe('#00ff00')
expect(pixelHex(c, 0, 1)).toBe('#0a141e80')
const z = zoom(c, 2)
expect(z.width).toBe(4)
expect(pixelHex(z, 1, 1)).toBe('#00ff00')
expect(pixelHex(z, 2, 3)).toBe('#fafbfc00')
expect(() => crop(img, 2, 0, 2, 1)).toThrow()
})
test('decodes the reference screenshot (filtered RGBA)', () => {
const ref = decodePng(readFileSync('docs/reference/game-manage-125.png'))
expect(ref.width).toBe(1804)
expect(ref.height).toBe(1063)
expect(ref.data.length).toBe(1804 * 1063 * 4)
})
})