Revert "added fast-xml-parser for testing"
This reverts commit 15ac52b6a0.
This commit is contained in:
@@ -5,20 +5,22 @@ describe('XML Parser', () => {
|
||||
it('should parse simple tag', () => {
|
||||
const xml = '<root></root>';
|
||||
const result = fromXml(xml);
|
||||
expect(result).toEqual({ root: '' });
|
||||
expect(result).toEqual({ tag: 'root', attributes: {}, children: [] });
|
||||
});
|
||||
|
||||
it('should parse self-closing tag', () => {
|
||||
const xml = '<item />';
|
||||
const result = fromXml(xml);
|
||||
expect(result).toEqual({ item: '' });
|
||||
expect(result).toEqual({ tag: 'item', attributes: {}, children: [] });
|
||||
});
|
||||
|
||||
it('should parse tag with attributes', () => {
|
||||
const xml = '<user id="1" name="someone" />';
|
||||
const result = fromXml(xml);
|
||||
expect(result).toEqual({
|
||||
user: { '@_id': '1', '@_name': 'someone' }
|
||||
tag: 'user',
|
||||
attributes: { id: '1', name: 'someone' },
|
||||
children: []
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +28,9 @@ describe('XML Parser', () => {
|
||||
const xml = '<email>someone@example.com</email>';
|
||||
const result = fromXml(xml);
|
||||
expect(result).toEqual({
|
||||
email: 'someone@example.com'
|
||||
tag: 'email',
|
||||
attributes: {},
|
||||
children: ['someone@example.com']
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,75 +38,54 @@ describe('XML Parser', () => {
|
||||
const xml = '<root><child>text</child></root>';
|
||||
const result = fromXml(xml);
|
||||
expect(result).toEqual({
|
||||
root: {
|
||||
child: 'text'
|
||||
}
|
||||
tag: 'root',
|
||||
attributes: {},
|
||||
children: [
|
||||
{ tag: 'child', attributes: {}, children: ['text'] }
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse multiple children', () => {
|
||||
const xml = '<root><a /><b /><c /></root>';
|
||||
const result = fromXml(xml);
|
||||
expect(result.root.a).toBe('');
|
||||
expect(result.root.b).toBe('');
|
||||
expect(result.root.c).toBe('');
|
||||
});
|
||||
|
||||
it('should parse repeated tags as arrays', () => {
|
||||
const xml = '<root><item>1</item><item>2</item><item>3</item></root>';
|
||||
const result = fromXml(xml);
|
||||
expect(result).toEqual({
|
||||
root: {
|
||||
item: ['1', '2', '3']
|
||||
}
|
||||
});
|
||||
expect(result.children.length).toBe(3);
|
||||
expect(result.children[0]).toEqual({ tag: 'a', attributes: {}, children: [] });
|
||||
});
|
||||
|
||||
it('should skip XML declaration', () => {
|
||||
const xml = '<?xml version="1.0"?><root />';
|
||||
const result = fromXml(xml);
|
||||
expect(result.root).toBe('');
|
||||
expect(result.tag).toBe('root');
|
||||
});
|
||||
|
||||
it('should skip comments', () => {
|
||||
const xml = '<root><!-- comment --><child /></root>';
|
||||
const result = fromXml(xml);
|
||||
expect(result).toEqual({
|
||||
root: { child: '' }
|
||||
});
|
||||
expect(result.children.length).toBe(1);
|
||||
expect(result.children[0].tag).toBe('child');
|
||||
});
|
||||
|
||||
it('should handle escaped characters', () => {
|
||||
const xml = '<text><hello> & "world"</text>';
|
||||
const result = fromXml(xml);
|
||||
expect(result.text).toBe('<hello> & "world"');
|
||||
});
|
||||
|
||||
it('should parse tag with attributes and text', () => {
|
||||
const xml = '<user id="1">John</user>';
|
||||
const result = fromXml(xml);
|
||||
expect(result).toEqual({
|
||||
user: {
|
||||
'@_id': '1',
|
||||
'#text': 'John'
|
||||
}
|
||||
});
|
||||
expect(result.children[0]).toBe('<hello> & "world"');
|
||||
});
|
||||
|
||||
it('should parse complex nested structure', () => {
|
||||
const xml = `
|
||||
<root>
|
||||
<user id="1" name="someone">
|
||||
<email>someone@example.com</email>
|
||||
<active />
|
||||
</user>
|
||||
</root>
|
||||
`;
|
||||
<root>
|
||||
<user id="1" name="someone">
|
||||
<email>someone@example.com</email>
|
||||
<active />
|
||||
</user>
|
||||
</root>
|
||||
`;
|
||||
const result = fromXml(xml);
|
||||
expect(result.root.user['@_id']).toBe('1');
|
||||
expect(result.root.user['@_name']).toBe('someone');
|
||||
expect(result.root.user.email).toBe('someone@example.com');
|
||||
expect(result.root.user.active).toBe('');
|
||||
expect(result.tag).toBe('root');
|
||||
expect(result.children[0].tag).toBe('user');
|
||||
expect(result.children[0].attributes.name).toBe('someone');
|
||||
expect(result.children[0].children.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user