-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Irene Alvarado
committed
Apr 23, 2021
1 parent
41dc8c3
commit 52b59a6
Showing
8 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Writing test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Write to a file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test file to read |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { readTXT, writeTXT } from '../../src/txt.ts' // replace with latest library https://deno.land/x/[email protected]/mod.ts | ||
|
||
// Path to a csv file | ||
const readTXTPath = './examples/txt/text.txt' | ||
const writeTXTPath = './examples/txt/text-write.txt' | ||
const content = 'Writing test' | ||
|
||
// read from a text file | ||
const text = await readTXT(readTXTPath) | ||
console.log(text) | ||
|
||
// write a text file | ||
await writeTXT(writeTXTPath, content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export async function readTXT(path: string) { | ||
const text = await Deno.readTextFile(path) | ||
return text | ||
} | ||
|
||
export async function writeTXT(path: string, text: string) { | ||
await Deno.writeTextFile(path, text) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { assertStringIncludes } from "https://deno.land/[email protected]/testing/asserts.ts" | ||
import { readTXT, writeTXT } from '../src/txt.ts' | ||
|
||
const txtReadPath = './examples/txt/text.txt' | ||
const jsonWritePath = './examples/txt/text-write2.txt' | ||
|
||
Deno.test("reads a txt file", async () => { | ||
const txt = await readTXT(txtReadPath) | ||
console.log(txt) | ||
|
||
assertStringIncludes(txt, 'Test file to read'); | ||
}) | ||
|
||
Deno.test("writes a txt file", async () => { | ||
const content = 'Write to a file' | ||
await writeTXT(jsonWritePath, content) | ||
const txt = await readTXT(jsonWritePath) | ||
|
||
assertStringIncludes(txt, content); | ||
}) |