Path: blob/main/tests/unit/schema-validation/hello-world.test.ts
6456 views
import { readAnnotatedYamlFromString } from "../../../src/core/lib/yaml-intelligence/annotated-yaml.ts";1import { asMappedString } from "../../../src/core/mapped-text.ts";23import { setSchemaDefinition } from "../../../src/core/lib/yaml-validation/schema.ts";4import { yamlValidationUnitTest } from "./utils.ts";56import { YAMLSchema } from "../../../src/core/lib/yaml-validation/yaml-schema.ts";78import { ObjectSchema } from "../../../src/core/lib/yaml-schema/types.ts";910yamlValidationUnitTest("schema-validation-hello-world", async () => {11const src = `12lets:13- 114- 215- 316- 417go:18- there19- and20- elsewhere21what:22about:23nested: "things like this"24`;25const schema: ObjectSchema = {26"type": "object",27"properties": {28"lets": { "type": "number", "maximum": 2 },29"annotate": { "type": "string" },30},31"$id": "test-schema",32};33setSchemaDefinition(schema);34const yamlSchema = new YAMLSchema(schema);35// deno-lint-ignore no-explicit-any36const fromPlainString = (schema: any, src: string) =>37schema.validateParse(asMappedString(src), readAnnotatedYamlFromString(src));38await fromPlainString(yamlSchema, src);39});404142