#2355 - update tests for ToBase32 to include BMP logic
This commit is contained in:
parent
ab7e5006af
commit
7d82619d7f
@ -65,6 +65,42 @@ TestRegister.addApiTests([
|
|||||||
assert.strictEqual(result.toString(), "493e8136b759370a415ef2cf2f7a69690441ff86592aba082bc2e2e0");
|
assert.strictEqual(result.toString(), "493e8136b759370a415ef2cf2f7a69690441ff86592aba082bc2e2e0");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
it("Composable Dish: toBase32 should support non-BMP Unicode alphabets", () => {
|
||||||
|
const alphabet = "🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅";
|
||||||
|
|
||||||
|
const result = new Dish("hello")
|
||||||
|
.apply(toBase32, {alphabet})
|
||||||
|
.toString();
|
||||||
|
|
||||||
|
// Should not contain replacement characters
|
||||||
|
assert.equal(result.includes("<22>"), false);
|
||||||
|
|
||||||
|
// Should contain only symbols from the alphabet
|
||||||
|
for (const ch of Array.from(result)) {
|
||||||
|
assert.ok(Array.from(alphabet).includes(ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
// "hello" => 8 Base32 symbols
|
||||||
|
assert.equal(Array.from(result).length, 8);
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("Composable Dish: toBase32 should omit padding for 32-character Unicode alphabets", () => {
|
||||||
|
const alphabet = "🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅";
|
||||||
|
|
||||||
|
const result = new Dish("hell")
|
||||||
|
.apply(toBase32, {alphabet})
|
||||||
|
.toString();
|
||||||
|
|
||||||
|
// Should not leak undefined from array indexing
|
||||||
|
assert.equal(result.includes("undefined"), false);
|
||||||
|
|
||||||
|
// Should not contain replacement characters
|
||||||
|
assert.equal(result.includes("<22>"), false);
|
||||||
|
|
||||||
|
// Unpadded Base32 output for 4-byte input should be 7 symbols
|
||||||
|
assert.equal(Array.from(result).length, 7);
|
||||||
|
}),
|
||||||
|
|
||||||
it("Dish translation: ArrayBuffer to ArrayBuffer", () => {
|
it("Dish translation: ArrayBuffer to ArrayBuffer", () => {
|
||||||
const dish = new Dish(new ArrayBuffer(10), 4);
|
const dish = new Dish(new ArrayBuffer(10), 4);
|
||||||
dish.get("array buffer");
|
dish.get("array buffer");
|
||||||
|
|||||||
@ -109,6 +109,38 @@ TestRegister.addApiTests([
|
|||||||
assert.equal(3 + result, 35);
|
assert.equal(3 + result, 35);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
it("toBase32: should support non-BMP Unicode alphabets", () => {
|
||||||
|
const alphabet = "🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅";
|
||||||
|
|
||||||
|
const result = chef.toBase32("hello", {alphabet}).toString();
|
||||||
|
|
||||||
|
// Should not contain replacement characters
|
||||||
|
assert.equal(result.includes("<22>"), false);
|
||||||
|
|
||||||
|
// Should contain only symbols from the alphabet
|
||||||
|
for (const ch of Array.from(result)) {
|
||||||
|
assert.ok(Array.from(alphabet).includes(ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
// "hello" => 8 Base32 symbols
|
||||||
|
assert.equal(Array.from(result).length, 8);
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("toBase32: should omit padding for 32-character Unicode alphabets", () => {
|
||||||
|
const alphabet = "🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅";
|
||||||
|
|
||||||
|
const result = chef.toBase32("hell", {alphabet}).toString();
|
||||||
|
|
||||||
|
// Should not leak undefined from array indexing
|
||||||
|
assert.equal(result.includes("undefined"), false);
|
||||||
|
|
||||||
|
// Should not contain replacement characters
|
||||||
|
assert.equal(result.includes("<22>"), false);
|
||||||
|
|
||||||
|
// Unpadded Base32 output for 4-byte input should be 7 symbols
|
||||||
|
assert.equal(Array.from(result).length, 7);
|
||||||
|
}),
|
||||||
|
|
||||||
it("chef.help: should exist", () => {
|
it("chef.help: should exist", () => {
|
||||||
assert(chef.help);
|
assert(chef.help);
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -172,5 +172,27 @@ TestRegister.addTests([
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "To Base32: should support non-BMP Unicode alphabets",
|
||||||
|
input: "hello",
|
||||||
|
expectedOutput: "🀝🀈🀐🀔🀖🀀🀊🀟",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "To Base32",
|
||||||
|
args: ["🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "To Base32: should omit padding for 32-character Unicode alphabets",
|
||||||
|
input: "hell",
|
||||||
|
expectedOutput: "🀝🀈🀐🀔🀖🀀🀇",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "To Base32",
|
||||||
|
args: ["🀇🀈🀉🀊🀋🀌🀍🀎🀏🀙🀚🀛🀜🀝🀞🀟🀠🀡🀐🀑🀒🀓🀔🀕🀖🀗🀘🀀🀁🀂🀃🀅"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user