Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.4.1 #84

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ close #

<br />

### ✔︎ Checklists

- [ ] This Pull Request introduces a new feature.
- [ ] This Pull Request fixes a bug.

<br />

### 🔄 Type of the Change

- [ ] 🎉 Feature
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deps-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:

steps:
- name: 🚚 Checkout Repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: dev

- name: 🦕 Update Dependencies
uses: hasundue/molt-action@v1-rc
uses: hasundue/molt-action@c7e98c50ac87758ba0d1242091990e374784ad79 # v1.0.0-rc.4
with:
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
base: dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gist-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:
- name: 🚚 Checkout Repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: 🦕 Setup Deno
uses: denoland/setup-deno@041b854f97b325bd60e53e9dc2de9cb9f9ac0cba # v1.1.4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: 🚚 Checkout Repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: 🦕 Setup Deno
uses: denoland/setup-deno@041b854f97b325bd60e53e9dc2de9cb9f9ac0cba # v1.1.4
Expand Down
4 changes: 2 additions & 2 deletions src/libs/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export async function readTOML(file: string): Promise<Lists> {
return convertFromTOML(data);
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
throw new Error(`File not found: "${file}"`);
throw new Error(`file not found: "${file}"`);
} else if (error instanceof Deno.errors.PermissionDenied) {
throw new Error(`Permission denied: "${file}"`);
throw new Error(`permission denied: "${file}"`);
} else throw error;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libs/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function transcodeXmlUrl(
type: string | undefined,
id: string | undefined,
): URL {
if (!type) throw new Error(`Parameter not set: "type" of "${title}"`);
if (!id) throw new Error(`Parameter not set: "id" of "${title}"`);
if (!type) throw new Error(`parameter not set: "type" of "${title}"`);
if (!id) throw new Error(`parameter not set: "id" of "${title}"`);

const url: URL | undefined = sites
.find((site: site) => site.type === type)?.url;
if (!url) throw new Error(`Site not found: "${type}" of "${title}"`);
if (!url) throw new Error(`site not found: "${type}" of "${title}"`);

return new URL(url.href.replace(encodeURI("{id}"), id));
}
98 changes: 51 additions & 47 deletions test/libs/convert_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { assertEquals } from "@std/assert";
import { convertFromTOML, convertToOPML } from "../../src/libs/convert.ts";
import type { List, Lists } from "../../src/types/mod.ts";

