Skip to content

Commit

Permalink
Enhance unit tests for set methods in Json handling; add tests for bo…
Browse files Browse the repository at this point in the history
…ol, int, long, double, and string values
  • Loading branch information
UIMSolutions committed Jan 18, 2025
1 parent 850211d commit 22c5801
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 38 deletions.
5 changes: 5 additions & 0 deletions core/uim/core/containers/maps/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ STRINGAA getStrings(Json[string] values, string[] keys) {

unittest {
Json[string] values;

Json testArray = Json.emptyArray;
testArray ~= "A";
testArray ~= "B";

values["a"] = Json("A");
values["b"] = "B".toJson;
assert(values.getStrings(["a"]) == ["a": "A"]);
Expand Down
133 changes: 98 additions & 35 deletions core/uim/core/containers/maps/values/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,120 @@ unittest {
V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, bool value) {
return set(items, keys, Json(value));
}
unittest {
Json[string] testmap;
assert(set(testmap, ["a", "b"], true)["a"].getBoolean == true);
assert(set(testmap, ["c", "d"], false)["c"].getBoolean == false);
}

V[K] set(K, V:Json)(auto ref V[K] items, K key, bool value) {
return set(items, key, Json(value));
}

V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, int value) {
return set(items, keys, Json(value));
}

V[K] set(K, V:Json)(auto ref V[K] items, K key, int value) {
return set(items, key, Json(value));
unittest {
Json[string] testmap;
assert(set(testmap, "a", true)["a"].getBoolean == true);
assert(set(testmap, "b", false)["b"].getBoolean == false);
}

V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, long value) {
return set(items, keys, Json(value));
}

V[K] set(K, V:Json)(auto ref V[K] items, K key, long value) {
return set(items, key, Json(value));
}
// #region set(K, V:Json)(..., int value)
V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, int value) {
return set(items, keys, Json(value));
}
unittest {
Json[string] testmap;
assert(set(testmap, ["a", "b"], 1)["a"].getLong == 1);
assert(set(testmap, ["c", "d"], 2)["c"].getLong == 2);
}

V[K] set(K, V:Json)(auto ref V[K] items, K key, int value) {
return set(items, key, Json(value));
}
unittest {
Json[string] testmap;
assert(set(testmap, "a", 1)["a"].getLong == 1);
assert(set(testmap, "b", 2)["b"].getLong == 2);
}
// #endregion set(K, V:Json)(..., int value)

// #region set(K, V:Json)(..., long value)
V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, long value) {
return set(items, keys, Json(value));
}
unittest {
Json[string] testmap;
assert(set(testmap, ["a", "b"], 1)["a"].getLong == 1);
assert(set(testmap, ["c", "d"], 2)["c"].getLong == 2);
}

V[K] set(K, V:Json)(auto ref V[K] items, K key, long value) {
return set(items, key, Json(value));
}
unittest {
Json[string] testmap;
assert(set(testmap, "a", 1)["a"].getLong == 1);
assert(set(testmap, "b", 2)["b"].getLong == 2);
}
// #endregion set(K, V:Json)(..., long value)

V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, double value) {
return set(items, keys, Json(value));
}
unittest {
Json[string] testmap;
assert(set(testmap, ["a", "b"], 1.1)["a"].getDouble == 1.1);
assert(set(testmap, ["c", "d"], 2.1)["c"].getDouble == 2.1);
}

V[K] set(K, V:Json)(auto ref V[K] items, K key, double value) {
return set(items, key, Json(value));
}

V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, string value) {
return set(items, keys, Json(value));
}

V[K] set(K, V:Json)(auto ref V[K] items, K key, string value) {
return set(items, key, Json(value));
}

V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, Json value) {
keys.each!(key => set(items, key, value));
return items;
unittest {
Json[string] testmap;
assert(set(testmap, "a", 1.1)["a"].getDouble == 1.1);
assert(set(testmap, "b", 2.1)["b"].getDouble == 2.1);
}

/* V[K] set(K, V:Json)(auto ref V[K] items, K key, STRINGAA value) {
items[key] = value.toJson;
return items;
} */

V[K] set(K, V:Json)(auto ref V[K] items, K key, Json value) {
items[key] = value;
return items;
}
// #region set(K, V:Json)(..., string value)
V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, string value) {
return set(items, keys, Json(value));
}
unittest {
Json[string] testmap;
assert(set(testmap, ["a", "b"], "one")["a"].getString == "one");
assert(set(testmap, ["c", "d"], "two")["c"].getString == "two");
}

V[K] set(K, V:Json)(auto ref V[K] items, K key, string value) {
return set(items, key, Json(value));
}
unittest {
Json[string] testmap;
assert(set(testmap, "a", "one")["a"].getString == "one");
assert(set(testmap, "b", "two")["b"].getString == "two");
}
// #endregion set(K, V:Json)(..., string value)

