Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/schema-validation/simple.test.ts
6451 views
1
/*
2
* simple.test.ts
3
*
4
* Copyright (C) 2022 Posit Software, PBC
5
*
6
*/
7
8
import { convertFromYaml } from "../../../src/core/lib/yaml-schema/from-yaml.ts";
9
10
import { readAndValidateYamlFromMappedString } from "../../../src/core/lib/yaml-schema/validated-yaml.ts";
11
12
import { asMappedString } from "../../../src/core/lib/mapped-text.ts";
13
14
import { setSchemaDefinition } from "../../../src/core/lib/yaml-validation/schema.ts";
15
import { readYamlFromString } from "../../../src/core/yaml.ts";
16
import { yamlValidationUnitTest } from "./utils.ts";
17
18
yamlValidationUnitTest("schema-completions", async () => {
19
const yml = `
20
foo: bar
21
baz:
22
- 1
23
- 2
24
- 3
25
NOTALLOWED: 5
26
bah:
27
wut: "wat"`;
28
29
const schema = convertFromYaml(readYamlFromString(`
30
id: schema-test-1
31
object:
32
properties:
33
baz:
34
arrayOf: string
35
foo: number
36
required: [blah]
37
propertyNames:
38
string:
39
pattern: "[a-z]+"
40
`));
41
setSchemaDefinition(schema);
42
43
const { yamlValidationErrors } = await readAndValidateYamlFromMappedString(
44
asMappedString(yml),
45
schema,
46
);
47
48
if (yamlValidationErrors.length === 0) {
49
throw new Error("validation should have failed.");
50
}
51
});
52
53