first commit
This commit is contained in:
48
test/xml-toolcall.test.ts
Executable file
48
test/xml-toolcall.test.ts
Executable file
@@ -0,0 +1,48 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user