use super::*;
#[test]
fn test_place_tag_beyond_arity_errors() {
let predicates = vec![Predicate::Root("dog".into())];
let arguments = vec![
Argument::Pronoun(Pronoun::You), Argument::Tagged((4, 0)), ];
let proposition = Proposition {
relation: 0,
terms: vec![1],
x1_present: true,
negated: false,
tense: None,
deontic: None,
};
let (_form, compiler) = compile_one(predicates, arguments, proposition);
assert!(
!compiler.errors.is_empty(),
"over-arity FA tag must produce a semantic error"
);
assert!(
compiler.errors.iter().any(|e| e.contains("x5")),
"error should name the offending place, got: {:?}",
compiler.errors
);
}
#[test]
fn test_untagged_overflow_known_arity_errors() {
let predicates = vec![Predicate::Root("dog".into())];
let arguments = vec![
Argument::Pronoun(Pronoun::Me), Argument::Pronoun(Pronoun::You), Argument::Pronoun(Pronoun::This), ];
let proposition = Proposition {
relation: 0,
terms: vec![0, 1, 2],
x1_present: true,
negated: false,
tense: None,
deontic: None,
};
let (_form, compiler) = compile_one(predicates, arguments, proposition);
assert!(
!compiler.errors.is_empty(),
"untagged argument over a known arity must error"
);
assert!(
compiler.errors.iter().any(|e| e.contains("overflow")),
"error should mention the overflow, got: {:?}",
compiler.errors
);
}
#[test]
fn test_untagged_overflow_unknown_arity_no_error() {
let predicates = vec![Predicate::Root("zzzzz".into())];
let arguments = vec![
Argument::Pronoun(Pronoun::Me), Argument::Pronoun(Pronoun::You), Argument::Pronoun(Pronoun::This), ];
let proposition = Proposition {
relation: 0,
terms: vec![0, 1, 2],
x1_present: true,
negated: false,
tense: None,
deontic: None,
};
let (_form, compiler) = compile_one(predicates, arguments, proposition);
assert!(
compiler.errors.is_empty(),
"unknown-arity overflow must not error, got: {:?}",
compiler.errors
);
}
#[test]
fn test_tag_collision_errors() {
let predicates = vec![Predicate::Root("dog".into())];
let arguments = vec![
Argument::Pronoun(Pronoun::You), Argument::Pronoun(Pronoun::This), Argument::Tagged((1, 0)), Argument::Tagged((1, 1)), ];
let proposition = Proposition {
relation: 0,
terms: vec![2, 3],
x1_present: true,
negated: false,
tense: None,
deontic: None,
};
let (_form, compiler) = compile_one(predicates, arguments, proposition);
assert!(
!compiler.errors.is_empty(),
"a tag re-targeting a filled place must error"
);
assert!(
compiler.errors.iter().any(|e| e.contains("already filled")),
"error should mention the collision, got: {:?}",
compiler.errors
);
}
#[test]
fn test_compound_in_restrictive_not_falsely_rejected() {
let predicates = vec![
Predicate::Root("dog".into()), Predicate::Root("fast".into()), Predicate::Root("runs".into()), Predicate::Pair((1, 2)), Predicate::Root("goes".into()), ];
let arguments = vec![
Argument::Description((Determiner::Indefinite, 0)), Argument::Restricted((
0,
RelClause {
kind: RelClauseKind::Restrictive,
body_sentence: 1,
},
)), ];
let sentences = vec![
Sentence::Simple(Proposition {
relation: 4,
terms: vec![1],
x1_present: true,
negated: false,
tense: None,
deontic: None,
}),
Sentence::Simple(Proposition {
relation: 3,
terms: vec![],
x1_present: false,
negated: false,
tense: None,
deontic: None,
}),
];
let (form, compiler) = compile_sentence_full(predicates, arguments, sentences);
assert!(
compiler.errors.is_empty(),
"valid pair-in-poi clause must not be rejected, got: {:?}",
compiler.errors
);
let bajra_x1 = get_pred_args(&form, "runs_x1", &compiler).unwrap();
let sutra_x1 = get_pred_args(&form, "fast_x1", &compiler).unwrap();
let gerku_x1 = get_pred_args(&form, "dog_x1", &compiler).unwrap();
assert_eq!(
bajra_x1[1], gerku_x1[1],
"pair head x1 must bind the dog variable"
);
assert_eq!(
sutra_x1[1], gerku_x1[1],
"pair modifier x1 must bind the dog variable"
);
assert_eq!(
bajra_x1[0], sutra_x1[0],
"pair must keep the shared event variable"
);
}
#[test]
fn test_rel_clause_on_name_firewall_still_applies() {
let predicates = vec![
Predicate::Root("cat".into()), Predicate::Root("bite".into()), ];
let arguments = vec![
Argument::Name("adam".into()), Argument::Description((Determiner::Indefinite, 0)), Argument::Restricted((
0,
RelClause {
kind: RelClauseKind::Restrictive,
body_sentence: 1,
},
)), ];
let sentences = vec![
Sentence::Simple(Proposition {
relation: 1,
terms: vec![2],
x1_present: true,
negated: false,
tense: None,
deontic: None,
}),
Sentence::Simple(Proposition {
relation: 1,
terms: vec![1], x1_present: true,
negated: false,
tense: None,
deontic: None,
}),
];
let (_form, compiler) = compile_sentence_full(predicates, arguments, sentences);
assert!(
!compiler.errors.is_empty(),
"ambiguous implicit-ke'a clause on a name must be rejected"
);
assert!(
compiler.errors.iter().any(|e| e.contains("explicit `it`")),
"error should direct the user to an explicit `it`, got: {:?}",
compiler.errors
);
}