MCPcopy Create free account
hub / github.com/pest-parser/pest / stack_ops

Function stack_ops

pest/src/stack.rs:250–319  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

248
249 #[test]
250 fn stack_ops() {
251 let mut stack = Stack::new();
252
253 // []
254 assert!(stack.is_empty());
255 assert_eq!(stack.peek(), None);
256 assert_eq!(stack.pop(), None);
257
258 // [0]
259 stack.push(0);
260 assert!(!stack.is_empty());
261 assert_eq!(stack.peek(), Some(&0));
262
263 // [0, 1]
264 stack.push(1);
265 assert!(!stack.is_empty());
266 assert_eq!(stack.peek(), Some(&1));
267
268 // [0]
269 assert_eq!(stack.pop(), Some(1));
270 assert!(!stack.is_empty());
271 assert_eq!(stack.peek(), Some(&0));
272
273 // [0, 2]
274 stack.push(2);
275 assert!(!stack.is_empty());
276 assert_eq!(stack.peek(), Some(&2));
277
278 // [0, 2, 3]
279 stack.push(3);
280 assert!(!stack.is_empty());
281 assert_eq!(stack.peek(), Some(&3));
282
283 // Take a snapshot of the current stack
284 // [0, 2, 3]
285 stack.snapshot();
286
287 // [0, 2]
288 assert_eq!(stack.pop(), Some(3));
289 assert!(!stack.is_empty());
290 assert_eq!(stack.peek(), Some(&2));
291
292 // Take a snapshot of the current stack
293 // [0, 2]
294 stack.snapshot();
295
296 // [0]
297 assert_eq!(stack.pop(), Some(2));
298 assert!(!stack.is_empty());
299 assert_eq!(stack.peek(), Some(&0));
300
301 // []
302 assert_eq!(stack.pop(), Some(0));
303 assert!(stack.is_empty());
304
305 // Test backtracking
306 // [0, 2]
307 stack.restore();

Callers

nothing calls this directly

Calls 4

pushMethod · 0.80
snapshotMethod · 0.80
newFunction · 0.50
restoreMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…