Skip to content

Commit 2607bd7

Browse files
add expected test
1 parent e88e4d8 commit 2607bd7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trim_ascii_start.loop_invariant_base.1\
2+
- Status: SUCCESS\
3+
- Description: "Check invariant before entry for loop trim_ascii_start.0"
4+
5+
trim_ascii_start.loop_invariant_step.1\
6+
- Status: SUCCESS\
7+
- Description: "Check invariant after step for loop trim_ascii_start.0"
8+
9+
VERIFICATION:- SUCCESSFUL
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// kani-flags: -Z loop-contracts
5+
6+
//! Check if while-let invariant is correctly applied.
7+
8+
#![feature(proc_macro_hygiene)]
9+
#![feature(stmt_expr_attributes)]
10+
11+
#[kani::proof]
12+
fn trim_ascii_start() {
13+
let mut a: [u8; 10] = kani::any();
14+
let s = a.as_slice();
15+
let mut bytes = s;
16+
#[kani::loop_invariant(
17+
bytes.len() <= s.len() &&
18+
(bytes.len() == 0 || (&s[s.len()-bytes.len()..]).as_ptr() == bytes.as_ptr())
19+
)]
20+
while let [first, rest @ ..] = bytes {
21+
if first.is_ascii_whitespace() {
22+
bytes = rest;
23+
} else {
24+
break;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)