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