From f1f14b4a1c50e204aeff3830182041d3e4b04433 Mon Sep 17 00:00:00 2001 From: bryphe Date: Fri, 4 Jan 2019 16:17:07 -0800 Subject: [PATCH] Initial Fs.readFileSync API --- src/Fs.re | 17 +++++++++++++++++ src/Fs.rei | 3 +++ test/Rench_Test/FsTest.re | 9 +++++++++ test/bin/TestFile.txt | 2 ++ test/bin/dune | 5 +++++ 5 files changed, 36 insertions(+) create mode 100644 src/Fs.re create mode 100644 src/Fs.rei create mode 100644 test/Rench_Test/FsTest.re create mode 100644 test/bin/TestFile.txt diff --git a/src/Fs.re b/src/Fs.re new file mode 100644 index 0000000..a11ee60 --- /dev/null +++ b/src/Fs.re @@ -0,0 +1,17 @@ +/* Fs.re */ + +let readFileSync = (path) => { + let chan = open_in_bin(path); + let data = ref(""); + try ({ + while (true) { + data := data ++ "\n" ++ input_line(chan); + } + data; + }) { + | End_of_file => { + close_in(chan); + data; + } + }: +}; diff --git a/src/Fs.rei b/src/Fs.rei new file mode 100644 index 0000000..7e50318 --- /dev/null +++ b/src/Fs.rei @@ -0,0 +1,3 @@ +/* Fs.re */ + +let readFileSync: (path: string) => string; diff --git a/test/Rench_Test/FsTest.re b/test/Rench_Test/FsTest.re new file mode 100644 index 0000000..ae166c0 --- /dev/null +++ b/test/Rench_Test/FsTest.re @@ -0,0 +1,9 @@ +open TestFramework; + +module Event = Rench.Event; + +describe("Fs", ({test, _}) => { + test("readFileSync", ({expect}) => { + expect.int(0).toBe(1); + }); +}); diff --git a/test/bin/TestFile.txt b/test/bin/TestFile.txt new file mode 100644 index 0000000..6fd9ce9 --- /dev/null +++ b/test/bin/TestFile.txt @@ -0,0 +1,2 @@ +Line 1: A +Line 2: B diff --git a/test/bin/dune b/test/bin/dune index 4249217..c3b1a8c 100644 --- a/test/bin/dune +++ b/test/bin/dune @@ -3,3 +3,8 @@ (public_name TestRunner.exe) (libraries Rench_Test) (package Rench_Test)) + +(install + (section bin) + (package Rench_Test) + (files TestFile.txt))