Make testing prints and pragmas only enabled under `-ddbg` flag

This commit is contained in:
Tristan B. Velloza Kildaire 2022-12-29 15:55:08 +02:00
parent a3d19fc515
commit ccc2a5cf31
2 changed files with 51 additions and 14 deletions

View File

@ -7,7 +7,6 @@ libpb
## Example usage ## Example usage
### Server initiation ### Server initiation
Firstly we create a new PocketBase instance to manage our server: Firstly we create a new PocketBase instance to manage our server:
@ -84,6 +83,15 @@ This is to show off deserialization method `fromJSON(RecordType)(JSONValue jsonI
//TODO: object test case, list test case //TODO: object test case, list test case
``` ```
## Development
### Unit tests
To run tests you will want to enable the `pragma`s and `writeln`s. therefore pass the `dbg` flag in as such:
```bash
dub test -ddbg
```
## License ## License

View File

@ -119,14 +119,20 @@ public class PocketBase
static foreach(cnt; 0..structTypes.length) static foreach(cnt; 0..structTypes.length)
{ {
pragma(msg, structTypes[cnt]); debug(dbg)
pragma(msg, structNames[cnt]); {
// pragma(msg, structValues[cnt]); pragma(msg, structTypes[cnt]);
pragma(msg, structNames[cnt]);
// pragma(msg, structValues[cnt]);
}
builtJSON[structNames[cnt]] = structValues[cnt]; builtJSON[structNames[cnt]] = structValues[cnt];
} }
writeln(builtJSON.toPrettyString()); debug(dbg)
{
writeln(builtJSON.toPrettyString());
}
return builtJSON; return builtJSON;
} }
@ -145,9 +151,12 @@ public class PocketBase
static foreach(cnt; 0..structTypes.length) static foreach(cnt; 0..structTypes.length)
{ {
pragma(msg, structTypes[cnt]); debug(dbg)
pragma(msg, structNames[cnt]); {
// pragma(msg, structValues[cnt]); pragma(msg, structTypes[cnt]);
pragma(msg, structNames[cnt]);
// pragma(msg, structValues[cnt]);
}
//TODO: Add all integral types //TODO: Add all integral types
static if(__traits(isSame, mixin(structTypes[cnt]), int)) static if(__traits(isSame, mixin(structTypes[cnt]), int))
@ -169,23 +178,39 @@ public class PocketBase
static if(__traits(isSame, mixin(structTypes[cnt]), string)) static if(__traits(isSame, mixin(structTypes[cnt]), string))
{ {
mixin("record."~structNames[cnt]) = jsonIn[structNames[cnt]].str(); mixin("record."~structNames[cnt]) = jsonIn[structNames[cnt]].str();
pragma(msg,"record."~structNames[cnt]);
debug(dbg)
{
pragma(msg,"record."~structNames[cnt]);
}
} }
static if(__traits(isSame, mixin(structTypes[cnt]), JSONValue)) static if(__traits(isSame, mixin(structTypes[cnt]), JSONValue))
{ {
mixin("record."~structNames[cnt]) = jsonIn[structNames[cnt]]; mixin("record."~structNames[cnt]) = jsonIn[structNames[cnt]];
pragma(msg,"record."~structNames[cnt]);
debug(dbg)
{
pragma(msg,"record."~structNames[cnt]);
}
} }
static if(__traits(isSame, mixin(structTypes[cnt]), bool)) static if(__traits(isSame, mixin(structTypes[cnt]), bool))
{ {
mixin("record."~structNames[cnt]) = jsonIn[structNames[cnt]].boolean(); mixin("record."~structNames[cnt]) = jsonIn[structNames[cnt]].boolean();
pragma(msg,"record."~structNames[cnt]);
debug(dbg)
{
pragma(msg,"record."~structNames[cnt]);
}
} }
//FIXME: Not sure how to get array support going, very new to meta programming //FIXME: Not sure how to get array support going, very new to meta programming
static if(__traits(isSame, mixin(structTypes[cnt]), mixin(structTypes[cnt])[])) static if(__traits(isSame, mixin(structTypes[cnt]), mixin(structTypes[cnt])[]))
{ {
mixin("record."~structNames[cnt]) = jsonIn[structNames[cnt]].boolean(); mixin("record."~structNames[cnt]) = jsonIn[structNames[cnt]].boolean();
pragma(msg,"record."~structNames[cnt]);
debug(dbg)
{
pragma(msg,"record."~structNames[cnt]);
}
} }
} }
@ -252,7 +277,11 @@ unittest
Person person = PocketBase.fromJSON!(Person)(json); Person person = PocketBase.fromJSON!(Person)(json);
writeln(person); debug(dbg)
{
writeln(person);
}
assert(cmp(person.firstname, "Tristan") == 0); assert(cmp(person.firstname, "Tristan") == 0);
assert(cmp(person.lastname, "Kildaire") == 0); assert(cmp(person.lastname, "Kildaire") == 0);