Prelude of builtin functions #7

Merged
defunkt merged 45 commits from prelude into main 2025-10-29 20:15:37 +00:00
Showing only changes of commit e95c0d6728 - Show all commits

View File

@ -108,16 +108,10 @@ expect.extend({
if (expected instanceof RegExp) expected = String(expected)
if (value instanceof RegExp) value = String(value)
if (isEqual(value, expected)) {
return { pass: true }
} else {
return {
message: () =>
`Expected evaluation to be ${JSON.stringify(expected)}, but got ${JSON.stringify(
value
)}`,
pass: false,
}
expect(value).toEqual(expected)
defunkt marked this conversation as resolved Outdated

I rewrote this in the branch I'm on too!

If you replace this line with

    expect(value).toEqual(expected)
      return {
        message: () => `Expected evaluation to be ${expected}, but got ${value}`,
        pass: true,
      }

You get to lean on bun's type checking code and you get all the nice diff support.

I rewrote this in the branch I'm on too! If you replace this line with ```ts expect(value).toEqual(expected) return { message: () => `Expected evaluation to be ${expected}, but got ${value}`, pass: true, } ``` You get to lean on bun's type checking code and you get all the nice diff support.

Awesome. Done.

Awesome. Done.
return {
message: () => `Expected evaluation to be ${expected}, but got ${value}`,
pass: true,
}
} catch (error) {
return {
@ -167,29 +161,3 @@ const trimWhitespace = (str: string): string => {
})
.join('\n')
}
function isEqual(a: any, b: any): boolean {
if (a === null && b === null) return true
switch (typeof a) {
case 'string':
case 'number':
case 'boolean':
case 'undefined':
return a === b
default:
return JSON.stringify(sortKeys(a)) === JSON.stringify(sortKeys(b))
}
}
function sortKeys(o: any): any {
if (Array.isArray(o)) return o.map(sortKeys)
if (o && typeof o === 'object' && o.constructor === Object)
return Object.keys(o)
.sort()
.reduce((r, k) => {
r[k] = sortKeys(o[k])
return r
}, {} as any)
return o
}