diff --git a/test/.snapshots/test/llms/parse-output.ts.md b/test/.snapshots/test/llms/parse-output.test.ts.md similarity index 84% rename from test/.snapshots/test/llms/parse-output.ts.md rename to test/.snapshots/test/llms/parse-output.test.ts.md index 54a5033..e9dba80 100644 --- a/test/.snapshots/test/llms/parse-output.ts.md +++ b/test/.snapshots/test/llms/parse-output.test.ts.md @@ -1,6 +1,6 @@ -# Snapshot report for `test/llms/parse-output.ts` +# Snapshot report for `test/llms/parse-output.test.ts` -The actual snapshot is saved in `parse-output.ts.snap`. +The actual snapshot is saved in `parse-output.test.ts.snap`. Generated by [AVA](https://avajs.dev). @@ -224,3 +224,40 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 'Invalid number output: NotANumber' + +## parseOutput - handles array correctly + +> should parse and return [1, 2, 3] for "[1, 2, 3]" + + [ + 1, + 2, + 3, + ] + +## parseOutput - handles object correctly + +> should parse and return {"a": 1, "b": "two"} for "{"a": 1, "b": "two"}" + + { + a: 1, + b: 'two', + } + +## parseOutput - handles boolean correctly + +> should parse and return true for "True" + + true + +## parseOutput - handles number correctly + +> should parse and return 123.45 for "123.45" + + 123.45 + +## parseOutput - throws error for invalid data + +> Snapshot 1 + + 'Invalid number output: not a number' diff --git a/test/.snapshots/test/llms/parse-output.test.ts.snap b/test/.snapshots/test/llms/parse-output.test.ts.snap new file mode 100644 index 0000000..b0f9151 Binary files /dev/null and b/test/.snapshots/test/llms/parse-output.test.ts.snap differ diff --git a/test/.snapshots/test/llms/parse-output.ts.snap b/test/.snapshots/test/llms/parse-output.ts.snap deleted file mode 100644 index 67e98c6..0000000 Binary files a/test/.snapshots/test/llms/parse-output.ts.snap and /dev/null differ diff --git a/test/llms/parse-output.ts b/test/llms/parse-output.test.ts similarity index 81% rename from test/llms/parse-output.ts rename to test/llms/parse-output.test.ts index 94ee932..267e57f 100644 --- a/test/llms/parse-output.ts +++ b/test/llms/parse-output.test.ts @@ -5,7 +5,8 @@ import { parseArrayOutput, parseBooleanOutput, parseNumberOutput, - parseObjectOutput + parseObjectOutput, + parseOutput } from '@/llms/parse-output' test('parseArrayOutput - handles valid arrays correctly', (t) => { @@ -191,3 +192,52 @@ test('parseNumberOutput - throws error for invalid outputs', (t) => { t.snapshot(error?.message) }) + +test('parseOutput - handles arrays correctly', (t) => { + const arraySchema = z.array(z.number()) + const output = '[1, 2, 3]' + const result = parseOutput(output, arraySchema) + + t.snapshot(result, 'should parse and return [1, 2, 3] for "[1, 2, 3]"') +}) + +test('parseOutput - handles objects correctly', (t) => { + const objectSchema = z.object({ a: z.number(), b: z.string() }) + const output = '{"a": 1, "b": "two"}' + const result = parseOutput(output, objectSchema) + + t.snapshot( + result, + 'should parse and return {"a": 1, "b": "two"} for "{"a": 1, "b": "two"}"' + ) +}) + +test('parseOutput - handles booleans correctly', (t) => { + const booleanSchema = z.boolean() + const output = 'True' + const result = parseOutput(output, booleanSchema) + + t.snapshot(result, 'should parse and return true for "True"') +}) + +test('parseOutput - handles numbers correctly', (t) => { + const numberSchema = z.number() + const output = '123.45' + const result = parseOutput(output, numberSchema) + + t.snapshot(result, 'should parse and return 123.45 for "123.45"') +}) + +test('parseOutput - throws error for invalid data', (t) => { + const numberSchema = z.number() + const output = 'not a number' + + const error = t.throws( + () => { + parseOutput(output, numberSchema) + }, + { instanceOf: Error } + ) + + t.snapshot(error?.message) +})