/
file_test.ts
104 lines (83 loc) · 2.37 KB
/
file_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test, assert, assertEqual } from "./test_util.ts";
function testFirstArgument(arg1, expectedSize) {
const file = new File(arg1, "name");
assert(file instanceof File);
assertEqual(file.name, "name");
assertEqual(file.size, expectedSize);
assertEqual(file.type, "");
}
test(function fileEmptyFileBits() {
testFirstArgument([], 0);
});
test(function fileStringFileBits() {
testFirstArgument(["bits"], 4);
});
test(function fileUnicodeStringFileBits() {
testFirstArgument(["𝓽𝓮𝔁𝓽"], 16);
});
test(function fileStringObjectFileBits() {
// tslint:disable-next-line no-construct
testFirstArgument([new String("string object")], 13);
});
test(function fileEmptyBlobFileBits() {
testFirstArgument([new Blob()], 0);
});
test(function fileBlobFileBits() {
testFirstArgument([new Blob(["bits"])], 4);
});
test(function fileEmptyFileFileBits() {
testFirstArgument([new File([], "world.txt")], 0);
});
test(function fileFileFileBits() {
testFirstArgument([new File(["bits"], "world.txt")], 4);
});
test(function fileArrayBufferFileBits() {
testFirstArgument([new ArrayBuffer(8)], 8);
});
test(function fileTypedArrayFileBits() {
testFirstArgument([new Uint8Array([0x50, 0x41, 0x53, 0x53])], 4);
});
test(function fileVariousFileBits() {
testFirstArgument(
[
"bits",
new Blob(["bits"]),
new Blob(),
new Uint8Array([0x50, 0x41]),
new Uint16Array([0x5353]),
new Uint32Array([0x53534150])
],
16
);
});
test(function fileNumberInFileBits() {
testFirstArgument([12], 2);
});
test(function fileArrayInFileBits() {
testFirstArgument([[1, 2, 3]], 5);
});
test(function fileObjectInFileBits() {
// "[object Object]"
testFirstArgument([{}], 15);
});
function testSecondArgument(arg2, expectedFileName) {
const file = new File(["bits"], arg2);
assert(file instanceof File);
assertEqual(file.name, expectedFileName);
}
test(function fileUsingFileName() {
testSecondArgument("dummy", "dummy");
});
test(function fileUsingSpecialCharacterInFileName() {
testSecondArgument("dummy/foo", "dummy:foo");
});
test(function fileUsingNullFileName() {
testSecondArgument(null, "null");
});
test(function fileUsingNumberFileName() {
testSecondArgument(1, "1");
});
test(function fileUsingEmptyStringFileName() {
testSecondArgument("", "");
});