Skip to content

Commit

Permalink
generalize schema tests for all locales. (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
bchavez authored Dec 21, 2023
1 parent bd43a1e commit c20f163
Show file tree
Hide file tree
Showing 51 changed files with 2,183 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#if NET6_0_OR_GREATER
using Argon;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using VerifyTests;
using VerifyXunit;
using Xunit;
using Z.ExtensionMethods;
using static VerifyXunit.Verifier;

namespace Bogus.Tests.SchemaTests;
Expand All @@ -24,20 +26,37 @@ public static void Init()


[UsesVerify]
public class EnLocaleSchemaTests
public class LocaleSchemaTests
{
[Fact]
public Task ensure_wellknown_en_locale_schema()
const string DataFolder = "../../../../Bogus/data/";

[Theory]
[MemberData(nameof(GetLocaleCodes))]
public Task ensure_wellknown_locale_schema(string localeCode)
{
var localeJson = File.ReadAllText("../../../../Bogus/data/en.locale.json");
var localeFile = Path.Combine(DataFolder, $"{localeCode}.locale.json");

var localeJsonRaw = File.ReadAllText(localeFile);

var enLocale = JToken.Parse(localeJson);
var locale = JToken.Parse(localeJsonRaw);

var settings = new VerifySettings();

settings.AddExtraSettings(jss => jss.ContractResolver = new InterceptedContractResolver(jss.ContractResolver));

return Verify(enLocale, settings);
return Verify(locale, settings)
.UseDirectory("../../Bogus/data/")
.UseFileName($"{localeCode}.locale.schema");
}

public static IEnumerable<object[]> GetLocaleCodes()
{
var localeCodes = Directory.GetFiles(DataFolder, "*.locale.json")
.Select(file => Path.GetFileNameWithoutExtension(file).GetBefore("."));
foreach(var localeCode in localeCodes )
{
yield return new[] { localeCode };
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions Source/Bogus/data/af_ZA.locale.schema.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
address: {
default_country: [Array String; 1],
postcode: [Array String; 2]
},
cell_phone: {
formats: [Array String; 6]
},
company: {
suffix: [Array String; 3]
},
internet: {
domain_suffix: [Array String; 5]
},
phone_number: {
formats: [Array String; 9]
},
title: Afrikaans
}
35 changes: 35 additions & 0 deletions Source/Bogus/data/ar.locale.schema.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
address: {
building_number: [Array String; 4],
city: [Array String; 1],
city_name: [Array String; 604],
city_prefix: [Array String; 1],
city_suffix: [Array String; 1],
default_country: [Array String; 1],
direction: [Array String; 8],
postcode: [Array String; 1],
secondary_address: [Array String; 6],
state: [Array String; 22],
street_address: [Array String; 2],
street_name: [Array String; 1],
street_prefix: [Array String; 6],
street_suffix: [Array String; 26]
},
lorem: {
supplemental: [Array String; 121],
words: [Array String; 117]
},
name: {
female_first_name: [Array String; 17],
first_name: [Array String; 34],
gender: [Array String; 2],
last_name: [Array String; 25],
male_first_name: [Array String; 17],
name: [Array String; 10],
prefix: [Array String; 2],
title: {
job: [Array String; 7]
}
},
title: Arabic
}
59 changes: 59 additions & 0 deletions Source/Bogus/data/az.locale.schema.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
address: {
building_number: [Array String; 1],
city: [Array String; 1],
city_name: [Array String; 78],
country: [Array String; 239],
default_country: [Array String; 1],
postcode: [Array String; 1],
secondary_address: [Array String; 1],
street_address: [Array String; 1],
street_name: [Array String; 2],
street_suffix: [Array String; 6],
street_title: [Array String; 235]
},
commerce: {
color: [Array String; 18],
department: [Array String; 18],
product_name: {
adjective: [Array String; 10],
material: [Array String; 7],
product: [Array String; 8]
}
},
company: {
name: [Array String; 8],
prefix: [Array String; 3],
suffix: [Array String; 2]
},
date: {
month: {
abbr: [Array String; 12],
abbr_context: [Array String; 12],
wide: [Array String; 12],
wide_context: [Array String; 12]
},
weekday: {
abbr: [Array String; 7],
abbr_context: [Array String; 7],
wide: [Array String; 7],
wide_context: [Array String; 7]
}
},
internet: {
domain_suffix: [Array String; 6],
free_email: [Array String; 5]
},
name: {
female_first_name: [Array String; 73],
female_last_name: [Array String; 10],
male_first_name: [Array String; 35],
male_last_name: [Array String; 10],
name: [Array String; 6]
},
phone_number: {
formats: [Array String; 1]
},
separator: və ,
title: Azerbaijani
}
63 changes: 63 additions & 0 deletions Source/Bogus/data/cz.locale.schema.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
address: {
building_number: [Array String; 3],
city: [Array String; 1],
city_name: [Array String; 602],
country: [Array String; 195],
default_country: [Array String; 1],
postcode: [Array String; 3],
secondary_address: [Array String; 2],
street: [Array String; 8311],
street_address: [Array String; 1],
street_name: [Array String; 1],
time_zone: [Array String; 143]
},
company: {
adjective: [Array String; 100],
bs_noun: [Array String; 109],
bs_verb: [Array String; 60],
descriptor: [Array String; 101],
name: [Array String; 3],
noun: [Array String; 104],
suffix: [Array String; 3]
},
date: {
month: {
abbr: [Array String; 12],
abbr_context: [Array String; 12],
wide: [Array String; 12],
wide_context: [Array String; 12]
},
weekday: {
abbr: [Array String; 7],
abbr_context: [Array String; 7],
wide: [Array String; 7],
wide_context: [Array String; 7]
}
},
internet: {
domain_suffix: [Array String; 5],
free_email: [Array String; 5]
},
lorem: {
words: [Array String; 249]
},
name: {
female_first_name: [Array String; 786],
female_last_name: [Array String; 999],
male_first_name: [Array String; 796],
male_last_name: [Array String; 999],
name: [Array String; 10],
prefix: [Array String; 4],
suffix: [Array String; 1],
title: {
descriptor: [Array String; 22],
job: [Array String; 25],
level: [Array String; 37]
}
},
phone_number: {
formats: [Array String; 6]
},
title: Czech
}
59 changes: 59 additions & 0 deletions Source/Bogus/data/de.locale.schema.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
address: {
building_number: [Array String; 6],
city: [Array String; 4],
city_prefix: [Array String; 7],
city_suffix: [Array String; 5],
country: [Array String; 237],
default_country: [Array String; 1],
postcode: [Array String; 2],
secondary_address: [Array String; 3],
state: [Array String; 16],
state_abbr: [Array String; 16],
street_address: [Array String; 1],
street_name: [Array String; 1],
street_root: [Array String; 1031]
},
cell_phone: {
formats: [Array String; 2]
},
company: {
legal_form: [Array String; 7],
name: [Array String; 3],
suffix: [Array String; 7]
},
date: {
month: {
abbr: [Array String; 12],
abbr_context: [Array String; 12],
wide: [Array String; 12],
wide_context: [Array String; 12]
},
weekday: {
abbr: [Array String; 7],
abbr_context: [Array String; 7],
wide: [Array String; 7],
wide_context: [Array String; 7]
}
},
internet: {
domain_suffix: [Array String; 7],
free_email: [Array String; 3]
},
lorem: {
words: [Array String; 249]
},
name: {
female_first_name: [Array String; 583],
first_name: [Array String; 1155],
last_name: [Array String; 1688],
male_first_name: [Array String; 572],
name: [Array String; 6],
nobility_title_prefix: [Array String; 4],
prefix: [Array String; 4]
},
phone_number: {
formats: [Array String; 4]
},
title: German
}
39 changes: 39 additions & 0 deletions Source/Bogus/data/de_AT.locale.schema.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
address: {
building_number: [Array String; 6],
city: [Array String; 1],
city_name: [Array String; 119],
country: [Array String; 237],
default_country: [Array String; 1],
postcode: [Array String; 1],
secondary_address: [Array String; 3],
state: [Array String; 9],
state_abbr: [Array String; 9],
street_address: [Array String; 1],
street_name: [Array String; 1],
street_root: [Array String; 198]
},
cell_phone: {
formats: [Array String; 4]
},
company: {
legal_form: [Array String; 7],
name: [Array String; 3],
suffix: [Array String; 7]
},
internet: {
domain_suffix: [Array String; 8],
free_email: [Array String; 3]
},
name: {
first_name: [Array String; 1155],
last_name: [Array String; 1688],
name: [Array String; 6],
nobility_title_prefix: [Array String; 4],
prefix: [Array String; 2]
},
phone_number: {
formats: [Array String; 8]
},
title: German (Austria)
}
24 changes: 24 additions & 0 deletions Source/Bogus/data/de_CH.locale.schema.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
address: {
country_code: [Array String; 10],
default_country: [Array String; 1],
postcode: [Array String; 9]
},
company: {
name: [Array String; 3],
suffix: [Array String; 8]
},
internet: {
domain_suffix: [Array String; 9]
},
name: {
first_name: [Array String; 336],
last_name: [Array String; 209],
name: [Array String; 6],
prefix: [Array String; 3]
},
phone_number: {
formats: [Array String; 9]
},
title: German (Switzerland)
}
Loading

0 comments on commit c20f163

Please sign in to comment.