49 lines
1.1 KiB
TypeScript
Executable File
49 lines
1.1 KiB
TypeScript
Executable File
import { describe, it, expect } from 'vitest';
|
|
import { parseXmlToolCalls } from '../src/parsers/xml-toolcall';
|
|
|
|
describe('XML ToolCall Parser', () => {
|
|
it('parses basic XML tool call correctly', () => {
|
|
const content = `
|
|
<tool_call>
|
|
<function=read>
|
|
<parameter=path>
|
|
/tmp/test.txt
|
|
</parameter>
|
|
</function>
|
|
</tool_call>
|
|
`;
|
|
|
|
const result = parseXmlToolCalls(content);
|
|
expect(result).toHaveLength(1);
|
|
expect(result[0].name).toBe('read');
|
|
expect(result[0].args).toEqual({ path: '/tmp/test.txt' });
|
|
});
|
|
|
|
it('parses multiple parameters correctly', () => {
|
|
const content = `
|
|
<function=write>
|
|
<parameter=path>
|
|
/tmp/a.txt
|
|
</parameter>
|
|
<parameter=content>
|
|
hello
|
|
</parameter>
|
|
</function>
|
|
`;
|
|
|
|
const result = parseXmlToolCalls(content);
|
|
expect(result).toHaveLength(1);
|
|
expect(result[0].name).toBe('write');
|
|
expect(result[0].args).toEqual({
|
|
path: '/tmp/a.txt',
|
|
content: 'hello'
|
|
});
|
|
});
|
|
|
|
it('ignores normal text', () => {
|
|
const content = `I will read the file. Let me check the system.`;
|
|
const result = parseXmlToolCalls(content);
|
|
expect(result).toHaveLength(0);
|
|
});
|
|
});
|