kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
chore: rename file and add tests
rodzic
b5053f1b52
commit
eecd49ed49
|
@ -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.
|
@ -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)
|
||||
})
|
Ładowanie…
Reference in New Issue