Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp committed Apr 21, 2021
1 parent fb2fc6b commit 59b3c76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions bytes/bytes_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ export class BytesList {
* Returns subset of bytes copied
*/
slice(start: number, end: number = this.len): Uint8Array {
const result = new Uint8Array(end - start);
if (end === start) {
return new Uint8Array();
}
if (start < 0 || this.len <= end) {
if (start < 0 || this.len < end) {
throw new Error("out of range");
} else if (end < start) {
throw new Error("start is greather than end");
throw new Error("invalid range");
}
const result = new Uint8Array(end - start);
const startIdx = this.getChunkIndex(start);
const endIdx = this.getChunkIndex(end - 1);
if (startIdx < 0 || endIdx < 0) {
Expand Down
19 changes: 13 additions & 6 deletions bytes/bytes_list_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function setup() {
arr.add(part5, 1, 2);
return arr;
}
Deno.test("BytesList.add", () => {
Deno.test("[bytes] BytesList.add", () => {
const arr = setup();
assertEquals(arr.size(), 10);
assertEquals(arr.getChunkIndex(-1), -1);
Expand All @@ -36,7 +36,7 @@ Deno.test("BytesList.add", () => {
assertEquals(arr.get(i), i);
}
});
Deno.test("BytesList.slice", () => {
Deno.test("[bytes] BytesList.slice", () => {
const arr = setup();
assertEquals(
bytes.equals(arr.slice(0, 4), new Uint8Array([0, 1, 2, 3])),
Expand All @@ -61,8 +61,15 @@ Deno.test("BytesList.slice", () => {
Error,
"out of range",
);
assertThrows(
() => {
arr.slice(1, 0);
},
Error,
"invalid range",
);
});
Deno.test("BytesList.concat", () => {
Deno.test("[bytes] BytesList.concat", () => {
const arr = setup();
assertEquals(
bytes.equals(
Expand All @@ -72,7 +79,7 @@ Deno.test("BytesList.concat", () => {
true,
);
});
Deno.test("BytesList.shift", () => {
Deno.test("[bytes] BytesList.shift", () => {
const arr = setup();
arr.shift(3);
assertEquals(arr.size(), 7);
Expand All @@ -93,7 +100,7 @@ Deno.test("BytesList.shift", () => {
true,
);
});
Deno.test("BytesList.shift 2", () => {
Deno.test("[bytes] BytesList.shift 2", () => {
const arr = new BytesList();
arr.add(new Uint8Array([0, 0, 0, 1, 2, 0]), 0, 5);
arr.shift(2);
Expand Down Expand Up @@ -121,7 +128,7 @@ Deno.test("BytesList.shift 2", () => {
true,
);
});
Deno.test("BytesList.shift 3", () => {
Deno.test("[bytes] BytesList.shift 3", () => {
const arr = new BytesList();
arr.add(new Uint8Array([0, 0, 0, 1, 2, 0]), 0, 5);
arr.shift(100);
Expand Down

0 comments on commit 59b3c76

Please sign in to comment.