1 module rfc6901;
2 
3 public import vision.json.pointer;
4 
5 version (unittest)
6 {
7 	import std.json;
8 
9 	void safelog(string msg) @trusted @nogc nothrow
10 	{
11 		import core.stdc.stdio : printf;
12 
13 		printf("%.*s\n", msg.length, &msg[0]);
14 	}
15 
16 	void testFunctionality()(JSONValue j)
17 	{
18 		assert(JsonPointer("/language").evaluate(j).str == "D");
19 		assert(JsonPointer("/rating").evaluate(j).floating == 3.5);
20 		assert(JsonPointer("/o/p1").evaluate(j).integer == 5);
21 		assert(JsonPointer("/a/3").evaluate(j).integer == 4);
22 	}
23 
24 	unittest
25 	{
26 		string s = `{ "language": "D", "rating": 3.5, "code": "42", "o": {"p1": 5, "p2": 6}, "a": [1,2,3,4,5] }`;
27 		JSONValue j = parseJSON(s);
28 
29 		testFunctionality(j);
30 		safelog("package works");
31 
32 		static assert(__traits(compiles, testFunctionality(JSONValue.init)), "package doesn't work");
33 	}
34 
35 	@safe unittest
36 	{
37 		static if (__traits(compiles, testFunctionality(JSONValue.init)))
38 		{
39 			pragma(msg, "package is @safe");
40 		}
41 		else
42 		{
43 			pragma(msg, "package is not @safe");
44 		}
45 	}
46 
47 	@nogc unittest
48 	{
49 		static if (__traits(compiles, testFunctionality(JSONValue.init)))
50 		{
51 			pragma(msg, "package is @nogc");
52 		}
53 		else
54 		{
55 			pragma(msg, "package is not @nogc");
56 		}
57 	}
58 
59 	nothrow unittest
60 	{
61 		static if (__traits(compiles, testFunctionality(JSONValue.init)))
62 		{
63 			pragma(msg, "package is nothrow");
64 		}
65 		else
66 		{
67 			pragma(msg, "package is not nothrow");
68 		}
69 	}
70 }