use position_preserving_moodle_question_xml_edit::*;
#[test]
fn read_as_stack_question() {
let mut parser = QParser::load_xml_file("tests/tests/minimal-stack.xml".to_string()).expect("Valid input should not fail");
let question = parser.get_as_stack_question(0);
assert_eq!(question.name.content, "minimal".to_string());
assert_eq!(question.questionvariables.content, "a: 1+rand(5);\r\nb: 2+rand(5);\r\nta: a+b;".to_string());
assert_eq!(question.questiontext.get_content().unwrap().unwrap_cdata(), "<p>\\({@a@}+{@b@}=\\) [[input:ans1]] </p>\r\n<p>[[validation:ans1]]</p>".to_string());
assert_eq!(question.inputs.get(&"ans1".to_string()).unwrap().r#type.content, "algebraic".to_string());
assert_eq!(question.inputs.get(&"ans1".to_string()).unwrap().tans.content, "ta".to_string());
assert_eq!(question.prts.get(&"prt1".to_string()).unwrap().nodes[0].answertest.content, "AlgEquiv".to_string());
assert_eq!(question.tests[0].description.content, "Test case assuming the teacher's input gets full marks.".to_string());
assert_eq!(question.tests[0].inputs.get(&"ans1".to_string()).unwrap().value.content, "ta".to_string());
assert_eq!(question.tests[0].expected.get(&"prt1".to_string()).unwrap().expectedscore.content, "1.0000000".to_string());
}
#[test]
fn access_by_type() {
let mut parser = QParser::load_xml_file("tests/tests/minimal-stack.xml".to_string()).expect("Valid input should not fail");
let question = parser.get_as_stack_question(0);
let mut all_castext_catenated: String = String::new();
for (_, c) in question.get_castext_fields() {
all_castext_catenated.push_str(&c.get_content().expect("These will currently always have content.").unwrap_cdata());
all_castext_catenated.push('|');
}
assert_eq!(all_castext_catenated, "<p>\\({@a@}+{@b@}=\\) [[input:ans1]] </p>\r\n<p>[[validation:ans1]]</p>||[[feedback:prt1]]|\\({@a@}+{@b@}={@ta@}\\)||Correct answer, well done.|Your answer is partially correct.|Incorrect answer.|||");
let mut all_casstrings_catenated: String = String::new();
for (_, c) in question.get_castring_fields() {
all_casstrings_catenated.push_str(&c.unwrap_cdata());
all_casstrings_catenated.push('|');
}
assert_eq!(all_casstrings_catenated, "ta|ans1|ta||1||0||ta|");
let mut all_keyval_catenated: String = String::new();
for (_, c) in question.get_keyval_fields() {
all_keyval_catenated.push_str(&c.unwrap_cdata());
all_keyval_catenated.push('|');
}
assert_eq!(all_keyval_catenated, "a: 1+rand(5);\r\nb: 2+rand(5);\r\nta: a+b;||");
}