1 module rfc6455;
2 
3 public import vibe.http.websockets;
4 
5 version (unittest)
6 {
7 	void safelog(string msg) @trusted @nogc nothrow
8 	{
9 		import core.stdc.stdio : printf;
10 
11 		printf("%.*s\n", msg.length, &msg[0]);
12 	}
13 
14 	void testFunctionality()()
15 	{
16 		void handleConn(scope WebSocket sock)
17 		{
18 			// simple echo server
19 			while (sock.connected)
20 			{
21 				auto msg = sock.receiveText();
22 				sock.send(msg);
23 			}
24 		}
25 
26 		void startServer()
27 		{
28 			import vibe.http.router;
29 
30 			auto router = new URLRouter;
31 			router.get("/ws", handleWebSockets(&handleConn));
32 
33 			// Start HTTP server using listenHTTP()...
34 		}
35 
36 		startServer();
37 	}
38 
39 	unittest
40 	{
41 		testFunctionality();
42 		safelog("package works");
43 	}
44 
45 	@safe unittest
46 	{
47 		static if (__traits(compiles, testFunctionality()))
48 		{
49 			pragma(msg, "package is @safe");
50 		}
51 		else
52 		{
53 			pragma(msg, "package is not @safe");
54 		}
55 	}
56 
57 	@nogc unittest
58 	{
59 		static if (__traits(compiles, testFunctionality()))
60 		{
61 			pragma(msg, "package is @nogc");
62 		}
63 		else
64 		{
65 			pragma(msg, "package is not @nogc");
66 		}
67 	}
68 
69 	nothrow unittest
70 	{
71 		static if (__traits(compiles, testFunctionality()))
72 		{
73 			pragma(msg, "package is nothrow");
74 		}
75 		else
76 		{
77 			pragma(msg, "package is not nothrow");
78 		}
79 	}
80 }