1- import type {
2- AssertionAdapter ,
3- ExtractionResult ,
4- PlainRecord ,
5- } from "./types.js" ;
1+ import type { AssertionAdapter , ExtractionResult , PlainRecord } from "./types.js" ;
62import { isPlainRecord } from "./types.js" ;
73
84/**
@@ -29,21 +25,9 @@ export interface ExtractionAssertions<TResult extends ExtractionResult> {
2925 assertMaxContentLength ( result : TResult , maximum : number ) : void ;
3026 assertContentContainsAny ( result : TResult , snippets : string [ ] ) : void ;
3127 assertContentContainsAll ( result : TResult , snippets : string [ ] ) : void ;
32- assertTableCount (
33- result : TResult ,
34- minimum ?: number | null ,
35- maximum ?: number | null ,
36- ) : void ;
37- assertDetectedLanguages (
38- result : TResult ,
39- expected : string [ ] ,
40- minConfidence ?: number | null ,
41- ) : void ;
42- assertMetadataExpectation (
43- result : TResult ,
44- path : string ,
45- expectation : MetadataExpectation ,
46- ) : void ;
28+ assertTableCount ( result : TResult , minimum ?: number | null , maximum ?: number | null ) : void ;
29+ assertDetectedLanguages ( result : TResult , expected : string [ ] , minConfidence ?: number | null ) : void ;
30+ assertMetadataExpectation ( result : TResult , path : string , expectation : MetadataExpectation ) : void ;
4731}
4832
4933/**
@@ -103,9 +87,7 @@ export function createAssertions<TResult extends ExtractionResult>(
10387 if ( ! expected . length ) {
10488 return ;
10589 }
106- const matches = expected . some ( ( token ) =>
107- result . mimeType . includes ( token ) ,
108- ) ;
90+ const matches = expected . some ( ( token ) => result . mimeType . includes ( token ) ) ;
10991 adapter . assertTrue (
11092 matches ,
11193 `Expected MIME type to contain one of ${ JSON . stringify ( expected ) } , got ${ result . mimeType } ` ,
@@ -133,34 +115,20 @@ export function createAssertions<TResult extends ExtractionResult>(
133115 return ;
134116 }
135117 const lowered = result . content . toLowerCase ( ) ;
136- const matches = snippets . some ( ( snippet ) =>
137- lowered . includes ( snippet . toLowerCase ( ) ) ,
138- ) ;
139- adapter . assertTrue (
140- matches ,
141- `Expected content to contain one of ${ JSON . stringify ( snippets ) } ` ,
142- ) ;
118+ const matches = snippets . some ( ( snippet ) => lowered . includes ( snippet . toLowerCase ( ) ) ) ;
119+ adapter . assertTrue ( matches , `Expected content to contain one of ${ JSON . stringify ( snippets ) } ` ) ;
143120 } ,
144121
145122 assertContentContainsAll ( result : TResult , snippets : string [ ] ) : void {
146123 if ( ! snippets . length ) {
147124 return ;
148125 }
149126 const lowered = result . content . toLowerCase ( ) ;
150- const allMatch = snippets . every ( ( snippet ) =>
151- lowered . includes ( snippet . toLowerCase ( ) ) ,
152- ) ;
153- adapter . assertTrue (
154- allMatch ,
155- `Expected content to contain all of ${ JSON . stringify ( snippets ) } ` ,
156- ) ;
127+ const allMatch = snippets . every ( ( snippet ) => lowered . includes ( snippet . toLowerCase ( ) ) ) ;
128+ adapter . assertTrue ( allMatch , `Expected content to contain all of ${ JSON . stringify ( snippets ) } ` ) ;
157129 } ,
158130
159- assertTableCount (
160- result : TResult ,
161- minimum ?: number | null ,
162- maximum ?: number | null ,
163- ) : void {
131+ assertTableCount ( result : TResult , minimum ?: number | null , maximum ?: number | null ) : void {
164132 const tables = Array . isArray ( result . tables ) ? result . tables : [ ] ;
165133 if ( typeof minimum === "number" ) {
166134 adapter . assertGreaterThanOrEqual (
@@ -178,18 +146,11 @@ export function createAssertions<TResult extends ExtractionResult>(
178146 }
179147 } ,
180148
181- assertDetectedLanguages (
182- result : TResult ,
183- expected : string [ ] ,
184- minConfidence ?: number | null ,
185- ) : void {
149+ assertDetectedLanguages ( result : TResult , expected : string [ ] , minConfidence ?: number | null ) : void {
186150 if ( ! expected . length ) {
187151 return ;
188152 }
189- adapter . assertDefined (
190- result . detectedLanguages ,
191- "Expected detectedLanguages to be defined" ,
192- ) ;
153+ adapter . assertDefined ( result . detectedLanguages , "Expected detectedLanguages to be defined" ) ;
193154 const languages = result . detectedLanguages ?? [ ] ;
194155 const allPresent = expected . every ( ( lang ) => languages . includes ( lang ) ) ;
195156 adapter . assertTrue (
@@ -209,20 +170,14 @@ export function createAssertions<TResult extends ExtractionResult>(
209170 }
210171 } ,
211172
212- assertMetadataExpectation (
213- result : TResult ,
214- path : string ,
215- expectation : MetadataExpectation ,
216- ) : void {
173+ assertMetadataExpectation ( result : TResult , path : string , expectation : MetadataExpectation ) : void {
217174 if ( ! isPlainRecord ( result . metadata ) ) {
218175 adapter . fail ( `Metadata is not a record for path ${ path } ` ) ;
219176 }
220177
221178 const value = getMetadataPath ( result . metadata , path ) ;
222179 if ( value === undefined || value === null ) {
223- adapter . fail (
224- `Metadata path '${ path } ' missing in ${ JSON . stringify ( result . metadata ) } ` ,
225- ) ;
180+ adapter . fail ( `Metadata path '${ path } ' missing in ${ JSON . stringify ( result . metadata ) } ` ) ;
226181 }
227182
228183 if ( ! isPlainRecord ( expectation ) ) {
0 commit comments