Deno.test("Parse TOML (RSS)", () => {
const toml = `
Deno.test("Parse TOML", async (t: Deno.TestContext) => {
await t.step("rss", () => {
const toml = `
[[lists]]
name = "list name"

Expand All @@ -12,21 +13,21 @@ title = "feed title"
xmlUrl = "https://example.com/feed"
`;

const feeds: Lists = {
lists: [{
name: "list name",
feeds: [{
title: "feed title",
xmlUrl: new URL("https://example.com/feed"),
const feeds: Lists = {
lists: [{
name: "list name",
feeds: [{
title: "feed title",
xmlUrl: new URL("https://example.com/feed"),
}],
}],
}],
};
};

assertEquals(convertFromTOML(toml), feeds);
});
assertEquals(convertFromTOML(toml), feeds);
});

Deno.test("Parse TOML (Site)", () => {
const toml = `
await t.step("site", () => {
const toml = `
[[lists]]
name = "list name"

Expand All @@ -36,23 +37,25 @@ type = "bluesky"
id = "username"
`;

const feeds: Lists = {
lists: [{
name: "list name",
feeds: [{
title: "feed title",
type: "bluesky",
id: "username",
xmlUrl: new URL("https://bsky.app/profile/username/rss"),
const feeds: Lists = {
lists: [{
name: "list name",
feeds: [{
title: "feed title",
type: "bluesky",
id: "username",
xmlUrl: new URL("https://bsky.app/profile/username/rss"),
}],
}],
}],
};
};

assertEquals(convertFromTOML(toml), feeds);
assertEquals(convertFromTOML(toml), feeds);
});
});

Deno.test("Convert Lists to OPML (RSS)", () => {
const xml = `\
Deno.test("Convert Lists to OPML", async (t: Deno.TestContext) => {
await t.step("rss", () => {
const xml = `\
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<body>
Expand All @@ -61,19 +64,19 @@ Deno.test("Convert Lists to OPML (RSS)", () => {
</opml>
`;

const list: List = {
name: "list name",
feeds: [{
title: "feed title",
xmlUrl: new URL("https://example.com/feed"),
}],
};
const list: List = {
name: "list name",
feeds: [{
title: "feed title",
xmlUrl: new URL("https://example.com/feed"),
}],
};

assertEquals(convertToOPML(list), xml);
});
assertEquals(convertToOPML(list), xml);
});

Deno.test("Convert Lists to OPML (Site)", () => {
const xml = `\
await t.step("site", () => {
const xml = `\
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<body>
Expand All @@ -82,14 +85,15 @@ Deno.test("Convert Lists to OPML (Site)", () => {
</opml>
`;

const list: List = {
name: "list name",
feeds: [{
title: "feed title",
type: "bluesky",
id: "username",
}],
};
const list: List = {
name: "list name",
feeds: [{
title: "feed title",
type: "bluesky",
id: "username",
}],
};

assertEquals(convertToOPML(list), xml);
assertEquals(convertToOPML(list), xml);
});
});
78 changes: 38 additions & 40 deletions test/libs/io_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { readTOML, writeXML } from "../../src/libs/io.ts";
import { convertFromTOML, convertToOPML } from "../../src/libs/convert.ts";
import type { Lists } from "../../src/types/mod.ts";

Deno.test("Read TOML", async () => {
const toml = `
Deno.test("Read TOML", async (t: Deno.TestContext) => {
await t.step("normal", async () => {
const toml = `
[[lists]]
name = "list name"

Expand All @@ -14,52 +15,49 @@ title = "feed title"
xmlUrl = "https://example.com/feed"
`;

const file: string = await Deno.makeTempFile({ suffix: ".toml" });
await Deno.writeTextFile(file, toml);
const lists: Lists = await readTOML(file);
const file: string = await Deno.makeTempFile({ suffix: ".toml" });
await Deno.writeTextFile(file, toml);
const lists: Lists = await readTOML(file);

assertEquals(convertFromTOML(toml), lists);
});
assertEquals(convertFromTOML(toml), lists);
});

Deno.test("Read TOML (File not found)", async () => {
try {
await readTOML("file-not-found.toml");
} catch (error) {
assertEquals(error.message, 'File not found: "file-not-found.toml"');
}
});
await t.step("file not found", async () => {
try {
await readTOML("file-not-found.toml");
} catch (error) {
assertEquals(error.message, 'file not found: "file-not-found.toml"');
}
});

Deno.test("Read TOML (Permission denied)", async () => {
const file: string = await Deno.makeTempFile({ suffix: ".toml" });
await Deno.chmod(file, 0o000);
try {
await readTOML(file);
} catch (error) {
assertEquals(error.message, `Permission denied: "${file}"`);
}
});
await t.step("permission denied", async () => {
const file: string = await Deno.makeTempFile({ suffix: ".toml" });
await Deno.chmod(file, 0o000);
try {
await readTOML(file);
} catch (error) {
assertEquals(error.message, `permission denied: "${file}"`);
}
});

Deno.test("Read TOML (Unexpected error)", async () => {
try {
await readTOML("");
} catch (error) {
assertIsError(error);
}
await t.step("unexpected error", async () => {
try {
await readTOML("");
} catch (error) {
assertIsError(error);
}
});
});

Deno.test("Write XML", async () => {
const feeds: Lists = {
lists: [
{
name: "list name",
feeds: [
{
title: "feed title",
xmlUrl: new URL("https://example.com/feed"),
},
],
},
],
lists: [{
name: "list name",
feeds: [{
title: "feed title",
xmlUrl: new URL("https://example.com/feed"),
}],
}],
};

const dir: string = await Deno.makeTempDir();
Expand Down
Loading