ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v), q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)). ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no longer uses, nor anything it calls, and the argument that fills it - including an argument for a parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
3.2 KiB
Text
75 lines
3.2 KiB
Text
# settings_test.ludic - a registry of settings as data: defaults, typed reads, a fact per change,
|
|
# ranges, the rescue set, and the file by key
|
|
import "ludic.settings"
|
|
import "ludic.base"
|
|
program SettingsTest {
|
|
numbers float
|
|
registry Toy of SettingDef as TOY from "packages/ludic.settings/tests/toy.lres"
|
|
|
|
function declare(settings_st: mut SettingsState) -> void {
|
|
settings_clear(settings_st)
|
|
for i in 0 .. TOY_COUNT { settings_add(settings_st, Toy[i]) }
|
|
}
|
|
|
|
function facts(settings_st: mut SettingsState) -> []SettingChanged { return q_drain(settings_changes(settings_st)) }
|
|
|
|
test "a registry declares the store, each at its default" (settings_st: mut SettingsState) {
|
|
declare(settings_st)
|
|
expect_eq(settings_count(settings_st), 5)
|
|
expect(settings_get_bool(settings_st, TOY_BLOOM))
|
|
expect_eq(settings_get_int(settings_st, TOY_SHADOW_Q), 2)
|
|
expect(settings_get_float(settings_st, TOY_RSCALE) > 0.77)
|
|
expect(settings_get_text(settings_st, TOY_LANG) == "en")
|
|
expect_eq(settings_id_of(settings_st, "rscale"), TOY_RSCALE)
|
|
expect_eq(settings_id_of(settings_st, "nothing"), -1)
|
|
}
|
|
|
|
test "a change is a fact, and setting what is there is none" (settings_st: mut SettingsState) {
|
|
declare(settings_st)
|
|
settings_set_int(settings_st, TOY_SHADOW_Q, 3)
|
|
settings_set_int(settings_st, TOY_SHADOW_Q, 3)
|
|
settings_set_text(settings_st, TOY_LANG, "tr")
|
|
let fs = facts(settings_st)
|
|
expect_eq(len(fs), 2)
|
|
expect(fs[0].key == "shadow_q")
|
|
expect_eq(fs[1].id, TOY_LANG)
|
|
}
|
|
|
|
test "a value out of range is the default" (settings_st: mut SettingsState) {
|
|
declare(settings_st)
|
|
settings_set_int(settings_st, TOY_SHADOW_Q, 9)
|
|
expect_eq(settings_get_int(settings_st, TOY_SHADOW_Q), 2)
|
|
settings_set_float(settings_st, TOY_RSCALE, 0.2)
|
|
expect(settings_get_float(settings_st, TOY_RSCALE) > 0.77)
|
|
}
|
|
|
|
test "a rescue puts back only what it lists" (settings_st: mut SettingsState) {
|
|
declare(settings_st)
|
|
settings_set_int(settings_st, TOY_SHADOW_Q, 0)
|
|
settings_set_bool(settings_st, TOY_BLOOM, false)
|
|
expect(not settings_is_safe(settings_st, TOY_SHADOW_Q))
|
|
settings_rescue(settings_st)
|
|
expect_eq(settings_get_int(settings_st, TOY_SHADOW_Q), 2)
|
|
expect(not settings_get_bool(settings_st, TOY_BLOOM))
|
|
}
|
|
|
|
test "the file is by key, and what it lacks or cannot hold keeps the store's" (settings_st: mut SettingsState) {
|
|
declare(settings_st)
|
|
settings_set_float(settings_st, TOY_RSCALE, 0.9)
|
|
settings_set_text(settings_st, TOY_LANG, "tr")
|
|
settings_set_bool(settings_st, TOY_HELD, true)
|
|
let text = Json.encode(settings_to_json(settings_st))
|
|
declare(settings_st)
|
|
settings_set_bool(settings_st, TOY_BLOOM, false)
|
|
let v = Json.parse(text)
|
|
Value.put(v, "shadow_q", Value.int(7))
|
|
Value.put(v, "stranger", Value.int(1))
|
|
settings_from_json(settings_st, v)
|
|
expect(settings_get_float(settings_st, TOY_RSCALE) > 0.89)
|
|
expect(settings_get_text(settings_st, TOY_LANG) == "tr")
|
|
expect_eq(settings_get_int(settings_st, TOY_SHADOW_Q), 2)
|
|
expect(settings_get_bool(settings_st, TOY_BLOOM))
|
|
expect(not settings_get_bool(settings_st, TOY_HELD))
|
|
expect(Value.has(settings_to_json(settings_st), "held") == 0)
|
|
}
|
|
}
|