import { attest, contextualize } from "@ark/attest"
import { jsonSchemaToType } from "@ark/json-schema"

contextualize(() => {
	it("allOf", () => {
		const tAllOf = jsonSchemaToType({
			allOf: [
				{ type: "string", minLength: 1 },
				{ type: "string", maxLength: 10 }
			]
		})
		attest(tAllOf.expression).snap("string <= 10 & >= 1")
	})

	it("anyOf", () => {
		const tAnyOf = jsonSchemaToType({
			anyOf: [
				{ type: "string", minLength: 1 },
				{ type: "string", maxLength: 10 }
			]
		})
		attest(tAnyOf.expression).snap("string <= 10 | string >= 1")
	})

	it("not", () => {
		const tNot = jsonSchemaToType({ not: { type: "string", maxLength: 3 } })
		attest(tNot.json).snap({
			predicate: ["$ark.jsonSchemaNotValidator"]
		})

		attest(tNot.allows(123)).equals(true)
		attest(tNot.allows("1234")).equals(true)
		attest(() => tNot.assert("123")).throws(
			'TraversalError: must be not: a string and at most length 3 (was "123")'
		)
	})

	it("oneOf", () => {
		const tOneOf = jsonSchemaToType({
			oneOf: [{ type: "string", minLength: 10 }, { const: "foo" }]
		})
		attest(tOneOf.json).snap({
			predicate: ["$ark.jsonSchemaOneOfValidator"]
		})

		attest(tOneOf.allows("foo")).equals(true)
		attest(tOneOf.allows("1234567890")).equals(true)
		attest(() => tOneOf.assert("bar")).throws(
			'TraversalError: must be valid according to jsonSchemaOneOfValidator (was "bar")'
		)
	})
})
__tests__
build.ts
config.ts
dtsGen.ts
jsdocGen.ts
mocha.globalSetup.ts
mocha.package.jsonc
nodeOptions.js
node_modules
package.json
patchC8.cjs
publish.ts
scratch
scratch.ts
shared.ts
testPackage.ts
testV8.js
ts.js
tsconfig.cjs.json
tsconfig.dts.json
tsconfig.esm.json
tsconfig.js.json
import { fromHere, shell } from "@ark/fs"

shell(
	`pnpm mocha --config ${fromHere("mocha.package.jsonc")} ${process.argv
		.slice(2)
		.join(" ")}`
)
