Seedable fake data generation for MoonBit, ported from Faker
import { "bobzhang/faker" }///|
test "seeded example" {
let faker = @faker.Faker(seed=42)
assert_eq(faker.person_full_name(), "Nikita Cormier")
assert_eq(faker.uuid(), "0d9b0fd3-2248-4649-9245-7c3890921ffc")
faker.seed(42)
assert_eq(faker.person_full_name(), "Nikita Cormier")
}///|
test "generating structured test data" {
let faker = @faker.Faker(seed=123)
let count = faker.int(min=3, max=8)
let identifiers = @faker.multiple(_ => faker.uuid(), count~)
assert_eq(identifiers.length(), count)
assert_true(faker.internet_email().contains("@"))
assert_true(@faker.luhn_valid(faker.finance_credit_card_number()))
assert_eq(faker.finance_iban(country_code="GB").length(), 22)
}// Also import "bobzhang/faker/locales/zh_cn" in moon.pkg.
///|
let faker = @faker.Faker(seed=42, locales=@zh_cn.locales())
///|
let name = faker.person_full_name()moon check --target all --warn-list +unnecessary_annotation
moon test --target all
moon fmt
moon infonode scripts/generate-locales.mjs
node scripts/generate-transliteration.mjs
node scripts/generate-slugify.mjs
node scripts/generate-case-data.mjs
node scripts/generate-finance-data.mjs
python3 scripts/generate-data-methods.py
python3 scripts/api-coverage.py
python3 scripts/generate-template-dispatch.py
node scripts/generate-parity.mjs
node scripts/generate-locale-parity.mjs
moon fmt
moon infopub suberror FakerError {
InvalidArgument(String)
MissingDefinition(String)
InvalidDefinition(String)
}pub struct Currency {
name : String
code : String
symbol : String
numeric_code : String
} derive(ToJson)pub struct Faker {
randomizer : &RandomSource
locales : Array[Locale]
template_depth : Int
ref_date : Int64
}fn Faker::float(self : Faker, min? : Double, max? : Double, multiple_of? : Double, fraction_digits? : Int, distributor? : (&RandomSource) -> Double) -> Double raisefn Faker::int(self : Faker, min? : Int, max? : Int, multiple_of? : Int, distributor? : (&RandomSource) -> Double) -> Int raisefn Faker::lorem_word(self : Faker, min_length? : Int, max_length? : Int, strategy? : LengthStrategy) -> String raisefn Faker::word_adjective(self : Faker, min_length? : Int, max_length? : Int, strategy? : LengthStrategy) -> String raisefn Faker::word_adverb(self : Faker, min_length? : Int, max_length? : Int, strategy? : LengthStrategy) -> String raisefn Faker::word_conjunction(self : Faker, min_length? : Int, max_length? : Int, strategy? : LengthStrategy) -> String raisefn Faker::word_interjection(self : Faker, min_length? : Int, max_length? : Int, strategy? : LengthStrategy) -> String raisefn Faker::word_noun(self : Faker, min_length? : Int, max_length? : Int, strategy? : LengthStrategy) -> String raisefn Faker::word_preposition(self : Faker, min_length? : Int, max_length? : Int, strategy? : LengthStrategy) -> String raisefn Faker::word_sample(self : Faker, min_length? : Int, max_length? : Int, strategy? : LengthStrategy) -> String raisefn Faker::word_verb(self : Faker, min_length? : Int, max_length? : Int, strategy? : LengthStrategy) -> String raisefn date_iso(timestamp_ms : Int64) -> String raisefn slugify(value : String) -> String