Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/schema-validation/hello-world.test.ts
6456 views
1
import { readAnnotatedYamlFromString } from "../../../src/core/lib/yaml-intelligence/annotated-yaml.ts";
2
import { asMappedString } from "../../../src/core/mapped-text.ts";
3
4
import { setSchemaDefinition } from "../../../src/core/lib/yaml-validation/schema.ts";
5
import { yamlValidationUnitTest } from "./utils.ts";
6
7
import { YAMLSchema } from "../../../src/core/lib/yaml-validation/yaml-schema.ts";
8
9
import { ObjectSchema } from "../../../src/core/lib/yaml-schema/types.ts";
10
11
yamlValidationUnitTest("schema-validation-hello-world", async () => {
12
const src = `
13
lets:
14
- 1
15
- 2
16
- 3
17
- 4
18
go:
19
- there
20
- and
21
- elsewhere
22
what:
23
about:
24
nested: "things like this"
25
`;
26
const schema: ObjectSchema = {
27
"type": "object",
28
"properties": {
29
"lets": { "type": "number", "maximum": 2 },
30
"annotate": { "type": "string" },
31
},
32
"$id": "test-schema",
33
};
34
setSchemaDefinition(schema);
35
const yamlSchema = new YAMLSchema(schema);
36
// deno-lint-ignore no-explicit-any
37
const fromPlainString = (schema: any, src: string) =>
38
schema.validateParse(asMappedString(src), readAnnotatedYamlFromString(src));
39
await fromPlainString(yamlSchema, src);
40
});
41
42