1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: add os.open_stdin/0 and os.File.get_line/0

This commit is contained in:
Delyan Angelov
2020-09-09 19:37:38 +03:00
parent 67cc515e74
commit ce6d2759f5
3 changed files with 80 additions and 1 deletions

View File

@@ -43,6 +43,23 @@ fn test_open_file() {
os.rm(filename)
}
fn test_file_get_line() {
filename := './fgetline.txt'
os.write_file(filename, 'line 1\nline 2')
mut f := os.open_file(filename, 'r', 0) or {
assert false
return
}
line1 := f.get_line() or { '' }
line2 := f.get_line() or { '' }
f.close()
//
//eprintln('line1: $line1')
//eprintln('line2: $line2')
assert line1 == 'line 1\n'
assert line2 == 'line 2'
}
fn test_create_file() {
filename := './test1.txt'
hello := 'hello world!'