Initial project import
This commit is contained in:
commit
23f2d29e32
11957 files changed
+1754577
No files matched your search
@@ -0,0 +1,30 @@
|
||||
module main
|
||||
|
||||
import readline
|
||||
|
||||
fn main() {
|
||||
run() or { panic('${err}') }
|
||||
}
|
||||
|
||||
fn run() ! {
|
||||
$if windows {
|
||||
eprintln('skipping on Windows, since raw mode and read_char are not yet implemented.')
|
||||
return
|
||||
} $else {
|
||||
// Explicit comptime block for other OSes than Windows is required to not break compilation on Windows.
|
||||
mut r := readline.Readline{}
|
||||
r.enable_raw_mode_nosig()
|
||||
defer {
|
||||
r.disable_raw_mode()
|
||||
}
|
||||
|
||||
for {
|
||||
entered := r.read_char()!
|
||||
if entered == `q` {
|
||||
break
|
||||
}
|
||||
println('got ${entered}')
|
||||
}
|
||||
println('Goodbye.')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
// Expect has to be installed for the test.
|
||||
const expect_exe = os.find_abs_path_of_executable('expect') or {
|
||||
eprintln('skipping test, since expect is missing')
|
||||
exit(0)
|
||||
}
|
||||
// Directory that contains the Expect scripts used in the test.
|
||||
const expect_tests_path = os.join_path(@VMODROOT, 'examples', 'readline', 'tests')
|
||||
|
||||
fn test_password_input() {
|
||||
correct := os.execute(os.join_path(expect_tests_path, 'readline.expect'))
|
||||
assert correct.exit_code == 0, correct.output
|
||||
|
||||
send_a := 'a'
|
||||
expect_a := 'got 97' // readline output for `a`
|
||||
a_res :=
|
||||
os.execute('${os.join_path(expect_tests_path, 'readline_from_expect_arg.expect')} ${send_a} "${expect_a}"')
|
||||
assert a_res.exit_code == 0, a_res.output
|
||||
|
||||
send_b := 'b'
|
||||
b_res :=
|
||||
os.execute('${os.join_path(expect_tests_path, 'readline_from_expect_arg.expect')} ${send_b} "${expect_a}"')
|
||||
assert b_res.exit_code == 1, b_res.output
|
||||
assert b_res.output.contains('got 98')
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env expect
|
||||
|
||||
set timeout 3
|
||||
set v_root [exec sh -c "git rev-parse --show-toplevel"]
|
||||
|
||||
spawn $v_root/v run $v_root/examples/readline/readline.v
|
||||
|
||||
send "a"
|
||||
expect "got 97" {} timeout { exit 1 }
|
||||
send "1"
|
||||
expect "got 49" {} timeout { exit 1 }
|
||||
send "q"
|
||||
expect "Goodbye." {} timeout { exit 1 }
|
||||
|
||||
expect eof
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env expect
|
||||
|
||||
set timeout 3
|
||||
set v_root [exec sh -c "git rev-parse --show-toplevel"]
|
||||
# Use input arguments for send and expect.
|
||||
set send_ [lindex $argv 0]
|
||||
set expect_ [lindex $argv 1]
|
||||
|
||||
spawn $v_root/v run $v_root/examples/readline/readline.v
|
||||
|
||||
send $send_
|
||||
expect $expect_ {} timeout { exit 1 }
|
||||
|
||||
expect eof
|
||||
Reference in new issue
Block a user