Skip to content

Commit

Permalink
chore(front_matter): cleanup deprecation-related code (#3932)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Dec 12, 2023
1 parent 21d0206 commit c3a0086
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 62 deletions.
9 changes: 4 additions & 5 deletions front_matter/_test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { assert, assertEquals, assertThrows } from "../assert/mod.ts";
import { dirname, fromFileUrl, join, resolve } from "../path/mod.ts";
import { Format } from "./_formats.ts";

const moduleDir = dirname(fromFileUrl(import.meta.url));
const testdataDir = resolve(moduleDir, "testdata");
Expand All @@ -23,7 +22,7 @@ export function resolveTestDataPath(filename: string): string {
}

export function runTestValidInputTests(
format: Format,
format: "yaml" | "toml" | "json" | "unknown",
testFn: (str: string) => boolean,
) {
const testdata = [
Expand All @@ -33,7 +32,7 @@ export function runTestValidInputTests(
];

// yaml is the default format, so it should be recognized without the format name
if (format === Format.YAML) {
if (format === "yaml") {
testdata.push(`---\nname: deno\n---\n`);
}

Expand All @@ -43,7 +42,7 @@ export function runTestValidInputTests(
}

export function runTestInvalidInputTests(
format: Format,
format: "yaml" | "toml" | "json" | "unknown",
testFn: (str: string) => boolean,
) {
[
Expand All @@ -61,7 +60,7 @@ export function runTestInvalidInputTests(
}

export function runExtractTypeErrorTests(
format: Format,
format: "yaml" | "toml" | "json" | "unknown",
extractFn: (str: string) => unknown,
) {
[
Expand Down
6 changes: 4 additions & 2 deletions front_matter/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { parse as parseYAML } from "../yaml/parse.ts";
import { parse as parseTOML } from "../toml/parse.ts";

export { Format } from "./_formats.ts";
/** @deprecated (will be removed after 0.210.0) Import from {@link https://deno.land/std/front_matter/test.ts} instead. */
export { test } from "./test.ts";
export {
/** @deprecated (will be removed after 0.210.0) Import from {@link https://deno.land/std/front_matter/test.ts} instead. */
test,
} from "./test.ts";

export const extract = createExtractor({
yaml: parseYAML as Parser,
Expand Down
21 changes: 11 additions & 10 deletions front_matter/any_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

import extract, { Format, test } from "./any.ts";
import { test } from "./test.ts";
import { extract } from "./any.ts";
import {
runExtractJSONTests,
runExtractTOMLTests,
Expand All @@ -14,15 +15,15 @@ import {
// YAML //

Deno.test("[ANY/YAML] test valid input true", () => {
runTestValidInputTests(Format.YAML, test);
runTestValidInputTests("yaml", test);
});

Deno.test("[ANY/YAML] test invalid input false", () => {
runTestInvalidInputTests(Format.YAML, test);
runTestInvalidInputTests("yaml", test);
});

Deno.test("[ANY/YAML] extract type error on invalid input", () => {
runExtractTypeErrorTests(Format.YAML, extract);
runExtractTypeErrorTests("yaml", extract);
});

Deno.test("[ANY/YAML] parse yaml delineate by `---`", async () => {
Expand All @@ -36,15 +37,15 @@ Deno.test("[ANY/YAML] parse yaml delineate by `---yaml`", async () => {
// JSON //

Deno.test("[ANY/JSON] test valid input true", () => {
runTestValidInputTests(Format.JSON, test);
runTestValidInputTests("json", test);
});

Deno.test("[ANY/JSON] test invalid input false", () => {
runTestInvalidInputTests(Format.JSON, test);
runTestInvalidInputTests("json", test);
});

Deno.test("[ANY/JSON] extract type error on invalid input", () => {
runExtractTypeErrorTests(Format.JSON, extract);
runExtractTypeErrorTests("json", extract);
});

Deno.test("[ANY/JSON] parse json delineate by ---json", async () => {
Expand All @@ -54,15 +55,15 @@ Deno.test("[ANY/JSON] parse json delineate by ---json", async () => {
// TOML //

Deno.test("[ANY/TOML] test valid input true", () => {
runTestValidInputTests(Format.TOML, test);
runTestValidInputTests("toml", test);
});

Deno.test("[ANY/TOML] test invalid input false", () => {
runTestInvalidInputTests(Format.TOML, test);
runTestInvalidInputTests("toml", test);
});

Deno.test("[ANY/TOML] extract type error on invalid input", () => {
runExtractTypeErrorTests(Format.TOML, extract);
runExtractTypeErrorTests("toml", extract);
});

Deno.test("[ANY/TOML] parse toml delineate by ---toml", async () => {
Expand Down
23 changes: 11 additions & 12 deletions front_matter/create_extractor_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

import { assertThrows } from "../assert/mod.ts";
import { Format } from "./_formats.ts";
import { parse as parseYAML } from "../yaml/parse.ts";
import { parse as parseTOML } from "../toml/parse.ts";
import {
Expand All @@ -14,23 +13,23 @@ import {
} from "./_test_utils.ts";
import { createExtractor, Parser } from "./create_extractor.ts";

const extractYAML = createExtractor({ [Format.YAML]: parseYAML as Parser });
const extractTOML = createExtractor({ [Format.TOML]: parseTOML as Parser });
const extractJSON = createExtractor({ [Format.JSON]: JSON.parse as Parser });
const extractYAML = createExtractor({ "yaml": parseYAML as Parser });
const extractTOML = createExtractor({ "toml": parseTOML as Parser });
const extractJSON = createExtractor({ "json": JSON.parse as Parser });
const extractYAMLOrJSON = createExtractor({
[Format.YAML]: parseYAML as Parser,
[Format.JSON]: JSON.parse as Parser,
"yaml": parseYAML as Parser,
"json": JSON.parse as Parser,
});
const extractAny = createExtractor({
[Format.YAML]: parseYAML as Parser,
[Format.JSON]: JSON.parse as Parser,
[Format.TOML]: parseTOML as Parser,
"yaml": parseYAML as Parser,
"json": JSON.parse as Parser,
"toml": parseTOML as Parser,
});

// YAML //

Deno.test("[YAML] extract type error on invalid input", () => {
runExtractTypeErrorTests(Format.YAML, extractYAML);
runExtractTypeErrorTests("yaml", extractYAML);
});

Deno.test("[YAML] parse yaml delineate by `---`", async () => {
Expand Down Expand Up @@ -61,7 +60,7 @@ Deno.test({
// JSON //

Deno.test("[JSON] extract type error on invalid input", () => {
runExtractTypeErrorTests(Format.JSON, extractJSON);
runExtractTypeErrorTests("json", extractJSON);
});

Deno.test("[JSON] parse json delineate by ---json", async () => {
Expand All @@ -71,7 +70,7 @@ Deno.test("[JSON] parse json delineate by ---json", async () => {
// TOML //

Deno.test("[TOML] extract type error on invalid input", () => {
runExtractTypeErrorTests(Format.TOML, extractTOML);
runExtractTypeErrorTests("toml", extractTOML);
});

Deno.test("[TOML] parse toml delineate by ---toml", async () => {
Expand Down
9 changes: 5 additions & 4 deletions front_matter/json_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

import extract, { Format, test } from "./json.ts";
import { test } from "./test.ts";
import { extract } from "./json.ts";
import {
runExtractJSONTests,
runExtractTypeErrorTests,
Expand All @@ -9,15 +10,15 @@ import {
} from "./_test_utils.ts";

Deno.test("[JSON] test valid input true", () => {
runTestValidInputTests(Format.JSON, test);
runTestValidInputTests("json", test);
});

Deno.test("[JSON] test invalid input false", () => {
runTestInvalidInputTests(Format.JSON, test);
runTestInvalidInputTests("json", test);
});

Deno.test("[JSON] extract type error on invalid input", () => {
runExtractTypeErrorTests(Format.JSON, extract);
runExtractTypeErrorTests("json", extract);
});

Deno.test("[JSON] parse json delineate by ---json", async () => {
Expand Down
9 changes: 4 additions & 5 deletions front_matter/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,20 @@
* ### Advanced usage
*
* ```ts
* import { test as _test } from "https://deno.land/std@$STD_VERSION/front_matter/test.ts";
* import {
* createExtractor,
* Format,
* Parser,
* test as _test,
* } from "https://deno.land/std@$STD_VERSION/front_matter/mod.ts";
* import { parse } from "https://deno.land/std@$STD_VERSION/toml/parse.ts";
*
* const extract = createExtractor({
* [Format.TOML]: parse as Parser,
* [Format.JSON]: JSON.parse as Parser,
* "toml": parse as Parser,
* "json": JSON.parse as Parser,
* });
*
* export function test(str: string): boolean {
* return _test(str, [Format.TOML, Format.JSON]);
* return _test(str, ["toml", "json"]);
* }
* ```
*
Expand Down
4 changes: 2 additions & 2 deletions front_matter/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ type Format = "yaml" | "toml" | "json" | "unknown";
* @param formats A list of formats to test for. Defaults to all supported formats.
*
* ```ts
* import { test, Format } from "https://deno.land/std@$STD_VERSION/front_matter/mod.ts";
* import { test } from "https://deno.land/std@$STD_VERSION/front_matter/mod.ts";
* import { assert } from "https://deno.land/std@$STD_VERSION/assert/assert.ts";
*
* assert(test("---\ntitle: Three dashes marks the spot\n---\n"));
* assert(test("---toml\ntitle = 'Three dashes followed by format marks the spot'\n---\n"));
* assert(test("---json\n{\"title\": \"Three dashes followed by format marks the spot\"}\n---\n"));
*
* assert(!test("---json\n{\"title\": \"Three dashes followed by format marks the spot\"}\n---\n", [Format.YAML]));
* assert(!test("---json\n{\"title\": \"Three dashes followed by format marks the spot\"}\n---\n", ["yaml"]));
* ```
*/
export function test(
Expand Down
15 changes: 7 additions & 8 deletions front_matter/test_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import {
runTestInvalidInputTests,
runTestValidInputTests,
} from "./_test_utils.ts";
import { Format } from "./_formats.ts";
import { test } from "./test.ts";

// GENERAL TESTS //

Deno.test("[ANY] try to test for unknown format", () => {
assertThrows(
() => test("foo", [Format.UNKNOWN]),
() => test("foo", ["unknown"]),
TypeError,
"Unable to test for unknown front matter format",
);
Expand All @@ -22,11 +21,11 @@ Deno.test("[ANY] try to test for unknown format", () => {
// YAML //

Deno.test("[YAML] test valid input true", () => {
runTestValidInputTests(Format.YAML, test);
runTestValidInputTests("yaml", test);
});

Deno.test("[YAML] test invalid input false", () => {
runTestInvalidInputTests(Format.YAML, test);
runTestInvalidInputTests("yaml", test);
});

Deno.test({
Expand All @@ -43,19 +42,19 @@ Deno.test({
// JSON //

Deno.test("[JSON] test valid input true", () => {
runTestValidInputTests(Format.JSON, test);
runTestValidInputTests("json", test);
});

Deno.test("[JSON] test invalid input false", () => {
runTestInvalidInputTests(Format.JSON, test);
runTestInvalidInputTests("json", test);
});

// TOML //

Deno.test("[TOML] test valid input true", () => {
runTestValidInputTests(Format.TOML, test);
runTestValidInputTests("toml", test);
});

Deno.test("[TOML] test invalid input false", () => {
runTestInvalidInputTests(Format.TOML, test);
runTestInvalidInputTests("toml", test);
});
5 changes: 2 additions & 3 deletions front_matter/toml.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

import { createExtractor, Parser } from "./create_extractor.ts";
import { Format } from "./_formats.ts";
import { test as _test } from "./test.ts";
import { parse } from "../toml/parse.ts";

export { Format } from "./_formats.ts";

/** @deprecated (will be removed after 0.210.0) Import from {@link https://deno.land/std/front_matter/toml.ts} and use `test(str, ["toml"])` instead. */
export function test(str: string): boolean {
return _test(str, [Format.TOML]);
return _test(str, ["toml"]);
}

export const extract = createExtractor({ [Format.TOML]: parse as Parser });
export const extract = createExtractor({ ["toml"]: parse as Parser });
/** @deprecated (will be removed after 0.210.0) Import {@linkcode extract} as a named import instead. */
export default extract;
9 changes: 5 additions & 4 deletions front_matter/toml_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

import extract, { Format, test } from "./toml.ts";
import { test } from "./test.ts";
import { extract } from "./toml.ts";
import {
runExtractTOMLTests,
runExtractTOMLTests2,
Expand All @@ -10,15 +11,15 @@ import {
} from "./_test_utils.ts";

Deno.test("[TOML] test valid input true", () => {
runTestValidInputTests(Format.TOML, test);
runTestValidInputTests("toml", test);
});

Deno.test("[TOML] test invalid input false", () => {
runTestInvalidInputTests(Format.TOML, test);
runTestInvalidInputTests("toml", test);
});

Deno.test("[TOML] extract type error on invalid input", () => {
runExtractTypeErrorTests(Format.TOML, extract);
runExtractTypeErrorTests("toml", extract);
});

Deno.test("[TOML] parse toml delineate by ---toml", async () => {
Expand Down
5 changes: 2 additions & 3 deletions front_matter/yaml.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

import { createExtractor, Parser } from "./create_extractor.ts";
import { Format } from "./_formats.ts";
import { test as _test } from "./test.ts";
import { parse } from "../yaml/parse.ts";

export { Format } from "./_formats.ts";

/** @deprecated (will be removed after 0.210.0) Import {@link https://deno.land/std/front_matter/yaml.ts} and use `test(str, ["yaml"])` instead. */
export function test(str: string): boolean {
return _test(str, [Format.YAML]);
return _test(str, ["yaml"]);
}

export const extract = createExtractor({ [Format.YAML]: parse as Parser });
export const extract = createExtractor({ ["yaml"]: parse as Parser });
/** @deprecated (will be removed after 0.210.0) Import {@linkcode extract} as a named import instead. */
export default extract;
Loading

0 comments on commit c3a0086

Please sign in to comment.