// #region set(K, V:Json)(..., Json value)
V[K] set(K, V:Json)(auto ref V[K] items, K[] keys, Json value) {
keys.each!(key => set(items, key, value));
return items;
}
unittest {
Json[string] testmap;
assert(set(testmap, ["a", "b"], Json("one"))["a"].getString == "one");
assert(set(testmap, ["c", "d"], Json("two"))["c"].getString == "two");
}

V[K] set(K, V:Json)(auto ref V[K] items, K key, Json value) {
items[key] = value;
return items;
}
unittest {
Json[string] testmap;
assert(set(testmap, "a", Json("one"))["a"].getString == "one");
assert(set(testmap, "b", Json("two"))["b"].getString == "two");
}
// #endregion set(K, V:Json)(..., Json value)

V[K] set(K, V:Json)(auto ref V[K] items, K key, string[] value) {
return set(items, key, value.map!(v => Json(v)).array);
Expand Down
98 changes: 95 additions & 3 deletions core/uim/core/containers/maps/values/string_.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,110 @@ unittest {
}

// #region set
V[K] set(K, V:string, T)(V[K] items, K key, T value) if (!is(T == string) && !is(T == Json)) {
/* V[K] set(K, V:string, T)(auto ref V[K] items, K key, T value) if (!is(T == string) && !is(T == Json)) {
return items.set(key, to!string(value));
} */

// #region V[K] set(K, V:string)(..., bool value)
V[K] set(K, V:string)(auto ref V[K] items, K[] keys, bool value) {
return set(items, keys, value ? "true" : "false");
}
unittest {
string[string] testmap;
assert(set(testmap, ["a", "b"], true)["a"] == "true");
assert(set(testmap, ["c", "d"], false)["c"] == "false");
}

V[K] set(K, V:string)(auto ref V[K] items, K key, bool value) {
return set(items, key, value ? "true" : "false");
}
unittest {
string[string] testmap;
assert(set(testmap, "a", true)["a"] == "true");
assert(set(testmap, "b", false)["b"] == "false");
}
// #endregion V[K] set(K, V:string)(..., bool value)

// #region V[K] set(K, V:string)(..., int value)
V[K] set(K, V:string)(auto ref V[K] items, K[] keys, int value) {
return set(items, keys, to!string(value));
}
unittest {
string[string] testmap;
writeln(set(testmap, ["a", "b"], 0));
assert(set(testmap, ["a", "b"], 0)["a"] == "0");
assert(set(testmap, ["c", "d"], 1)["c"] == "1");
}

V[K] set(K, V:string)(auto ref V[K] items, K key, int value) {
return set(items, key, to!string(value));
}
unittest {
string[string] testmap;
assert(set(testmap, "a", 0)["a"] == "0");
assert(set(testmap, "b", 1)["b"] == "1");
}
// #endregion V[K] set(K, V:string)(..., int value)

// #region V[K] set(K, V:string)(..., long value)
V[K] set(K, V:string)(auto ref V[K] items, K[] keys, long value) {
return set(items, keys, to!string(value));
}
unittest {
string[string] testmap;
writeln(set(testmap, ["a", "b"], 0));
assert(set(testmap, ["a", "b"], 0)["a"] == "0");
assert(set(testmap, ["c", "d"], 1)["c"] == "1");
}

V[K] set(K, V:string)(auto ref V[K] items, K key, long value) {
return set(items, key, to1string(value));
}
unittest {
string[string] testmap;
assert(set(testmap, "a", 0)["a"] == "0");
assert(set(testmap, "b", 1)["b"] == "1");
}
// #endregion V[K] set(K, V:string)(..., long value)

// #region V[K] set(K, V:string)(..., double value)
V[K] set(K, V:string)(auto ref V[K] items, K[] keys, double value) {
return set(items, keys, to!string(value));
}
unittest {
string[string] testmap;
assert(set(testmap, ["a", "b"], 0.1)["a"] == "0.1");
assert(set(testmap, ["c", "d"], 1.1)["c"] == "1.1");
}

V[K] set(K, V:string)(auto ref V[K] items, K key, double value) {
return set(items, key, to!string(value));
}
unittest {
string[string] testmap;
assert(set(testmap, "a", 0.1)["a"] == "0.1");
assert(set(testmap, "b", 1.1)["b"] == "1.1");
}
// #endregion V[K] set(K, V:string)(..., double value)

V[K] set(K, V:string)(auto ref V[K] items, K key, Json value) {
return items.set(key, value.toString);
}

V[K] set(K, V:string)(V[K] items, K key, Json value) {
V[K] set(K, V:string)(auto ref V[K] items, K key, Json value) {
return items.set(key, value.toString);
}

V[K] set(K, V:string)(V[K] items, K key, V value) {
// #region V[K] set(K, V:string)(..., string value)
V[K] set(K, V:string)(auto ref V[K] items, K[] keys, string value) {
keys.each!(key => set(items, key, value));
return items;
}
V[K] set(K, V:string)(auto ref V[K] items, K key, string value) {
items[key] = value;
return items;
}
// #endregion V[K] set(K, V:string)(..., string value)

unittest {
string[string] testmap;
Expand Down

0 comments on commit 22c5801

Please sign in to comment.