Reproducible relational test data construction for MoonBit.
Dependencies
| 组件 | 版本 |
|---|---|
| moon | 0.1.20260920 (914d7da 2026-09-20) |
| moonc | v0.10.14+7d59c7ec9 (2026-09-18) |
| moonrun | 0.1.20260920 (914d7da 2026-09-20) |
| CLI 依赖 | moonbitlang/async 0.22.1、moonbitlang/x 0.5.5 |
| 本地验证 | Windows / MSVC;Node.js v26.5.1 |
moon add tlhuecdkoyg/MoonFixture@0.1.0import {
"tlhuecdkoyg/MoonFixture" @fixture,
}test "relational fixture" {
let model : @fixture.Model = {
name: "shop",
entities: [
{
name: "users", count: 5,
fields: [@fixture.Field::new("id", Sequence(1, 1), primary=true)],
},
{
name: "orders", count: 20,
fields: [
@fixture.Field::new("id", Sequence(100, 1), primary=true),
@fixture.Field::new("user_id", Reference("users", "id")),
@fixture.Field::new("quantity", IntegerRange(1, 5)),
@fixture.Field::new("unit_price", Constant(Integer(200))),
@fixture.Field::new("total", Multiply("quantity", "unit_price")),
],
},
],
}
let context = @fixture.Context::new(2026U)
let plan = @fixture.compile(model, context~).unwrap()
let data = plan.generate().unwrap()
assert_true(@fixture.validate_dataset(model, data).is_valid())
assert_eq(@fixture.replay(plan.replay_json()).unwrap(), data)
}moon run cmd/main --target native -- --help
moon run cmd/main --target native -- generate examples/shop.json --seed 2026 --output shop-data.json
moon run cmd/main --target native -- validate shop-data.json --model examples/shop.json
moon run cmd/main --target native -- manifest examples/shop.json --seed 2026 --output replay.json
moon run cmd/main --target native -- replay replay.json --output replayed-data.json
moon run cmd/main --target native -- generate examples/shop.json --format csv --table products
moon run cmd/main --target native -- generate examples/shop.json --format sqlite --output sqlite-batches.jsonmoon build --target native --deny-warn
python scripts/integration.pypython scripts/verify.py
python scripts/count_lines.py --minimum 4000pub(all) struct BatchProgress {
rows_accepted : Int
batches_accepted : Int
completed : Bool
}pub(all) enum Expectation {
RowCount(String, Int, Int)
NonNull(String, String)
IntegerBounds(String, String, Int, Int)
TextLength(String, String, Int, Int)
LessEqual(String, String, String)
SumEquals(String, String, Int64)
RelatedCount(String, String, String, String, Int, Int)
}pub(all) struct FieldPlan {
name : String
evaluation_index : Int
unique : Bool
primary : Bool
finite_capacity : String?
local_dependencies : Array[String]
parent_entity : String?
}pub(all) struct FieldProfile {
name : String
present : Int
missing : Int
nulls : Int
booleans : Int
true_values : Int
integers : Int
texts : Int
distinct : Int
min_integer : Int?
max_integer : Int?
sum_integer : Int64
min_text_length : Int?
max_text_length : Int?
}pub(all) enum Generator {
Constant(Value)
Sequence(Int, Int)
IntegerRange(Int, Int)
BooleanChance(Int)
Choice(Array[Value])
WeightedChoice(Array[(Value, Int)])
Pattern(String, Int)
DateOffset(Int, Int)
Reference(String, String)
Copy(String)
Add(String, String)
Multiply(String, String)
Concat(Array[String], String)
Lookup(String, String, String, String)
} derive(Eq, Debug)pub(all) struct GroupSummary {
key : Value
count : Int
integer_count : Int
null_count : Int
sum : Int64
min : Int?
max : Int?
}pub(all) struct MutationResult {
dataset : Dataset
operations : Array[Mutation]
report : ValidationReport
}pub(all) struct PlanReport {
model : String
fingerprint : String
rows : Int64
cells : Int64
entities : Array[EntityPlan]
notes : Array[String]
}fn Table::group_sum(self : Table, key_field : String, amount_field : String) -> Result[Array[GroupSummary], Issue]fn Table::visit_csv(self : Table, columns : Array[String], size : Int, consume : (String) -> Bool, offset? : Int) -> Result[BatchProgress, Issue]fn Table::visit_ndjson(self : Table, size : Int, consume : (String) -> Bool, offset? : Int) -> Result[BatchProgress, Issue]fn check_expectations(data : Dataset, expectations : Array[Expectation], max_issues? : Int) -> ValidationReportfn compare_datasets(model : Model, before : Dataset, after : Dataset, max_differences? : Int) -> Result[Comparison, Issue]fn sqlite_bundle(model : Model, data : Dataset, batch_size? : Int) -> Result[SqliteBundle, Array[Issue]]fn validate_dataset(model : Model, data : Dataset, max_issues? : Int, check_counts? : Bool) -> ValidationReportInstall
Download zipReproducible relational test data construction for MoonBit.
Dependencies