A guide page for the four registries: where entries live, how targets point at them, the other new fields, the brace-reference table, what students never see, the lecture and glossary pages, every new error and lint rule, and the migration from terms.yaml and values.yaml. The setup guide points at it. The README covers glossary.yaml, the nine schemas, the 2.1 checks, the glossary lint family and the note severity, the new lecture commands and report sections, migrate glossary, and schema version 2.1. Module docs and the changelog follow. docs/design/2.1/CODES.md maps the specification's E, W, and I codes to coursebank's messages and lint codes, each with its test, and REPORT.md records what changed, the two remaining schema differences, every choice made where the specification left room, and suggested changes to it. A new test covers the validation messages the specification does not number. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
310 lines
9.5 KiB
Rust
310 lines
9.5 KiB
Rust
// SPDX-License-Identifier: Prosperity-3.0.0
|
|
// Copyright Scienting
|
|
// Source: https://git.scient.ing/education/coursebank
|
|
|
|
//! The errors 2.1 adds, one test each.
|
|
//!
|
|
//! Each test breaks the example course in `docs/design/2.1/examples/v21/` the way
|
|
//! the prototype's self-test does (`prototype/check21.py --selftest`) and checks
|
|
//! that validation reports it. `docs/design/2.1/CODES.md` maps the
|
|
//! specification's codes to the messages asserted here.
|
|
|
|
mod common;
|
|
|
|
use common::{edit, v21_course};
|
|
use coursebank::catalog::Catalog;
|
|
use coursebank::course::CourseFile;
|
|
use coursebank::course::glossary::Symbol;
|
|
|
|
/// The example course, loaded.
|
|
fn course(tag: &str) -> CourseFile {
|
|
CourseFile::load_dir(&v21_course(tag)).expect("the example loads")
|
|
}
|
|
|
|
/// Asserts exactly one issue contains `needle`.
|
|
fn reports(issues: &[String], needle: &str) {
|
|
let hits = issues.iter().filter(|i| i.contains(needle)).count();
|
|
assert_eq!(
|
|
hits, 1,
|
|
"expected one issue containing {needle:?}, got {issues:#?}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn the_example_validates_with_no_errors() {
|
|
let catalog = Catalog::load(&v21_course("valid")).unwrap();
|
|
let issues = catalog.validate().unwrap();
|
|
assert!(issues.is_empty(), "{issues:#?}");
|
|
}
|
|
|
|
#[test]
|
|
fn e2101_an_id_in_two_registries() {
|
|
let mut c = course("e2101");
|
|
let target = c.learning_targets["t-align-fill-matrix"].clone();
|
|
c.learning_targets.insert("term-gap".into(), target);
|
|
reports(
|
|
&c.validate(),
|
|
"`term-gap` is declared as both a learning target and a term",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2101_a_registry_id_without_its_prefix() {
|
|
let mut c = course("e2101-prefix");
|
|
let term = c.terms.remove("term-gap").unwrap();
|
|
c.terms.insert("gap".into(), term);
|
|
let issues = c.validate();
|
|
reports(&issues, "term `gap`: a term id is `term-` followed by");
|
|
}
|
|
|
|
#[test]
|
|
fn e2102_a_target_lists_an_undeclared_entry() {
|
|
let mut c = course("e2102");
|
|
c.learning_targets
|
|
.get_mut("t-align-fill-matrix")
|
|
.unwrap()
|
|
.terms
|
|
.push("term-nope".into());
|
|
reports(
|
|
&c.validate(),
|
|
"target `t-align-fill-matrix`: `terms` names `term-nope`, which is not a declared term",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2102_an_id_listed_under_the_wrong_registry() {
|
|
let mut c = course("e2102-wrong");
|
|
c.learning_targets
|
|
.get_mut("t-align-fill-matrix")
|
|
.unwrap()
|
|
.equations
|
|
.push("term-gap".into());
|
|
reports(
|
|
&c.validate(),
|
|
"`equations` names `term-gap`, which is not a declared equation",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2103_a_symbol_with_neither_term_nor_meaning() {
|
|
let mut c = course("e2103");
|
|
c.equations
|
|
.get_mut("eq-global-recurrence")
|
|
.unwrap()
|
|
.symbols
|
|
.push(Symbol {
|
|
symbol: "q".into(),
|
|
term: None,
|
|
meaning: None,
|
|
units: None,
|
|
});
|
|
reports(
|
|
&c.validate(),
|
|
"equation `eq-global-recurrence`: symbol `q` needs a `term` or a `meaning`",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2103_a_symbol_naming_an_undeclared_term() {
|
|
let mut c = course("e2103-term");
|
|
c.equations.get_mut("eq-global-recurrence").unwrap().symbols[2].term = Some("term-nope".into());
|
|
reports(
|
|
&c.validate(),
|
|
"symbol `d` names the term `term-nope`, which is not declared",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2104_a_value_with_neither_value_nor_range() {
|
|
let mut c = course("e2104");
|
|
c.values.get_mut("val-alignment-count-100").unwrap().value = None;
|
|
reports(
|
|
&c.validate(),
|
|
"value `val-alignment-count-100`: give a `value` or a `range`",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2104_a_range_that_runs_high_to_low_and_an_undeclared_term() {
|
|
let mut c = course("e2104-range");
|
|
let v = c.values.get_mut("val-per-decade").unwrap();
|
|
v.range = Some([7.0, 5.0]);
|
|
v.term = Some("term-nope".into());
|
|
let issues = c.validate();
|
|
reports(
|
|
&issues,
|
|
"value `val-per-decade`: range runs from 7 down to 5",
|
|
);
|
|
reports(
|
|
&issues,
|
|
"value `val-per-decade`: term `term-nope` is not declared",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2105_a_citation_key_not_in_references() {
|
|
let mut c = course("e2105");
|
|
c.values
|
|
.get_mut("val-alignment-count-100")
|
|
.unwrap()
|
|
.source
|
|
.as_mut()
|
|
.unwrap()
|
|
.reference = "nobody2020".into();
|
|
c.terms.get_mut("term-alignment-matrix").unwrap().textbook[0].reference =
|
|
Some("nobody2021".into());
|
|
c.misconceptions
|
|
.get_mut("mis-only-matches-count")
|
|
.unwrap()
|
|
.evidence[0]
|
|
.reference = Some("nobody2022".into());
|
|
let issues = c.validate();
|
|
reports(
|
|
&issues,
|
|
"source cites `nobody2020`, which is not in references",
|
|
);
|
|
reports(&issues, "textbook cites `nobody2021`");
|
|
reports(&issues, "evidence cites `nobody2022`");
|
|
}
|
|
|
|
#[test]
|
|
fn e2106_a_brace_reference_that_does_not_resolve() {
|
|
let mut c = course("e2106");
|
|
c.terms.get_mut("term-gap").unwrap().definition = "See {term-missing}.".into();
|
|
reports(
|
|
&c.validate(),
|
|
"term `term-gap`: definition refers to `{term-missing}`, which is not a declared term",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2106_an_old_reading_keeps_its_2_0_behaviour_for_targets() {
|
|
// A 2.0 reading with a mistyped `{t-...}` validated and rendered the braces
|
|
// literally. It still validates (the linter reports it); a new kind of
|
|
// reference in the same field is checked.
|
|
let mut c = course("e2106-legacy");
|
|
let reading = &mut c.lectures.get_mut("l09").unwrap().readings[0];
|
|
reading.focus = Some("See {t-typo} and {val-typo}.".into());
|
|
let issues = c.validate();
|
|
assert!(!issues.iter().any(|i| i.contains("t-typo")), "{issues:#?}");
|
|
reports(&issues, "reading 1 focus refers to `{val-typo}`");
|
|
}
|
|
|
|
#[test]
|
|
fn e2106_a_new_field_checks_every_kind() {
|
|
let mut c = course("e2106-new");
|
|
c.learning_objectives
|
|
.get_mut("lo-alignment-scoring")
|
|
.unwrap()
|
|
.description = Some("Builds on {t-typo}.".into());
|
|
reports(
|
|
&c.validate(),
|
|
"objective `lo-alignment-scoring`: description refers to `{t-typo}`",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2107_a_pattern_that_does_not_compile() {
|
|
let mut c = course("e2107");
|
|
c.values
|
|
.get_mut("val-per-decade")
|
|
.unwrap()
|
|
.conflicts
|
|
.push("5.7(".into());
|
|
c.policy.target_text_forbid.push("[unclosed".into());
|
|
let issues = c.validate();
|
|
reports(
|
|
&issues,
|
|
"value `val-per-decade`: conflicts pattern `5.7(` does not compile",
|
|
);
|
|
reports(
|
|
&issues,
|
|
"policy.target_text_forbid: pattern `[unclosed` does not compile",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn e2108_an_option_names_an_undeclared_misconception() {
|
|
let root = v21_course("e2108");
|
|
edit(
|
|
&root,
|
|
"banks/alignment.yaml",
|
|
"misconception_id: mis-only-matches-count",
|
|
"misconception_id: mis-nope",
|
|
);
|
|
let issues = Catalog::load(&root).unwrap().validate().unwrap();
|
|
reports(
|
|
&issues,
|
|
"option o-matches-only: misconception_id `mis-nope` is not a declared misconception",
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn messages_name_the_file_that_defined_the_entry() {
|
|
let mut c = course("attribution");
|
|
c.terms.get_mut("term-gap").unwrap().definition = "See {term-missing}.".into();
|
|
let issues = c.validate();
|
|
assert!(
|
|
issues
|
|
.iter()
|
|
.any(|i| i.starts_with("objectives/lo-alignment-scoring.yaml: term `term-gap`")),
|
|
"{issues:#?}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn policy_levels_and_blueprints_are_keyed_by_level() {
|
|
let mut c = course("policy");
|
|
let level = c.policy.levels["1"].clone();
|
|
c.policy.levels.insert("6".into(), level);
|
|
c.policy
|
|
.blueprints
|
|
.get_mut("module")
|
|
.unwrap()
|
|
.level_counts
|
|
.insert("7".into(), 1);
|
|
let issues = c.validate();
|
|
reports(&issues, "policy.levels: `6` is not a level");
|
|
reports(&issues, "policy.blueprints: `module` counts items at `7`");
|
|
}
|
|
|
|
/// The checks the specification does not number: required text that is
|
|
/// present but empty, and numbers outside the range the schema gives.
|
|
#[test]
|
|
fn empty_required_text_and_out_of_range_numbers_are_errors() {
|
|
let mut c = course("required");
|
|
c.terms.get_mut("term-gap").unwrap().definition = " ".into();
|
|
c.equations.get_mut("eq-global-recurrence").unwrap().says = String::new();
|
|
c.values.get_mut("val-per-decade").unwrap().say = String::new();
|
|
c.misconceptions
|
|
.get_mut("mis-only-matches-count")
|
|
.unwrap()
|
|
.correction = String::new();
|
|
let lecture = c.lectures.get_mut("l09").unwrap();
|
|
lecture.materials[0].url = String::new();
|
|
lecture.readings[0].minutes = Some(0);
|
|
c.policy.levels.get_mut("3").unwrap().name = String::new();
|
|
c.policy.blueprints.get_mut("module").unwrap().minutes = Some(0.0);
|
|
c.policy.exam_conditions.as_mut().unwrap().seconds_per_item = Some(0.0);
|
|
|
|
let issues = c.validate();
|
|
reports(&issues, "term `term-gap`: empty definition");
|
|
reports(&issues, "equation `eq-global-recurrence`: empty says");
|
|
reports(&issues, "value `val-per-decade`: empty say");
|
|
reports(
|
|
&issues,
|
|
"misconception `mis-only-matches-count`: empty correction",
|
|
);
|
|
reports(&issues, "lecture `l09`: material 1 has no url");
|
|
reports(
|
|
&issues,
|
|
"lecture `l09` reading 1: minutes must be at least 1",
|
|
);
|
|
reports(&issues, "policy.levels: level 3 has an empty name");
|
|
reports(&issues, "policy.blueprints: `module` gives no time");
|
|
reports(
|
|
&issues,
|
|
"policy.exam_conditions: seconds_per_item must be above 0",
|
|
);
|
|
}
|