forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob_test.ts
35 lines (31 loc) · 1.07 KB
/
blob_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, assert, assertEquals } from "./test_util.ts";
test(function blobString() {
const b1 = new Blob(["Hello World"]);
const str = "Test";
const b2 = new Blob([b1, str]);
assertEquals(b2.size, b1.size + str.length);
});
test(function blobBuffer() {
const buffer = new ArrayBuffer(12);
const u8 = new Uint8Array(buffer);
const f1 = new Float32Array(buffer);
const b1 = new Blob([buffer, u8]);
assertEquals(b1.size, 2 * u8.length);
const b2 = new Blob([b1, f1]);
assertEquals(b2.size, 3 * u8.length);
});
test(function blobSlice() {
const blob = new Blob(["Deno", "Foo"]);
const b1 = blob.slice(0, 3, "Text/HTML");
assert(b1 instanceof Blob);
assertEquals(b1.size, 3);
assertEquals(b1.type, "text/html");
const b2 = blob.slice(-1, 3);
assertEquals(b2.size, 0);
const b3 = blob.slice(100, 3);
assertEquals(b3.size, 0);
const b4 = blob.slice(0, 10);
assertEquals(b4.size, blob.size);
});
// TODO(qti3e) Test the stored data in a Blob after implementing FileReader API.