import test from 'node:test';
import assert from 'node:assert/strict';
import { mxesc1Encode, mxesc1Decode } from '@open-matrix/federation/mxesc1';

test('mxesc1 roundtrip: ascii + unicode + spaces', () => {
  const samples = ['hello', 'hello world', 'über', 'foo', 'a/b.c-d_e~'];
  for (const s of samples) {
    const enc = mxesc1Encode(s);
    const dec = mxesc1Decode(enc);
    assert.equal(dec, s);
  }
});

test('mxesc1 encodes unsafe chars', () => {
  assert.equal(mxesc1Encode(' '), '%20');
  assert.equal(mxesc1Encode('#'), '%23');
});
