mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-05-30 16:11:41 +00:00
Refactor limits test
This commit is contained in:
parent
b146c21147
commit
ba6018957a
@ -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
|
||||||
let m = module()
|
(10, Some(10), true),
|
||||||
.memory()
|
// table/memory is always valid without max
|
||||||
.with_min(10)
|
(10, None, true),
|
||||||
.with_max(Some(10))
|
];
|
||||||
.build()
|
|
||||||
.build();
|
|
||||||
assert!(validate_module(&m).is_ok());
|
|
||||||
|
|
||||||
// mem is always valid without max
|
for (min, max, is_valid) in test_cases {
|
||||||
|
// defined table
|
||||||
let m = module()
|
let m = module()
|
||||||
.memory()
|
.table()
|
||||||
.with_min(10)
|
.with_min(min)
|
||||||
|
.with_max(max)
|
||||||
.build()
|
.build()
|
||||||
.build();
|
.build();
|
||||||
assert!(validate_module(&m).is_ok());
|
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()
|
||||||
|
.memory()
|
||||||
|
.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(),
|
||||||
|
"memory".into(),
|
||||||
|
External::Memory(MemoryType::new(min, max))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
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]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user