import { unitTest } from "../test.ts";
import { assert } from "testing/asserts";
import { Metadata } from "../../src/config/types.ts";
import { readYamlFromString } from "../../src/core/yaml.ts";
import { readAnnotatedYamlFromString } from "../../src/core/lib/yaml-intelligence/annotated-yaml.ts";
import { yamlValidationUnitTest } from "./schema-validation/utils.ts";
const yamlStr = `
project:
type: website
other:
array:
- foo
- bar
`;
unitTest("yaml", async () => {
const yaml = readYamlFromString(yamlStr) as Metadata;
assert(
(yaml.project as Metadata).type === "website",
"Project type not read properly",
);
assert(
Array.isArray((yaml.other as Metadata).array) &&
((yaml.other as Metadata).array as string[]).length === 2,
"Other array key not read properly",
);
});
const circularYml = "foo: &foo\n bar: *foo";
unitTest("yaml-circular-should-fail", async () => {
try {
readYamlFromString(circularYml);
assert(false, "circular structure should have raised");
} catch (_e) {
}
try {
readAnnotatedYamlFromString(circularYml);
assert(false, "circular structure should have raised");
} catch (_e) {
}
});
const sharedYml = "foo:\n bar: &bar\n baz: bah\n baz: *bar";
unitTest("yaml-shared-should-pass", async () => {
readYamlFromString(sharedYml);
readYamlFromString(circularYml);
});
const exprYml = `label: fig-test
fig-cap: !expr paste("Air Quality")`;
unitTest("yaml-expr-tag-should-pass", async () => {
const yml = readYamlFromString(exprYml) as any;
assert(yml["fig-cap"].tag === "!expr");
assert(yml["fig-cap"].value === 'paste("Air Quality")');
});
yamlValidationUnitTest("annotated-yaml-expr-tag-should-pass", async () => {
const yml = readAnnotatedYamlFromString(exprYml).result as any;
assert(yml["fig-cap"].tag === "!expr");
assert(yml["fig-cap"].value === 'paste("Air Quality")');
});