Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small fix #8

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions fakerjs2generator/source/generator.d
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,14 @@ string genMustacheAA(Out)(Mustache[string] m, ref Out o, string[] path
iformat(o, 1, "%sstring %s(%sEnum which) {\n", overWrite ? "override " : ""
, pathToFuncName(path), enumName
);
iformat(o, 2, "final switch(which) {\n", m.length);
iformat(o, 2, "switch(which) {\n", m.length);
foreach(it; m.byKeyValue()) {
iformat(o, 3, "case %sEnum.%s: return ", enumName, it.key);
buildSingleMustache(o, it.value);
formattedWrite(o, ";\n");
}
iformat(o, 3, "default: return \"\";\n");
iformat(o, 2, "}\n");
iformat(o, 2, "return \"\";\n");
iformat(o, 1, "}");
return ret;
}
Expand All @@ -392,15 +392,15 @@ string genChemicalUnit(Out)(ChemicalUnit[] m, ref Out o, string[] path
{
string ret = pathToFuncName(path);
iformat(o, 1, "%sChemicalUnit %s() {\n", overWrite ? "override " : "", ret);
iformat(o, 2, "final switch(uniform(0, %s, this.rnd)) {\n", m.length);
iformat(o, 2, "switch(uniform(0, %s, this.rnd)) {\n", m.length);
foreach(idx, it; m) {
iformat(o, 3, "case %s: return ChemicalUnit(%s, %s)", idx
, `q"{` ~ it.name ~ `}"`
, `q"{` ~ it.symbol ~ `}"`);
formattedWrite(o, ";\n");
}
iformat(o, 3, "default: return ChemicalUnit(\"\",\"\");\n");
iformat(o, 2, "}\n");
iformat(o, 2, "return ChemicalUnit(\"\", \"\");\n");
iformat(o, 1, "}");
return ret;
}
Expand All @@ -410,16 +410,16 @@ string genChemicalElement(Out)(ChemicalElement[] m, ref Out o, string[] path
{
string ret = pathToFuncName(path);
iformat(o, 1, "%sChemicalElement %s() {\n", overWrite ? "override " : "", ret);
iformat(o, 2, "final switch(uniform(0, %s, this.rnd)) {\n", m.length);
iformat(o, 2, "switch(uniform(0, %s, this.rnd)) {\n", m.length);
foreach(idx, it; m) {
iformat(o, 3, "case %s: return ChemicalElement(%s, %s, %s)", idx
, `q"{` ~ it.symbol ~ `}"`
, `q"{` ~ it.name ~ `}"`
, it.atomicNumber);
formattedWrite(o, ";\n");
}
iformat(o, 3, "default: return ChemicalElement(\"\",\"\");\n");
iformat(o, 2, "}\n");
iformat(o, 2, "return ChemicalElement(\"\", \"\", 0);\n");
iformat(o, 1, "}");
return ret;
}
Expand All @@ -429,16 +429,16 @@ string genCurrency(Out)(Currency[] m, ref Out o, string[] path
{
string ret = pathToFuncName(path);
iformat(o, 1, "%sCurrency %s() {\n", overWrite ? "override " : "", pathToFuncName(path));
iformat(o, 2, "final switch(uniform(0, %s, this.rnd)) {\n", m.length);
iformat(o, 2, "switch(uniform(0, %s, this.rnd)) {\n", m.length);
foreach(idx, it; m) {
iformat(o, 3, "case %s: return Currency(%s, %s, %s)", idx
, `q"{` ~ it.name ~ `}"`
, `q"{` ~ it.code ~ `}"`
, `q"{` ~ it.symbol ~ `}"`);
formattedWrite(o, ";\n");
}
iformat(o, 3, "default: return Currency(\"\",\"\",\"\");\n");
iformat(o, 2, "}\n");
iformat(o, 2, "return Currency(\"\", \"\", \"\");\n");
iformat(o, 1, "}");
return ret;
}
Expand All @@ -448,7 +448,7 @@ string genAirplane(Out)(Airplane[] m, ref Out o, string[] path
{
string ret = pathToFuncName(path);
iformat(o, 1, "%sAirplane %s() {\n", overWrite ? "override " : "", ret);
iformat(o, 2, "final switch(uniform(0, %s, this.rnd)) {\n", m.length);
iformat(o, 2, "switch(uniform(0, %s, this.rnd)) {\n", m.length);
foreach(idx, it; m) {
iformat(o, 3, "case %s: return Airplane(%s, %s)", idx
, it.name.isNull()
Expand All @@ -459,8 +459,8 @@ string genAirplane(Out)(Airplane[] m, ref Out o, string[] path
: "nullable(q\"{" ~ it.iataTypeCode.get() ~ "}\")");
formattedWrite(o, ";\n");
}
iformat(o, 3, "default: return Airplane(Nullable!(string).init, Nullable!(string).init);\n");
iformat(o, 2, "}\n");
iformat(o, 2, "return Airplane(Nullable!(string).init, Nullable!(string).init);\n");
iformat(o, 1, "}");
return ret;
}
Expand All @@ -470,7 +470,7 @@ string genAirport(Out)(Airport[] m, ref Out o, string[] path
{
string ret = pathToFuncName(path);
iformat(o, 1, "%sAirport %s() {\n", overWrite ? "override " : "", ret);
iformat(o, 2, "final switch(uniform(0, %s, this.rnd)) {\n", m.length);
iformat(o, 2, "switch(uniform(0, %s, this.rnd)) {\n", m.length);
foreach(idx, it; m) {
iformat(o, 3, "case %s: return Airport(%s, %s)", idx
, it.name.isNull()
Expand All @@ -481,8 +481,8 @@ string genAirport(Out)(Airport[] m, ref Out o, string[] path
: "nullable(q\"{" ~ it.iataCode.get() ~ "}\")");
formattedWrite(o, ";\n");
}
iformat(o, 3, "default: return Airport(Nullable!(string).init, Nullable!(string).init);\n");
iformat(o, 2, "}\n");
iformat(o, 2, "return Airport(Nullable!(string).init, Nullable!(string).init);\n");
iformat(o, 1, "}");
return ret;
}
Expand All @@ -492,7 +492,7 @@ string genAirline(Out)(Airline[] m, ref Out o, string[] path
{
string ret = pathToFuncName(path);
iformat(o, 1, "%sAirline %s() {\n", overWrite ? "override " : "", ret);
iformat(o, 2, "final switch(uniform(0, %s, this.rnd)) {\n", m.length);
iformat(o, 2, "switch(uniform(0, %s, this.rnd)) {\n", m.length);
foreach(idx, it; m) {
iformat(o, 3, "case %s: return Airline(%s, %s)", idx
, it.name.isNull()
Expand All @@ -503,8 +503,8 @@ string genAirline(Out)(Airline[] m, ref Out o, string[] path
: "nullable(q\"{" ~ it.iataCode.get() ~ "}\")");
formattedWrite(o, ";\n");
}
iformat(o, 3, "default: return Airline(Nullable!(string).init, Nullable!(string).init);\n");
iformat(o, 2, "}\n");
iformat(o, 2, "return Airline(Nullable!(string).init, Nullable!(string).init);\n");
iformat(o, 1, "}");
return ret;
}
Expand All @@ -514,14 +514,14 @@ string genMustache(Out)(Mustache[] m, ref Out o, string[] path
{
string ret = pathToFuncName(path);
iformat(o, 1, "%sstring %s() {\n", overWrite ? "override " : "", ret);
iformat(o, 2, "final switch(uniform(0, %s, this.rnd)) {\n", m.length);
iformat(o, 2, "switch(uniform(0, %s, this.rnd)) {\n", m.length);
foreach(idx, it; m) {
iformat(o, 3, "case %s: return ", idx);
buildSingleMustache(o, it);
formattedWrite(o, ";\n");
}
iformat(o, 3, "default: return \"\";\n");
iformat(o, 2, "}\n");
iformat(o, 2, "return \"\";\n");
iformat(o, 1, "}");
return ret;
}
Expand Down Expand Up @@ -665,7 +665,7 @@ class Faker_base {
}

final string internetEmoji() {
final switch(uniform(0, 10, this.rnd)) {
switch(uniform(0, 10, this.rnd)) {
case 0: return this.internetEmojiSmiley();
case 1: return this.internetEmojiBody();
case 2: return this.internetEmojiPerson();
Expand All @@ -676,6 +676,7 @@ class Faker_base {
case 7: return this.internetEmojiObject();
case 8: return this.internetEmojiSymbol();
case 9: return this.internetEmojiFlag();
default: return "";
}
}

Expand Down
8 changes: 4 additions & 4 deletions source/faked/faker_af_za.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class Faker_af_za : Faker_en {
}

override string locationCityPattern() {
final switch(uniform(0, 1, this.rnd)) {
switch(uniform(0, 1, this.rnd)) {
case 0: return locationCityName();
default: return "";
}
return "";
}

override string locationDefaultCountry() {
Expand All @@ -82,11 +82,11 @@ class Faker_af_za : Faker_en {
}

override string locationStreetPattern() {
final switch(uniform(0, 2, this.rnd)) {
switch(uniform(0, 2, this.rnd)) {
case 0: return personFirstName() ~ " " ~ locationStreetSuffix();
case 1: return personLastName() ~ " " ~ locationStreetSuffix();
default: return "";
}
return "";
}

override string personFemaleFirstName() {
Expand Down
16 changes: 8 additions & 8 deletions source/faked/faker_ar.d
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ class Faker_ar : Faker_en {
}

override string locationCityPattern() {
final switch(uniform(0, 1, this.rnd)) {
switch(uniform(0, 1, this.rnd)) {
case 0: return locationCityName();
default: return "";
}
return "";
}

override string locationCountry() {
Expand Down Expand Up @@ -261,19 +261,19 @@ class Faker_ar : Faker_en {
}

override string locationStreetAddress(LocationStreetAddressEnum which) {
final switch(which) {
switch(which) {
case LocationStreetAddressEnum.normal: return locationBuildingNumber() ~ " " ~ locationStreet();
case LocationStreetAddressEnum.full: return locationBuildingNumber() ~ " " ~ locationStreet() ~ " " ~ locationSecondaryAddress();
default: return "";
}
return "";
}

override string locationStreetPattern() {
final switch(uniform(0, 2, this.rnd)) {
switch(uniform(0, 2, this.rnd)) {
case 0: return locationStreetPrefix() ~ " " ~ personFirstName();
case 1: return locationStreetPrefix() ~ " " ~ personLastName();
default: return "";
}
return "";
}

string locationStreetPrefix() {
Expand Down Expand Up @@ -669,10 +669,10 @@ class Faker_ar : Faker_en {
}

override string teamName() {
final switch(uniform(0, 1, this.rnd)) {
switch(uniform(0, 1, this.rnd)) {
case 0: return locationState() ~ " " ~ teamCreature();
default: return "";
}
return "";
}

override string vehicleFuel() {
Expand Down
16 changes: 8 additions & 8 deletions source/faked/faker_az.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class Faker_az : Faker_en {
}

override string companyNamePattern() {
final switch(uniform(0, 3, this.rnd)) {
switch(uniform(0, 3, this.rnd)) {
case 0: return companyPrefix() ~ " " ~ personFemaleFirstName();
case 1: return companyPrefix() ~ " " ~ personMaleFirstName();
case 2: return companyPrefix() ~ " " ~ personMaleLastName();
default: return "";
}
return "";
}

string companyPrefix() {
Expand Down Expand Up @@ -139,10 +139,10 @@ class Faker_az : Faker_en {
}

override string locationCityPattern() {
final switch(uniform(0, 1, this.rnd)) {
switch(uniform(0, 1, this.rnd)) {
case 0: return locationCityName();
default: return "";
}
return "";
}

override string locationCountry() {
Expand Down Expand Up @@ -220,11 +220,11 @@ class Faker_az : Faker_en {
}

override string locationStreetAddress(LocationStreetAddressEnum which) {
final switch(which) {
switch(which) {
case LocationStreetAddressEnum.normal: return locationStreet() ~ ", " ~ locationBuildingNumber();
case LocationStreetAddressEnum.full: return locationStreet() ~ ", " ~ locationBuildingNumber() ~ " " ~ locationSecondaryAddress();
default: return "";
}
return "";
}

override string locationStreetName() {
Expand Down Expand Up @@ -293,11 +293,11 @@ class Faker_az : Faker_en {
}

override string locationStreetPattern() {
final switch(uniform(0, 2, this.rnd)) {
switch(uniform(0, 2, this.rnd)) {
case 0: return locationStreetSuffix() ~ " " ~ locationStreetName();
case 1: return locationStreetName() ~ " " ~ locationStreetSuffix();
default: return "";
}
return "";
}

override string locationStreetSuffix() {
Expand Down
3 changes: 2 additions & 1 deletion source/faked/faker_base.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Faker_base {
}

final string internetEmoji() {
final switch(uniform(0, 10, this.rnd)) {
switch(uniform(0, 10, this.rnd)) {
case 0: return this.internetEmojiSmiley();
case 1: return this.internetEmojiBody();
case 2: return this.internetEmojiPerson();
Expand All @@ -60,6 +60,7 @@ class Faker_base {
case 7: return this.internetEmojiObject();
case 8: return this.internetEmojiSymbol();
case 9: return this.internetEmojiFlag();
default: return "";
}
}

Expand Down
16 changes: 8 additions & 8 deletions source/faked/faker_cs_cz.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Faker_cs_cz : Faker_en {
}

override string companyNamePattern() {
final switch(uniform(0, 2, this.rnd)) {
switch(uniform(0, 2, this.rnd)) {
case 0: return personLastName() ~ " " ~ companySuffix();
case 1: return personMaleLastName() ~ " a " ~ personMaleLastName() ~ " " ~ companySuffix();
default: return "";
}
return "";
}

override string companySuffix() {
Expand Down Expand Up @@ -208,10 +208,10 @@ class Faker_cs_cz : Faker_en {
}

override string locationCityPattern() {
final switch(uniform(0, 1, this.rnd)) {
switch(uniform(0, 1, this.rnd)) {
case 0: return locationCityName();
default: return "";
}
return "";
}

override string locationCountry() {
Expand Down Expand Up @@ -289,11 +289,11 @@ class Faker_cs_cz : Faker_en {
}

override string locationStreetAddress(LocationStreetAddressEnum which) {
final switch(which) {
switch(which) {
case LocationStreetAddressEnum.normal: return locationStreet() ~ " " ~ locationBuildingNumber();
case LocationStreetAddressEnum.full: return locationStreet() ~ " " ~ locationBuildingNumber() ~ " " ~ locationSecondaryAddress();
default: return "";
}
return "";
}

override string locationStreetName() {
Expand Down Expand Up @@ -1756,10 +1756,10 @@ class Faker_cs_cz : Faker_en {
}

override string locationStreetPattern() {
final switch(uniform(0, 1, this.rnd)) {
switch(uniform(0, 1, this.rnd)) {
case 0: return locationStreetName();
default: return "";
}
return "";
}

override string loremWords() {
Expand Down
Loading
Loading