Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173/** Round-trip and concatenation tests for the UTF-8 byte helpers shipped as `@internal` exports of the built artifact. @module */
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { bytesToString, concatBytes, stringToBytes,} from '../dist/final/neutral/index.mjs';
await describe({ name: 'byte conversions', children: [ it({ name: 'round-trips ASCII text through its exact UTF-8 bytes', fn: async () => { /** ASCII fixture decoded back below. */ const ascii = 'hello config'; /** UTF-8 encoding of the two-letter sample. */ const hiBytes = stringToBytes('hi',);
expect(hiBytes,).toEqual(new Uint8Array([ 104, 105, ],),); /** Round-trip result of the ASCII fixture. */ const decoded = bytesToString(stringToBytes(ascii,),); expect(decoded,).toBe(ascii,); }, },),
it({ name: 'round-trips multi-byte UTF-8 and emoji text through their exact bytes', fn: async () => { /** Mixed-width fixture carrying two-byte, three-byte, and four-byte code points. */ const mixed = 'héllo 世界 🎉'; /** UTF-8 encoding of the accented two-byte sample. */ const accentBytes = stringToBytes('é',); /** UTF-8 encoding of the four-byte emoji sample. */ const emojiBytes = stringToBytes('🎉',);
expect(accentBytes,).toEqual(new Uint8Array([ 195, 169, ],),); expect(emojiBytes,).toEqual(new Uint8Array([ 240, 159, 142, 137, ],),); /** Round-trip result of the mixed-width fixture. */ const decoded = bytesToString(stringToBytes(mixed,),); expect(decoded,).toBe(mixed,); }, },),
it({ name: 'encodes the empty string as zero bytes and decodes empty bytes back', fn: async () => { /** Empty byte buffer decoded back below. */ const emptyBytes = new Uint8Array(0,);
expect(stringToBytes('',),).toHaveLength(0,); expect(bytesToString(emptyBytes,),).toBe('',); }, },),
it({ name: 'concatenates multiple chunks into one buffer in order', fn: async () => { /** Joined result of three consecutive chunks. */ const joined = concatBytes([ new Uint8Array([ 1, 2, ],), new Uint8Array([ 3, ],), new Uint8Array([ 4, 5, ],), ],);
expect(joined,).toEqual(new Uint8Array([ 1, 2, 3, 4, 5, ],),); }, },),
it({ name: 'copies a single chunk into one buffer of its own', fn: async () => { /** Lone chunk handed to `concatBytes`. */ const chunk = new Uint8Array([ 7, 8, 9, ],); /** Result buffer built from the lone chunk. */ const joined = concatBytes([chunk],);
expect(joined === chunk,).toBe(false,); expect(joined,).toEqual(chunk,); }, },),
it({ name: 'returns a zero-length buffer for no chunks', fn: async () => { expect(concatBytes([],),).toHaveLength(0,); }, },),
it({ name: 'agrees with the runtime TextEncoder and TextDecoder on mixed text', fn: async () => { /** Fixture exercising every conversion width at once. */ const mixed = 'abc é 世 🎉'; /** Reference encoding from the runtime itself. */ const expectedBytes = new TextEncoder() .encode(mixed,);
expect(stringToBytes(mixed,),).toEqual(expectedBytes,); expect(bytesToString(expectedBytes,),).toBe(new TextDecoder().decode(expectedBytes,),); }, },), ],},);