-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
41 additions
and
48 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: "tests/*.test.ts" | ||
jsr_dependencies: "@cross/test @std/assert" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,60 @@ | ||
import { assertEquals } from "jsr:@std/[email protected]"; | ||
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, | ||
|
@@ -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); | ||
|
||
|