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

net: use mut and refs as receivers consistently (#8205)

This commit is contained in:
Delyan Angelov
2021-01-20 12:11:01 +02:00
committed by GitHub
parent 158aefc37f
commit d92f5c55ba
15 changed files with 236 additions and 206 deletions

View File

@@ -3,7 +3,7 @@ import smtp
import time
// Used to test that a function call returns an error
fn fn_errors(c smtp.Client, m smtp.Mail) bool {
fn fn_errors(mut c smtp.Client, m smtp.Mail) bool {
c.send(m) or { return true }
return false
}
@@ -14,7 +14,9 @@ fn fn_errors(c smtp.Client, m smtp.Mail) bool {
* Created by: nedimf (07/2020)
*/
fn test_smtp() {
$if !network ? { return }
$if !network ? {
return
}
client_cfg := smtp.Client{
server: 'smtp.mailtrap.io'
@@ -32,20 +34,57 @@ fn test_smtp() {
body: 'Plain text'
}
mut client := smtp.new_client(client_cfg) or { assert false return }
mut client := smtp.new_client(client_cfg) or {
assert false
return
}
assert true
client.send(send_cfg) or { assert false return }
client.send(send_cfg) or {
assert false
return
}
assert true
// client.send({ send_cfg | body_type: .html, body: '<html><h1>HTML V email!</h1></html>' }) or { assert false return }
client.send({ send_cfg | from: 'alexander@vlang.io' }) or { assert false return }
client.send({ send_cfg | cc: 'alexander@vlang.io,joe@vlang.io', bcc: 'spytheman@vlang.io' }) or { assert false return }
client.send({ send_cfg | date: time.now().add_days(1000) }) or { assert false return }
client.send({
send_cfg |
from: 'alexander@vlang.io'
}) or {
assert false
return
}
client.send({
send_cfg |
cc: 'alexander@vlang.io,joe@vlang.io'
bcc: 'spytheman@vlang.io'
}) or {
assert false
return
}
client.send({
send_cfg |
date: time.now().add_days(1000)
}) or {
assert false
return
}
assert true
client.quit() or { assert false return }
client.quit() or {
assert false
return
}
assert true
// This call should return an error, since the connection is closed
if !fn_errors(client, send_cfg) { assert false return }
client.reconnect() or { assert false return }
client.send(send_cfg) or { assert false return }
if !fn_errors(mut client, send_cfg) {
assert false
return
}
client.reconnect() or {
assert false
return
}
client.send(send_cfg) or {
assert false
return
}
assert true
}