add more subtype test-cases & fix normalize in case of normalizing sub-ladders

This commit is contained in:
Michael Sippel 2023-10-02 19:16:20 +02:00
parent ccd60fc7bf
commit 3b944d15c8
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 32 additions and 4 deletions

View file

@ -31,7 +31,16 @@ impl TypeTerm {
match self {
TypeTerm::Ladder(args) => {
for x in args.into_iter() {
new_ladder.push(x.normalize());
match x.normalize() {
TypeTerm::Ladder(gs) => {
for g in gs {
new_ladder.push(g);
}
}
g => {
new_ladder.push(g);
}
}
}
}
@ -102,9 +111,7 @@ impl TypeTerm {
TypeTerm::Ladder( v ) => {
v
},
_ => {
unreachable!();
}
flat => vec![ flat ]
}
}
}

View file

@ -72,5 +72,26 @@ fn test_syntactic_subtype() {
),
Err(None)
);
assert_eq!(
dict.parse("<Duration Seconds>~").expect("parse error")
.is_syntactic_subtype_of(
&dict.parse("").expect("parse errror")
),
Ok(1)
);
assert_eq!(
dict.parse("
<Duration Seconds>
~
~<PosInt 10 BigEndian>
~< Seq <Digit 10> ~ Char >"
).expect("parse error")
.is_syntactic_subtype_of(
&dict.parse("<Seq Char>").expect("parse errror")
),
Ok(4)
);
}