Skip to content

Commit

Permalink
Use cross runtime ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Oct 7, 2024
1 parent 87ddb16 commit 8f7464c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 48 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/deno.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]

jobs:
deno_ci:
uses: cross-org/workflows/.github/workflows/deno-ci.yml@main
with:
entrypoint: src/base64.ts
lint_docs: false
bun_ci:
uses: cross-org/workflows/.github/workflows/bun-ci.yml@main
with:
jsr_dependencies: "@cross/test @std/assert"
node_ci:
uses: cross-org/workflows/.github/workflows/node-ci.yml@main
with:
test_target: "test/*.test.ts"
jsr_dependencies: "@cross/test @std/assert"
2 changes: 2 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
},
"imports": {
"@cross/fs": "jsr:@cross/fs@^0.1.11",
"@cross/test": "jsr:@cross/test@^0.0.9",
"@std/assert": "jsr:@std/assert@^1.0.6",
"@std/path": "jsr:@std/path@^1.0.6",
"esbuild": "npm:esbuild@^0.24.0",
"esbuild-plugin-d.ts": "npm:esbuild-plugin-d.ts@^1.3.0"
Expand Down
34 changes: 18 additions & 16 deletions tests/base64.test.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
import { assertEquals } from "jsr:@std/assert@1.0.2";
import { assertEquals } from "@std/assert";
import { test } from "@cross/test";

import { base64 } from "../src/base64.ts";

Deno.test("Encode 'Hello world'", function () {
test("Encode 'Hello world'", function () {
const result = base64.fromString("Hello world");
assertEquals(result, "SGVsbG8gd29ybGQ=");
});

Deno.test("Decode 'Hello world'", function () {
test("Decode 'Hello world'", function () {
const result = base64.toString("SGVsbG8gd29ybGQ=");
assertEquals(result, "Hello world");
});

// Basic string base64url
Deno.test("Encode 'Hello world' in base64url mode", function () {
test("Encode 'Hello world' in base64url mode", function () {
const result = base64.fromString("Hello world", true);
assertEquals(result, "SGVsbG8gd29ybGQ");
});

Deno.test("Decode 'Hello world' in base64url mode", function () {
test("Decode 'Hello world' in base64url mode", function () {
const result = base64.toString("SGVsbG8gd29ybGQ", true);
assertEquals(result, "Hello world");
});

// UTF-8 string
Deno.test("Encode 'ɸåäd' in base64url mode", function () {
test("Encode 'ɸåäd' in base64url mode", function () {
const result = base64.fromString("ɸåäd");
assertEquals(result, "ybjDpcOkZA==");
});

Deno.test("Decode 'ɸåäd' in base64url mode", function () {
test("Decode 'ɸåäd' in base64url mode", function () {
const result = base64.toString("ybjDpcOkZA==");
assertEquals(result, "ɸåäd");
});

// UTF-8 string url mode
Deno.test("Encode 'ɸåäd' in base64url mode", function () {
test("Encode 'ɸåäd' in base64url mode", function () {
const result = base64.fromString("ɸåäd", true);
assertEquals(result, "ybjDpcOkZA");
});

Deno.test("Decode 'ɸåäd' in base64url mode", function () {
test("Decode 'ɸåäd' in base64url mode", function () {
const result = base64.toString("ybjDpcOkZA", true);
assertEquals(result, "ɸåäd");
});

// ArrayBuffer base64
Deno.test("Encode array buffer", function () {
test("Encode array buffer", function () {
const result = base64.fromArrayBuffer(
Uint8Array.from([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]).buffer,
);
assertEquals(result, "AAECAwQFBgcI");
});

Deno.test("Decode array buffer", function () {
test("Decode array buffer", function () {
const result = base64.toArrayBuffer("AAECAwQFBgcI");
assertEquals(
result,
Expand All @@ -61,38 +63,38 @@ Deno.test("Decode array buffer", function () {
});

// Validate
Deno.test("AAECAwQFBgcI is valid base64 and base64url", function () {
test("AAECAwQFBgcI is valid base64 and base64url", function () {
const resultNormal = base64.validate("AAECAwQFBgcI"),
resultUrl = base64.validate("AAECAwQFBgcI", true);

assertEquals(resultNormal, true);
assertEquals(resultUrl, true);
});

Deno.test("SGVsbG8gd29ybGQ= is valid base64 but not base64url", function () {
test("SGVsbG8gd29ybGQ= is valid base64 but not base64url", function () {
const resultNormal = base64.validate("SGVsbG8gd29ybGQ="),
resultUrl = base64.validate("SGVsbG8gd29ybGQ=", true);

assertEquals(resultNormal, true);
assertEquals(resultUrl, false);
});

Deno.test("PDw/Pz8+Pg== is valid base64 but not base64url", function () {
test("PDw/Pz8+Pg== is valid base64 but not base64url", function () {
const resultNormal = base64.validate("PDw/Pz8+Pg=="),
resultUrl = base64.validate("PDw/Pz8+Pg==", true);
assertEquals(resultNormal, true);
assertEquals(resultUrl, false);
});

Deno.test("c3ViamVjdHM_X2Q9MQ is valid base64 but not base64url", function () {
test("c3ViamVjdHM_X2Q9MQ is valid base64 but not base64url", function () {
const resultNormal = base64.validate("c3ViamVjdHM_X2Q9MQ"),
resultUrl = base64.validate("c3ViamVjdHM_X2Q9MQ", true);

assertEquals(resultNormal, false);
assertEquals(resultUrl, true);
});

Deno.test("c3ViamVjdHM_+X2Q9MQ is neither base64 nor base64url", function () {
test("c3ViamVjdHM_+X2Q9MQ is neither base64 nor base64url", function () {
const resultNormal = base64.validate("c3ViamVjdHM_+X2Q9MQ"),
resultUrl = base64.validate("c3ViamVjdHM_+X2Q9MQ", true);

Expand Down

0 comments on commit 8f7464c

Please sign in to comment.