chore: rename file and add tests

old-agentic-v1^2
Philipp Burckhardt 2023-06-20 10:54:53 -04:00
rodzic b5053f1b52
commit eecd49ed49
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: A2C3BCA4F31D1DDD
4 zmienionych plików z 90 dodań i 3 usunięć

Wyświetl plik

@ -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'

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -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)
})