import { AssertionErrorConstructor , FailedAssertionError } from "./error.js" ; param name param actual param expected param errorConstructor export function assertStringEquals ( name , actual , expected , errorConstructor = FailedAssertionError ) { if ( ! actual ) { throw new errorConstructor ( `Missing ${ name }. Expected: ${ expected }` , actual , expected ) ; } if ( typeof actual !== "string" ) { throw new errorConstructor ( `${ name } is not of type string` , actual , expected ) ; } if ( expected !== actual ) { throw new errorConstructor ( `${ name } not allowed: ${ actual }. Expected: ${ expected }` , actual , expected ) ; } } param name param actual param expected param errorConstructor export function assertStringArrayContainsString ( name , actual , expected , errorConstructor = FailedAssertionError ) { if ( ! actual ) { throw new errorConstructor ( `Missing ${ name }. ${ expectationMessage ( expected ) }` , actual , expected ) ; } if ( typeof actual !== "string" ) { throw new errorConstructor ( `${ name } is not of type string` , actual , expected ) ; } return assertStringArraysOverlap ( name , actual , expected , errorConstructor ) ; } param name param actual param expected param errorConstructor export function assertStringArraysOverlap ( name , actual , expected , errorConstructor = FailedAssertionError ) { if ( ! actual ) { throw new errorConstructor ( `Missing ${ name }. ${ expectationMessage ( expected ) }` , actual , expected ) ; } const expectedAsSet = new Set ( Array . isArray ( expected ) ? expected : [ expected ] ) ; if ( typeof actual === "string" ) { actual = [ actual ] ; } if ( ! Array . isArray ( actual ) ) { throw new errorConstructor ( `${ name } is not an array` , actual , expected ) ; } const overlaps = actual . some ( ( actualItem ) => { if ( typeof actualItem !== "string" ) { throw new errorConstructor ( `${ name } includes elements that are not of type string` , actual , expected ) ; } return expectedAsSet . has ( actualItem ) ; } ) ; if ( ! overlaps ) { throw new errorConstructor ( `${ name } not allowed: ${ actual . join ( ", " ) }. ${ expectationMessage ( expected ) }` , actual , expected ) ; } } param expected function expectationMessage ( expected ) { if ( Array . isArray ( expected ) ) { if ( expected . length > 1 ) { return `Expected one of: ${ expected . join ( ", " ) }` ; } return `Expected: ${ expected [ 0 ] }` ; } return `Expected: ${ expected }` ; } param actual param errorFactory export function assertIsNotPromise ( actual , errorFactory ) { if ( actual && typeof ( actual as { then ? : unknown ; } ) . then === "function" ) { throw errorFactory ( ) ; } }