Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869/** * Tests for base64ToArrayBuffer utility function. * * Obsidian API: `function base64ToArrayBuffer(base64: string): ArrayBuffer` */import { describe, it, expect } from 'vitest'import { base64ToArrayBuffer } from '../obsidian-stubs'
describe('base64ToArrayBuffer', () => { it('returns empty ArrayBuffer for empty string', () => { const buffer = base64ToArrayBuffer('') expect(buffer.byteLength).toBe(0) })
it('decodes "AA==" to single zero byte', () => { // "AA==" is base64 for [0x00] const buffer = base64ToArrayBuffer('AA==') const bytes = new Uint8Array(buffer) expect(bytes.length).toBe(1) expect(bytes[0]).toBe(0x00) })
it('decodes "/w==" to single byte 0xff', () => { // "/w==" is base64 for [0xff] const buffer = base64ToArrayBuffer('/w==') const bytes = new Uint8Array(buffer) expect(bytes.length).toBe(1) expect(bytes[0]).toBe(0xff) })
it('decodes multi-byte base64 string', () => { // "SGVsbG8=" is base64 for "Hello" const buffer = base64ToArrayBuffer('SGVsbG8=') const bytes = new Uint8Array(buffer) expect(bytes.length).toBe(5) expect(String.fromCharCode(...bytes)).toBe('Hello') })
it('handles base64 without padding', () => { // Some base64 strings don't need padding (when length is divisible by 3) // "YWJj" is base64 for "abc" (no padding needed) const buffer = base64ToArrayBuffer('YWJj') const bytes = new Uint8Array(buffer) expect(String.fromCharCode(...bytes)).toBe('abc') })
it('handles binary data roundtrip', () => { // Test that we can correctly decode arbitrary binary data // "3q2+7w==" is base64 for [0xde, 0xad, 0xbe, 0xef] const buffer = base64ToArrayBuffer('3q2+7w==') const bytes = new Uint8Array(buffer) expect(bytes.length).toBe(4) expect(bytes[0]).toBe(0xde) expect(bytes[1]).toBe(0xad) expect(bytes[2]).toBe(0xbe) expect(bytes[3]).toBe(0xef) })
it('handles longer binary sequences', () => { // "AAECAwQFBgcICQoLDA0ODw==" is base64 for bytes 0x00-0x0f const buffer = base64ToArrayBuffer('AAECAwQFBgcICQoLDA0ODw==') const bytes = new Uint8Array(buffer) expect(bytes.length).toBe(16) for (let i = 0; i < 16; i++) { expect(bytes[i]).toBe(i) } })})