1 // Benchmarks and tests that require private items
5 use super::{from_str, Parser, StackElement, Stack};
10 let mut stack = Stack::new();
12 assert!(stack.is_empty());
13 assert!(stack.is_empty());
14 assert!(!stack.last_is_index());
19 assert!(stack.len() == 1);
20 assert!(stack.is_equal_to(&[StackElement::Index(1)]));
21 assert!(stack.starts_with(&[StackElement::Index(1)]));
22 assert!(stack.ends_with(&[StackElement::Index(1)]));
23 assert!(stack.last_is_index());
24 assert!(stack.get(0) == StackElement::Index(1));
26 stack.push_key("foo".to_string());
28 assert!(stack.len() == 2);
29 assert!(stack.is_equal_to(&[StackElement::Index(1), StackElement::Key("foo")]));
30 assert!(stack.starts_with(&[StackElement::Index(1), StackElement::Key("foo")]));
31 assert!(stack.starts_with(&[StackElement::Index(1)]));
32 assert!(stack.ends_with(&[StackElement::Index(1), StackElement::Key("foo")]));
33 assert!(stack.ends_with(&[StackElement::Key("foo")]));
34 assert!(!stack.last_is_index());
35 assert!(stack.get(0) == StackElement::Index(1));
36 assert!(stack.get(1) == StackElement::Key("foo"));
38 stack.push_key("bar".to_string());
40 assert!(stack.len() == 3);
41 assert!(stack.is_equal_to(&[StackElement::Index(1),
42 StackElement::Key("foo"),
43 StackElement::Key("bar")]));
44 assert!(stack.starts_with(&[StackElement::Index(1)]));
45 assert!(stack.starts_with(&[StackElement::Index(1), StackElement::Key("foo")]));
46 assert!(stack.starts_with(&[StackElement::Index(1),
47 StackElement::Key("foo"),
48 StackElement::Key("bar")]));
49 assert!(stack.ends_with(&[StackElement::Key("bar")]));
50 assert!(stack.ends_with(&[StackElement::Key("foo"), StackElement::Key("bar")]));
51 assert!(stack.ends_with(&[StackElement::Index(1),
52 StackElement::Key("foo"),
53 StackElement::Key("bar")]));
54 assert!(!stack.last_is_index());
55 assert!(stack.get(0) == StackElement::Index(1));
56 assert!(stack.get(1) == StackElement::Key("foo"));
57 assert!(stack.get(2) == StackElement::Key("bar"));
61 assert!(stack.len() == 2);
62 assert!(stack.is_equal_to(&[StackElement::Index(1), StackElement::Key("foo")]));
63 assert!(stack.starts_with(&[StackElement::Index(1), StackElement::Key("foo")]));
64 assert!(stack.starts_with(&[StackElement::Index(1)]));
65 assert!(stack.ends_with(&[StackElement::Index(1), StackElement::Key("foo")]));
66 assert!(stack.ends_with(&[StackElement::Key("foo")]));
67 assert!(!stack.last_is_index());
68 assert!(stack.get(0) == StackElement::Index(1));
69 assert!(stack.get(1) == StackElement::Key("foo"));
73 fn bench_streaming_small(b: &mut Bencher) {
75 let mut parser = Parser::new(
94 fn bench_small(b: &mut Bencher) {
107 fn big_json() -> string::String {
108 let mut src = "[\n".to_string();
110 src.push_str(r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e": \
118 fn bench_streaming_large(b: &mut Bencher) {
119 let src = big_json();
121 let mut parser = Parser::new(src.chars());
123 match parser.next() {
131 fn bench_large(b: &mut Bencher) {
132 let src = big_json();
133 b.iter( || { let _ = from_str(&src); });