Skip to content

Commit

Permalink
Add static array test for JsonSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Heromyth committed Dec 14, 2021
1 parent 1c1958c commit 0f160c4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
4 changes: 4 additions & 0 deletions examples/test/source/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,14 @@ class GreetingSettings : GreetingSettingsBase {

}

/**
*
*/
class GreetingBase {
int id;
private string content;


this() {

}
Expand Down
25 changes: 18 additions & 7 deletions examples/test/source/test/DeductionTest.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module test.DeductionTest;

import common;
import hunt.logging.ConsoleLogger;

import std.traits;
import hunt.util.Traits;

import std.conv;
import std.traits;

class DeductionTest {

Expand All @@ -23,10 +23,15 @@ class DeductionTest {
// deduce(greetings);
// }

// {
// GreetingBase[string][] greetings;
// deduce(greetings);
// }

{
GreetingBase[string][] greetings;
GreetingBase[2] greetings;
deduce(greetings);
}
}
}

// void testConstructor() {
Expand Down Expand Up @@ -55,6 +60,8 @@ alias CaseSensitive = Flag!"caseSensitive";

void deduce(T, CaseSensitive sensitive = CaseSensitive.yes)(T v) { // if(!is(T == class))
trace(sensitive);


static if(is(T : U[], U)) {
tracef("T[], T: %s, U: %s", T.stringof, U.stringof);

Expand All @@ -67,6 +74,10 @@ void deduce(T, CaseSensitive sensitive = CaseSensitive.yes)(T v) { // if(!is(T =
static if(is(U : S[K], S, K)) {
infof("T[][], T: %s, U: %s, S: %s, K: %s", T.stringof, U.stringof, S.stringof, K.stringof);
}

static if(isStaticArray!(T)) {
infof("T[]: %s[%d]", U.stringof, T.length);
}
}


Expand Down Expand Up @@ -102,9 +113,9 @@ void deduce(T, CaseSensitive sensitive = CaseSensitive.yes)(T v) { // if(!is(T =
// }
// }

void deduce(T : U[], U)(T v) if(is(U == class)) {
infof("Array, T: %s, U: %s", T.stringof, U.stringof);
}
// void deduce(T : U[], U)(T v) if(is(U == class)) {
// infof("Array, T: %s, U: %s", T.stringof, U.stringof);
// }

// void deduce(T)(T v) if(is(T : U[], U) && is(U == interface)) {
// static if(is(T : U[], U)) {
Expand Down
42 changes: 41 additions & 1 deletion examples/test/source/test/JsonSerializerTest.d
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,28 @@ class JsonSerializerTest1 {
}
}
}

void testStaticArray01() {

StaticArrayTester b = new StaticArrayTester();

SimpleCode tempCode = new SimpleCode();
tempCode.number = 12;
b.codes[1] = tempCode;

b.strings[1] = "test";

JSONValue js = toJson(b);

string str = js.toPrettyString();

trace(str);

StaticArrayTester b2 = toObject!(StaticArrayTester)(str);
assert(b2.codes[1].number == b.codes[1].number);

trace(b.strings[1]);
}
}


Expand Down Expand Up @@ -719,4 +741,22 @@ class GroupSkuModelMessage
@JsonProperty("used_num")
int usedNum;

}
}


class SimpleCode {
int number;
}


class StaticArrayTester {
SimpleCode[4] codes;
string[4] strings;

this() {
SimpleCode code = new SimpleCode();
code.number = 10;

codes[0] = code;
}
}

0 comments on commit 0f160c4

Please sign in to comment.