This repository has been archived by the owner on Feb 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
99f31da
commit 9c2179c
Showing
4 changed files
with
59 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,3 +168,6 @@ cython_debug/ | |
|
||
# magic environments | ||
.magic | ||
|
||
# Rattler | ||
output |
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,39 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json | ||
|
||
context: | ||
version: "13.4.2" | ||
|
||
package: | ||
name: "gojo" | ||
version: 0.1.0 | ||
|
||
source: | ||
- path: ./src | ||
|
||
build: | ||
script: | ||
- mkdir -p ${PREFIX}/lib/mojo | ||
- mojo package gojo -o ${PREFIX}/lib/mojo/gojo.mojopkg | ||
|
||
tests: | ||
- script: | ||
# commands to run to test the package. If any of the commands | ||
# returns with an error code, the test is considered failed. | ||
- mojo package info/recipe/src/gojo -o info/recipe/test/gojo.mojopkg | ||
- mojo test info/recipe/test/ | ||
|
||
# requirements: | ||
# run: | ||
# - mojo | ||
|
||
files: | ||
# Extra files to be copied to the test directory from the "work directory" | ||
source: | ||
- test/**/* | ||
|
||
about: | ||
homepage: https://github.com/thatstoasty/gojo | ||
license: MIT | ||
license_file: LICENSE | ||
summary: Experiments in porting over Golang stdlib into Mojo. | ||
repository: https://github.com/thatstoasty/gojo |
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,55 +1,61 @@ | ||
from gojo.io import read_all, FileWrapper | ||
from gojo.builtins.bytes import to_string | ||
import pathlib | ||
import testing | ||
|
||
|
||
def test_read(): | ||
# var test = MojoTest("Testing FileWrapper.read") | ||
var file = FileWrapper("test/data/test.txt", "r") | ||
var test_file = str(pathlib._dir_of_current_file()) + "/data/test.txt" | ||
var file = FileWrapper(test_file, "r") | ||
var dest = List[UInt8, True](capacity=16) | ||
_ = file.read(dest) | ||
testing.assert_equal(to_string(dest), "12345\n") | ||
|
||
|
||
def test_read_all(): | ||
# var test = MojoTest("Testing FileWrapper.read_all") | ||
var file = FileWrapper("test/data/test_big_file.txt", "r") | ||
var test_file = str(pathlib._dir_of_current_file()) + "/data/test_big_file.txt" | ||
var file = FileWrapper(test_file, "r") | ||
var result = file.read_all() | ||
var bytes = result[0] | ||
testing.assert_equal(len(bytes), 15359) | ||
bytes.append(0) | ||
|
||
with open("test/data/test_big_file.txt", "r") as f: | ||
with open(test_file, "r") as f: | ||
var expected = f.read() | ||
testing.assert_equal(String(bytes), expected) | ||
|
||
|
||
def test_io_read_all(): | ||
# var test = MojoTest("Testing io.read_all with FileWrapper") | ||
var file = FileWrapper("test/data/test_big_file.txt", "r") | ||
var test_file = str(pathlib._dir_of_current_file()) + "/data/test_big_file.txt" | ||
var file = FileWrapper(test_file, "r") | ||
var result = read_all(file) | ||
var bytes = result[0] | ||
testing.assert_equal(len(bytes), 15359) | ||
bytes.append(0) | ||
|
||
with open("test/data/test_big_file.txt", "r") as f: | ||
with open(test_file, "r") as f: | ||
var expected = f.read() | ||
testing.assert_equal(String(bytes), expected) | ||
|
||
|
||
def test_read_byte(): | ||
# var test = MojoTest("Testing FileWrapper.read_byte") | ||
var file = FileWrapper("test/data/test.txt", "r") | ||
var test_file = str(pathlib._dir_of_current_file()) + "/data/test.txt" | ||
var file = FileWrapper(test_file, "r") | ||
testing.assert_equal(int(file.read_byte()[0]), 49) | ||
|
||
|
||
def test_write(): | ||
# var test = MojoTest("Testing FileWrapper.write") | ||
var file = FileWrapper("test/data/test_write.txt", "w") | ||
var test_file = str(pathlib._dir_of_current_file()) + "/data/test_write.txt" | ||
var file = FileWrapper(test_file, "w") | ||
var content = "12345" | ||
var bytes_written = file.write(content.as_bytes_slice()) | ||
testing.assert_equal(bytes_written[0], 5) | ||
|
||
with open("test/data/test_write.txt", "r") as f: | ||
with open(test_file, "r") as f: | ||
var expected = f.read() | ||
testing.assert_equal(content, expected) |