mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: add input_password(prompt) and unit tests (#15507)
This commit is contained in:
8
examples/password/correct.expect
Executable file
8
examples/password/correct.expect
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/expect
|
||||
spawn ./password
|
||||
expect "Enter your password : "
|
||||
send "Sample\r"
|
||||
expect "Confirm password : "
|
||||
send "Sample\r"
|
||||
expect "Password confirmed! You entered: Sample ."
|
||||
expect eof
|
8
examples/password/incorrect.expect
Executable file
8
examples/password/incorrect.expect
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/expect
|
||||
spawn ./password
|
||||
expect "Enter your password : "
|
||||
send "Sample123\r"
|
||||
expect "Confirm password : "
|
||||
send "Sample234\r"
|
||||
expect "Passwords do not match ."
|
||||
expect eof
|
14
examples/password/password.v
Normal file
14
examples/password/password.v
Normal file
@ -0,0 +1,14 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
|
||||
fn main() {
|
||||
original_password := os.input_password('Enter your password : ')!
|
||||
repeated_password := os.input_password('Confirm password : ')!
|
||||
|
||||
if original_password == repeated_password {
|
||||
println('Password confirmed! You entered: $original_password .')
|
||||
} else {
|
||||
println('Passwords do not match .')
|
||||
}
|
||||
}
|
3
examples/password/password_ci.vsh
Normal file
3
examples/password/password_ci.vsh
Normal file
@ -0,0 +1,3 @@
|
||||
chdir('examples/password')?
|
||||
assert execute('./correct.expect').exit_code == 0
|
||||
assert execute('./incorrect.expect').exit_code == 0
|
Reference in New Issue
Block a user