<commit_before>"use strict"

const expect = require('expect')
const createVerge3ChrLoader = require('./createVerge3ChrLoader')
const fill = require('lodash/fill')
const zlib = require('zlib')

const signature = 5392451
const version = 5
const flags = 1
const tcol = 2
const hx = 3
const hy = 4
const hw = 5
const hh = 6
const fxsize = 7
const fysize = 8
const totalframes = 9
const didle = 10
const uidle = 11
const lidle = 12
const ridle = 13
const customscripts = 14
const compression = 15
const imagedata = fill(Array(fxsize * fysize * 4 * totalframes), 99)
const imagedataCompressed = [...zlib.deflateSync(Buffer.from(imagedata))]

const chrs = Buffer.concat([
  Buffer.from(new Uint32Array([
    signature,
    version,
    32, // bpp
    flags,
    tcol,
    hx, hy, hw, hh,
    fxsize, fysize,
    totalframes,
    didle, uidle, lidle, ridle,
  ]).buffer),
  Buffer.from(new Uint32Array([2]).buffer),
  Buffer.from('F0\0'),
  Buffer.from(new Uint32Array([2]).buffer),
  Buffer.from('F1\0'),
  Buffer.from(new Uint32Array([2]).buffer),
  Buffer.from('F2\0'),
  Buffer.from(new Uint32Array([2]).buffer),
  Buffer.from('F3\0'),
  Buffer.from(new Uint32Array([2]).buffer),
  Buffer.from('F4\0'),
  Buffer.from(new Uint32Array([2]).buffer),
  Buffer.from('F5\0'),
  Buffer.from(new Uint32Array([2]).buffer),
  Buffer.from('F6\0'),
  Buffer.from(new Uint32Array([2]).buffer),
  Buffer.from('F7\0'),
  Buffer.from(new Uint32Array([customscripts, compression]).buffer),
  Buffer.from(new Uint32Array([imagedata.length, imagedataCompressed.length]).buffer),
  Buffer.from(imagedataCompressed),
])

{
  // can read chrs
  const loader = createVerge3ChrLoader({
    data: Buffer.from(chrs)
  })

  const data = loader.load()

  expect(data.signature).toBe(signature)
  expect(data.version).toBe(version)
  expect(data.bpp).toBe(32)
  expect(data.flags).toBe(flags)
  expect(data.tcol).toBe(tcol)
  expect(data.hx).toBe(hx)
  expect(data.hy).toBe(hy)
  expect(data.hw).toBe(hw)
  expect(data.hh).toBe(hh)
  expect(data.fxsize).toBe(fxsize)
  expect(data.fysize).toBe(fysize)
  expect(data.totalframes).toBe(totalframes)
  expect(data.didle).toBe(10)
  expect(data.uidle).toBe(11)
  expect(data.lidle).toBe(12)
  expect(data.ridle).toBe(13)
  expect(data.anims).toEqual([
    {length: 2, animbuf: 'F0'},
    {length: 2, animbuf: 'F1'},<commit_msg>simplify<commit_after>"use strict"

const expect = require('expect')
const createVerge3ChrLoader = require('./createVerge3ChrLoader')
const fill = require('lodash/fill')
const zlib = require('zlib')
const {makeBuffer, B} = require('../makeBuffer')

const signature = 5392451
const version = 5
const flags = 1
const tcol = 2
const hx = 3
const hy = 4
const hw = 5
const hh = 6
const fxsize = 7
const fysize = 8
const totalframes = 9
const didle = 10
const uidle = 11
const lidle = 12
const ridle = 13
const customscripts = 14
const compression = 15
const imagedata = fill(Array(fxsize * fysize * 4 * totalframes), 99)
const imagedataCompressed = [...zlib.deflateSync(Buffer.from(imagedata))]

const chrs = makeBuffer([
  B.u32([
    signature,
    version,
    32, // bpp
    flags,
    tcol,
    hx, hy, hw, hh,
    fxsize, fysize,
    totalframes,
    didle, uidle, lidle, ridle,
  ]),
  B.u32(2), B.string('F0\0'),
  B.u32(2), B.string('F1\0'),
  B.u32(2), B.string('F2\0'),
  B.u32(2), B.string('F3\0'),
  B.u32(2), B.string('F4\0'),
  B.u32(2), B.string('F5\0'),
  B.u32(2), B.string('F6\0'),
  B.u32(2), B.string('F7\0'),
  B.u32([customscripts, compression]),
  B.u32([imagedata.length, imagedataCompressed.length]),
  B.u8(imagedataCompressed),
])

{
  // can read chrs
  const loader = createVerge3ChrLoader({
    data: chrs
  })

  const data = loader.load()

  expect(data.signature).toBe(signature)
  expect(data.version).toBe(version)
  expect(data.bpp).toBe(32)
  expect(data.flags).toBe(flags)
  expect(data.tcol).toBe(tcol)
  expect(data.hx).toBe(hx)
  expect(data.hy).toBe(hy)
  expect(data.hw).toBe(hw)
  expect(data.hh).toBe(hh)
  expect(data.fxsize).toBe(fxsize)
  expect(data.fysize).toBe(fysize)
  expect(data.totalframes).toBe(totalframes)
  expect(data.didle).toBe(10)
  expect(data.uidle).toBe(11)
  expect(data.lidle).toBe(12)
  expect(data.ridle).toBe(13)
  expect(data.anims).toEqual([
    {length: 2, animbuf: 'F0'},
    {length: 2, animbuf: 'F1'},
{'fraction_non_alphanumeric': 0.1695621959694232, 'fraction_numerical': 0.045170257123002086, 'mean_word_length': 4.259439707673569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1676851', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1666, 'n_words': 321}