Refactor limits test

This commit is contained in:
Sergey Pepyakin 2017-12-05 17:06:39 +01:00
parent b146c21147
commit ba6018957a

View File

@ -11,61 +11,59 @@ fn empty_is_valid() {
} }
#[test] #[test]
fn mem_limits() { fn limits() {
let test_cases = vec![
// min > max // min > max
let m = module() (10, Some(9), false),
.memory()
.with_min(10)
.with_max(Some(9))
.build()
.build();
assert!(validate_module(&m).is_err());
// min = max // min = max
(10, Some(10), true),
// table/memory is always valid without max
(10, None, true),
];
for (min, max, is_valid) in test_cases {
// defined table
let m = module()
.table()
.with_min(min)
.with_max(max)
.build()
.build();
assert_eq!(validate_module(&m).is_ok(), is_valid);
// imported table
let m = module()
.with_import(
ImportEntry::new(
"core".into(),
"table".into(),
External::Table(TableType::new(min, max))
)
)
.build();
assert_eq!(validate_module(&m).is_ok(), is_valid);
// defined memory
let m = module() let m = module()
.memory() .memory()
.with_min(10) .with_min(min)
.with_max(Some(10)) .with_max(max)
.build() .build()
.build(); .build();
assert!(validate_module(&m).is_ok()); assert_eq!(validate_module(&m).is_ok(), is_valid);
// mem is always valid without max // imported table
let m = module() let m = module()
.memory() .with_import(
.with_min(10) ImportEntry::new(
.build() "core".into(),
"memory".into(),
External::Memory(MemoryType::new(min, max))
)
)
.build(); .build();
assert!(validate_module(&m).is_ok()); assert_eq!(validate_module(&m).is_ok(), is_valid);
} }
#[test]
fn table_limits() {
// min > max
let m = module()
.table()
.with_min(10)
.with_max(Some(9))
.build()
.build();
assert!(validate_module(&m).is_err());
// min = max
let m = module()
.table()
.with_min(10)
.with_max(Some(10))
.build()
.build();
assert!(validate_module(&m).is_ok());
// table is always valid without max
let m = module()
.table()
.with_min(10)
.build()
.build();
assert!(validate_module(&m).is_ok());
} }
#[test] #[test]