1 module rfc1867;
2 
3 public import vibe.inet.webform;
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 		import vibe.stream.memory;
17 
18 		auto content_type = "multipart/form-data; boundary=\"AaB03x\"";
19 
20 		auto input = createMemoryStream(cast(ubyte[])(
21 				"--AaB03x\r\n" ~
22 				"Content-Disposition: form-data; name=submitname\r\n" ~
23 				"\r\n" ~
24 				"Larry\r\n" ~
25 				"--AaB03x\r\n" ~
26 				"Content-Disposition: form-data; name=files; filename=file1.txt\r\n" ~
27 				"Content-Type: text/plain\r\n" ~
28 				"Content-Length: 29\r\n" ~
29 				"\r\n" ~
30 				"... contents of file1.txt ...\r\n" ~
31 				"--AaB03x--\r\n").dup, false);
32 
33 		FormFields fields;
34 		FilePartFormFields files;
35 
36 		parseMultiPartForm(fields, files, content_type, input, 4096);
37 
38 		assert(fields["submitname"] == "Larry");
39 		assert(files["files"].filename == "file1.txt");
40 	}
41 
42 	unittest
43 	{
44 		testFunctionality();
45 		safelog("package works");
46 	}
47 
48 	@safe unittest
49 	{
50 		static if (__traits(compiles, testFunctionality()))
51 		{
52 			pragma(msg, "package is @safe");
53 		}
54 		else
55 		{
56 			pragma(msg, "package is not @safe");
57 		}
58 	}
59 
60 	@nogc unittest
61 	{
62 		static if (__traits(compiles, testFunctionality()))
63 		{
64 			pragma(msg, "package is @nogc");
65 		}
66 		else
67 		{
68 			pragma(msg, "package is not @nogc");
69 		}
70 	}
71 
72 	nothrow unittest
73 	{
74 		static if (__traits(compiles, testFunctionality()))
75 		{
76 			pragma(msg, "package is nothrow");
77 		}
78 		else
79 		{
80 			pragma(msg, "package is not nothrow");
81 		}
82 	}
83 }