1 module vksdk.objects.base.RequestParam; 2 3 import vibe.data.json; 4 5 struct RequestParam { 6 7 @name("key") 8 string key; 9 10 @name("value") 11 string value; 12 13 size_t toHash() const pure nothrow { 14 size_t hash = value.hashOf(); 15 hash = key.hashOf(hash); 16 return hash; 17 } 18 19 bool opEquals(RequestParam requestParam) const @safe pure nothrow { 20 return key == requestParam.key && value == requestParam.value; 21 } 22 23 string toString() { 24 return "RequestParam{" 25 ~ "key='" ~ key ~ "'" 26 ~ ", value='" ~ value ~ "'" 27 ~ "}"; 28 } 29 } 30 31 unittest { 32 RequestParam element1; 33 element1.key = "key1"; 34 element1.value = "value1"; 35 36 RequestParam element2; 37 element2.key = "key1"; 38 element2.value = "value1"; 39 40 assert(element1 == element2); 41 } 42 43 unittest { 44 RequestParam element1; 45 element1.key = "key1"; 46 element1.value = "value1"; 47 48 RequestParam element2; 49 element2.key = "key2"; 50 element2.value = "value2"; 51 52 assert(element1 != element2); 53 } 54 55 unittest { 56 string requestParamsString = "RequestParam{key='key1', value='value1'}"; 57 58 RequestParam element; 59 element.key = "key1"; 60 element.value = "value1"; 61 62 assert(element.toString == requestParamsString); 63 } 64 65 unittest { 66 RequestParam element1; 67 element1.key = "key1"; 68 element1.value = "value1"; 69 70 RequestParam element2; 71 element2.key = "key1"; 72 element2.value = "value1"; 73 74 import std.stdio; 75 writeln(element1.toHash); 76 writeln(element2.toHash); 77 78 assert(element1.toHash == element2.toHash); 79 }