mirror of
https://github.com/kou029w/websri.git
synced 2025-01-18 16:08:16 +00:00
add iterator and size getter
This commit is contained in:
parent
f7ac85b913
commit
c085fcbe8f
3 changed files with 61 additions and 0 deletions
10
src/index.ts
10
src/index.ts
|
@ -173,6 +173,16 @@ export class IntegrityMetadataSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*[Symbol.iterator](): Generator<IntegrityMetadata> {
|
||||||
|
for (const integrityMetadata of this.#set) {
|
||||||
|
yield integrityMetadata;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get size(): number {
|
||||||
|
return this.#set.length;
|
||||||
|
}
|
||||||
|
|
||||||
join(separator = " "): string {
|
join(separator = " "): string {
|
||||||
return this.#set.map(String).join(separator);
|
return this.#set.map(String).join(separator);
|
||||||
}
|
}
|
||||||
|
|
32
test/integrity-metadata-set/iterator.js
Normal file
32
test/integrity-metadata-set/iterator.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import assert from "node:assert";
|
||||||
|
import { test } from "node:test";
|
||||||
|
import { IntegrityMetadata, IntegrityMetadataSet } from "../../dist/index.js";
|
||||||
|
|
||||||
|
test("correctly iterate over the set", function () {
|
||||||
|
const integrityMetadataSet = new IntegrityMetadataSet(`
|
||||||
|
sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=
|
||||||
|
sha384-VbxVaw0v4Pzlgrpf4Huq//A1ZTY4x6wNVJTCpkwL6hzFczHHwSpFzbyn9MNKCJ7r
|
||||||
|
sha512-wVJ82JPBJHc9gRkRlwyP5uhX1t9dySJr2KFgYUwM2WOk3eorlLt9NgIe+dhl1c6ilKgt1JoLsmn1H256V/eUIQ==
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
[...integrityMetadataSet],
|
||||||
|
[
|
||||||
|
new IntegrityMetadata(
|
||||||
|
"sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=",
|
||||||
|
),
|
||||||
|
new IntegrityMetadata(
|
||||||
|
"sha384-VbxVaw0v4Pzlgrpf4Huq//A1ZTY4x6wNVJTCpkwL6hzFczHHwSpFzbyn9MNKCJ7r",
|
||||||
|
),
|
||||||
|
new IntegrityMetadata(
|
||||||
|
"sha512-wVJ82JPBJHc9gRkRlwyP5uhX1t9dySJr2KFgYUwM2WOk3eorlLt9NgIe+dhl1c6ilKgt1JoLsmn1H256V/eUIQ==",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("if the empty set, return the empty set", function () {
|
||||||
|
const integrityMetadataSet = new IntegrityMetadataSet();
|
||||||
|
|
||||||
|
assert.deepEqual([...integrityMetadataSet], []);
|
||||||
|
});
|
19
test/integrity-metadata-set/size.js
Normal file
19
test/integrity-metadata-set/size.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { test } from "node:test";
|
||||||
|
import { IntegrityMetadataSet } from "../../dist/index.js";
|
||||||
|
|
||||||
|
test("return the correct size of the set", function () {
|
||||||
|
const integrityMetadataSet = new IntegrityMetadataSet(`
|
||||||
|
sha256-MV9b23bQeMQ7isAGTkoBZGErH853yGk0W/yUx1iU7dM=
|
||||||
|
sha384-VbxVaw0v4Pzlgrpf4Huq//A1ZTY4x6wNVJTCpkwL6hzFczHHwSpFzbyn9MNKCJ7r
|
||||||
|
sha512-wVJ82JPBJHc9gRkRlwyP5uhX1t9dySJr2KFgYUwM2WOk3eorlLt9NgIe+dhl1c6ilKgt1JoLsmn1H256V/eUIQ==
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.strictEqual(integrityMetadataSet.size, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("if the empty set, return 0", function () {
|
||||||
|
const integrityMetadataSet = new IntegrityMetadataSet();
|
||||||
|
|
||||||
|
assert.strictEqual(integrityMetadataSet.size, 0);
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue