import { describe, it, expect } from 'vitest';
import { serialize, deserialize } from '../../src/types/application/xml';
describe('application/xml', () => {
describe('serialize', () => {
it('should serialize a string', () => {
const result = serialize('Hello, World!', { type: 'application/xml' });
expect(result).toBe('Hello, World!');
});
it('should serialize a number', () => {
const result = serialize(123, { type: 'application/xml' });
expect(result).toBe('123');
});
it('should serialize a boolean', () => {
const result = serialize(true, { type: 'application/xml' });
expect(result).toBe('true');
});
it('should serialize an array', () => {
const result = serialize([1, 2, 3], { type: 'application/xml' });
expect(result).toBe('<_0 type="number">1<_1 type="number">2<_2 type="number">3');
});
it('should serialize an object', () => {
const result = serialize({ a: 1, b: 2, c: 3 }, { type: 'application/xml' });
expect(result).toBe('123');
});
it('should serialize an object with a custom root element name', () => {
const result = serialize({ a: 1, b: 2, c: 3 }, { type: 'application/xml', rootElementName: 'fsh', });
expect(result).toBe('123');
});
it('should serialize an object with indent', () => {
const result = serialize({ a: 1, b: 2, c: 3 }, { type: 'application/xml', indent: 2 });
expect(result).toBe(`
1
2
3
`);
});
});
describe('deserialize', () => {
it('should deserialize a string', () => {
const result = deserialize('Hello, World!', { type: 'application/xml' });
expect(result).toBe('Hello, World!');
});
it('should deserialize a number', () => {
const result = deserialize('123', { type: 'application/xml' });
expect(result).toBe(123);
});
it('should deserialize a boolean', () => {
const result = deserialize('true', { type: 'application/xml' });
expect(result).toBe(true);
});
it('should deserialize an array', () => {
const result = deserialize('<_0 type="number">1<_1 type="number">2<_2 type="number">3', { type: 'application/xml' });
expect(result).toEqual([1, 2, 3]);
});
it('should deserialize an object', () => {
const result = deserialize<{ a: number, b: number, c: number }>(
'123',
{ type: 'application/xml' },
);
expect(result).toEqual({ a: 1, b: 2, c: 3 });
});
});
});