test_that("ILandConfig persists values", {
cfg_path <- tempfile(fileext = ".json")
cfg <- ILandConfig$new(config_path = cfg_path)
expect_equal(cfg$get_github_repo(), "edfm-tum/iland-model")
cfg$set_github_repo("paudelsushil/ilandR")
cfg$set_repo_root(tempdir())
cfg$save()
cfg2 <- ILandConfig$new(config_path = cfg_path)
expect_equal(cfg2$get_github_repo(), "paudelsushil/ilandR")
expect_true(nzchar(cfg2$get_repo_root()))
})
test_that("ILandProject get/set/save roundtrip", {
xml_path <- tempfile(fileext = ".xml")
writeLines("old", xml_path)
prj <- iland_project_load(xml_path)
expect_true(prj$is_loaded())
expect_equal(prj$get("model.path.home"), "old")
prj$set("model.path.home", "new_home")
expect_equal(prj$get("model.path.home"), "new_home")
out_path <- tempfile(fileext = ".xml")
prj$save(out_path)
expect_true(file.exists(out_path))
prj2 <- iland_project_load(out_path)
expect_equal(prj2$get("model.path.home"), "new_home")
})
test_that("ILandProject dotted-key semantics are strict and validated", {
xml_path <- tempfile(fileext = ".xml")
writeLines("deep", xml_path)
prj <- iland_project_load(xml_path)
expect_false(prj$exists("a.b"))
expect_equal(prj$get("a.b", default = "missing"), "missing")
prj$set("a.b", "direct")
expect_true(prj$exists("a.b"))
expect_equal(prj$get("a.b"), "direct")
expect_error(prj$get(""), "at least one non-empty path segment")
})