-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite file handle, adjust file.seek() (#36)
* rewrite file handle, adjust file.seek() Signed-off-by: Flipez <code@brauser.io> * add file.content(), file.read(INT) Signed-off-by: Flipez <code@brauser.io> * readAll from 0, update tests and docs Signed-off-by: Flipez <code@brauser.io> * enhance tests Signed-off-by: Flipez <code@brauser.io> * improve error handling Signed-off-by: Flipez <code@brauser.io> * improve read and seek Signed-off-by: Flipez <code@brauser.io> * improve file.write; add nil check to seek Signed-off-by: Flipez <code@brauser.io>
- Loading branch information
Showing
6 changed files
with
170 additions
and
58 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
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
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 |
---|---|---|
@@ -1,17 +1,33 @@ | ||
package object_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestFileObjectMethods(t *testing.T) { | ||
tests := []inputTestCase{ | ||
{`let a = open("../main.go"); a.close()`, true}, | ||
{`let a = open("../fixtures/module.rl"); a.read()`, "a = 1\nA = 5\n\nSum = fn(a, b) {\n return a + b\n}\n"}, | ||
{`let a = open("../fixtures/module.rl"); a.lines().size()`, 7}, | ||
{`(open("").wat().lines().size() == open("").methods().size() + 1).plz_s()`, "true"}, | ||
{`open("").type()`, "FILE"}, | ||
{`open("../fixtures/module.rl").close()`, true}, | ||
{`a = open("../fixtures/module.rl"); a.close(); a.position()`, -1}, | ||
{`open("../fixtures/module.rl").content().size()`, 49}, | ||
{`open("../fixtures/module.rl").content(1)`, "To many arguments: want=0, got=1"}, | ||
{`open("../fixtures/module.rl").read()`, "To few arguments: want=1, got=0"}, | ||
{`open("../fixtures/module.rl").read(1)`, "a"}, | ||
{`open("../fixtures/module.rl").position()`, 0}, | ||
{`a = open("../fixtures/module.rl"); a.read(1); a.content(); a.position()`, 0}, | ||
{`a = open("../fixtures/module.rl"); a.read(1); a.position()`, 1}, | ||
{`a = open("../fixtures/module.rl"); a.read(1); a.content().size()`, 49}, | ||
{`open("../fixtures/module.rl").lines().size()`, 7}, | ||
{`a = open("../fixtures/module.rl"); a.read(25); a.lines().size()`, 7}, | ||
{`open("../fixtures/nope")`, "open ../fixtures/nope: no such file or directory"}, | ||
{`open("../fixtures/nope").content()`, "Failed to invoke method: content"}, | ||
{`a = open("../fixtures/nope", "rw"); a.content()`, ""}, | ||
{`(open("../fixtures/module.rl").wat().lines().size() == open("../fixtures/module.rl").methods().size() + 1).plz_s()`, "true"}, | ||
{`open("").type()`, "ERROR"}, | ||
{`open("../fixtures/module.rl").type()`, "FILE"}, | ||
} | ||
|
||
testInput(t, tests) | ||
|
||
os.Remove("../fixtures/nope") | ||
} |
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
24b74b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: