switch pnf tests to sugared terms

This commit is contained in:
Michael Sippel 2025-04-05 22:55:20 +02:00
parent 78c83cc481
commit 2ecbc84233
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -1,58 +1,79 @@
use crate::{dict::BimapTypeDict, parser::*};
#[test]
fn test_param_normalize() {
fn test_normalize_id() {
let mut dict = BimapTypeDict::new();
assert_eq!(
dict.parse("A~B~C").expect("parse error"),
dict.parse("A~B~C").expect("parse error").param_normalize(),
dict.parse("A~B~C").expect("parse error").sugar(&mut dict),
dict.parse("A~B~C").expect("parse error").sugar(&mut dict).normalize(),
);
assert_eq!(
dict.parse("<A B>~C").expect("parse error"),
dict.parse("<A B>~C").expect("parse error").param_normalize(),
);
assert_eq!(
dict.parse("<A B~C>").expect("parse error"),
dict.parse("<A B>~<A C>").expect("parse error").param_normalize(),
);
assert_eq!(
dict.parse("<A~Y B>").expect("parse error"),
dict.parse("<A B>~<Y B>").expect("parse error").param_normalize(),
);
assert_eq!(
dict.parse("<A B~C D~E>").expect("parse error"),
dict.parse("<A B D>~<A C D>~<A C E>").expect("parse errror").param_normalize(),
);
assert_eq!(
dict.parse("<A~X B~C D~E>").expect("parse error"),
dict.parse("<A B D>~<A B~C E>~<X C E>").expect("parse errror").param_normalize(),
);
assert_eq!(
dict.parse("<Seq <Digit 10>~Char>").expect("parse error"),
dict.parse("<Seq <Digit 10>>~<Seq Char>").expect("parse errror").param_normalize(),
);
assert_eq!(
dict.parse("<Seq Char> ~ <<ValueDelim '\\0'> Char> ~ <<ValueDelim '\\0'> Ascii~x86.UInt8>").expect("parse error").param_normalize(),
dict.parse("<Seq~<ValueDelim '\\0'> Char~Ascii~x86.UInt8>").expect("parse error")
);
assert_eq!(
dict.parse("<Seq Char~Ascii> ~ <<ValueDelim '\\0'> Char~Ascii> ~ <<ValueDelim '\\0'> x86.UInt8>").expect("parse error").param_normalize(),
dict.parse("<Seq~<ValueDelim '\\0'> Char~Ascii~x86.UInt8>").expect("parse error")
);
assert_eq!(
dict.parse("<A~Y <B C~D~E> F H H>").expect("parse error"),
dict.parse("<A <B C> F H H>
~<A <B D> F H H>
~<A~Y <B E> F H H>").expect("parse errror")
.param_normalize(),
dict.parse("<A B>~C").expect("parse error").sugar(&mut dict),
dict.parse("<A B>~C").expect("parse error").sugar(&mut dict).normalize(),
);
}
#[test]
fn test_normalize_spec() {
let mut dict = BimapTypeDict::new();
assert_eq!(
dict.parse("<A B~C>").expect("parse error").sugar(&mut dict),
dict.parse("<A B>~<A C>").expect("parse error").sugar(&mut dict).normalize(),
);
assert_eq!(
dict.parse("<A~Y B>").expect("parse error").sugar(&mut dict),
dict.parse("<A B>~<Y B>").expect("parse error").sugar(&mut dict).normalize(),
);
assert_eq!(
dict.parse("<A B~C D~E>").expect("parse error").sugar(&mut dict),
dict.parse("<A B D>~<A C D>~<A C E>").expect("parse errror").sugar(&mut dict).normalize(),
);
assert_eq!(
dict.parse("<A~X B~C D~E>").expect("parse error").sugar(&mut dict),
dict.parse("<A B D>~<A B~C E>~<X C E>").expect("parse errror").sugar(&mut dict).normalize(),
);
}
#[test]
fn test_normalize_seq() {
let mut dict = BimapTypeDict::new();
assert_eq!(
dict.parse("<Seq Char~Ascii>").expect("parse error").sugar(&mut dict),
dict.parse("<Seq Char>~<Seq Ascii>").expect("parse errror").sugar(&mut dict).normalize(),
);
eprintln!("---------------");
assert_eq!(
dict.parse("<Seq <Digit 10>~Char>").expect("parse error").sugar(&mut dict),
dict.parse("<Seq <Digit 10>>~<Seq Char>").expect("parse errror").sugar(&mut dict).normalize(),
);
eprintln!("---------------");
assert_eq!(
dict.parse("<Seq~<ValueDelim '\\0'> Char~Ascii~native.UInt8>").expect("parse error").sugar(&mut dict),
dict.parse("<Seq Char> ~ <<ValueDelim '\\0'> Char> ~ <<ValueDelim '\\0'> Ascii~native.UInt8>").expect("parse error").sugar(&mut dict).normalize(),
);
eprintln!("---------------");
assert_eq!(
dict.parse("<Seq~<ValueDelim '\\0'> Char~Ascii~native.UInt8>").expect("parse error").sugar(&mut dict),
dict.parse("<Seq Char~Ascii> ~ <<ValueDelim '\\0'> Char~Ascii> ~ <<ValueDelim '\\0'> native.UInt8>").expect("parse error").sugar(&mut dict).normalize(),
);
}
#[test]
fn test_normalize_complex_spec() {
let mut dict = BimapTypeDict::new();
assert_eq!(
dict.parse("<A~Y <B C~D~E> F H H>").expect("parse error").sugar(&mut dict),
dict.parse("<A <B C> F H H>
~<A <B D> F H H>
~<A~Y <B E> F H H>").expect("parse errror").sugar(&mut dict)
.normalize(),
);
}