v2 / vlib / v / tests / websocket_logger_interface_should_compile_test.v
69 lines · 54 sloc · 1.13 KB · a80bc2331450fc28c900097f8afafe173f161d27
Raw
1// vtest build: !windows && present_openssl?
2import net.websocket as ws
3
4pub type RawMessage = ws.Message
5
6pub struct WsTransport {
7pub mut:
8 ws ws.Client
9}
10
11struct WsClient {
12pub mut:
13 transport Transport
14}
15
16pub interface Transport {
17 send()
18 wait()
19}
20
21fn (wst WsTransport) send() {
22 println('send is called')
23}
24
25fn (wst WsTransport) wait() {
26 println('wait is called')
27}
28
29pub fn new_ws_client(transport Transport) !WsClient {
30 return WsClient{
31 transport: transport
32 }
33}
34
35fn server() ! {
36 mut s := ws.new_server(.ip6, 8081, '/')
37
38 s.on_connect(fn (mut s ws.ServerClient) !bool {
39 if s.resource_name != '/' {
40 return false
41 }
42 println('Client has connected...')
43 return true
44 })!
45
46 s.on_message(fn (mut ws_ ws.Client, msg &RawMessage) ! {
47 mut transport := WsTransport{}
48 mut ws_client := new_ws_client(transport)!
49 _ := ws_client
50 })
51
52 s.on_close(fn (mut ws_ ws.Client, code int, reason string) ! {
53 println('client (${ws_.id}) closed connection')
54 })
55
56 s.listen() or { println('error on server listen: ${err}') }
57
58 unsafe {
59 s.free()
60 }
61}
62
63fn abc() ! {
64 server()!
65}
66
67fn test_compilation_of_the_example_code_in_issue_15839() {
68 assert true
69}
70