summaryrefslogtreecommitdiff
path: root/js/files_test.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-03-28 04:29:36 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-03-27 23:29:36 -0400
commit597ee38ef28d040cbf4d629cf3d2bd3e89a70a11 (patch)
treeed376d8951cd986beddf6a96341cbf47a2d22a11 /js/files_test.ts
parentd0b6152f11800b0baac1ae68d2eef7bfcea13cb5 (diff)
Rewrite readFile and writeFile (#2000)
Using open/read/write
Diffstat (limited to 'js/files_test.ts')
-rw-r--r--js/files_test.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/js/files_test.ts b/js/files_test.ts
index 0decd9f00..f953946bc 100644
--- a/js/files_test.ts
+++ b/js/files_test.ts
@@ -163,6 +163,19 @@ testPerm({ read: true }, async function seekStart() {
assertEquals(decoded, "world!");
});
+testPerm({ read: true }, function seekSyncStart() {
+ const filename = "tests/hello.txt";
+ const file = Deno.openSync(filename);
+ // Deliberately move 1 step forward
+ file.readSync(new Uint8Array(1)); // "H"
+ // Skipping "Hello "
+ file.seekSync(6, Deno.SeekMode.SEEK_START);
+ const buf = new Uint8Array(6);
+ file.readSync(buf);
+ const decoded = new TextDecoder().decode(buf);
+ assertEquals(decoded, "world!");
+});
+
testPerm({ read: true }, async function seekCurrent() {
const filename = "tests/hello.txt";
const file = await Deno.open(filename);
@@ -176,6 +189,19 @@ testPerm({ read: true }, async function seekCurrent() {
assertEquals(decoded, "world!");
});
+testPerm({ read: true }, function seekSyncCurrent() {
+ const filename = "tests/hello.txt";
+ const file = Deno.openSync(filename);
+ // Deliberately move 1 step forward
+ file.readSync(new Uint8Array(1)); // "H"
+ // Skipping "ello "
+ file.seekSync(5, Deno.SeekMode.SEEK_CURRENT);
+ const buf = new Uint8Array(6);
+ file.readSync(buf);
+ const decoded = new TextDecoder().decode(buf);
+ assertEquals(decoded, "world!");
+});
+
testPerm({ read: true }, async function seekEnd() {
const filename = "tests/hello.txt";
const file = await Deno.open(filename);
@@ -186,6 +212,16 @@ testPerm({ read: true }, async function seekEnd() {
assertEquals(decoded, "world!");
});
+testPerm({ read: true }, function seekSyncEnd() {
+ const filename = "tests/hello.txt";
+ const file = Deno.openSync(filename);
+ file.seekSync(-6, Deno.SeekMode.SEEK_END);
+ const buf = new Uint8Array(6);
+ file.readSync(buf);
+ const decoded = new TextDecoder().decode(buf);
+ assertEquals(decoded, "world!");
+});
+
testPerm({ read: true }, async function seekMode() {
const filename = "tests/hello.txt";
const file = await Deno.open(filename);