@@ -2582,139 +2582,4 @@ impl FromStr for Json {
25822582}
25832583
25842584#[ cfg( test) ]
2585- mod tests {
2586- // Benchmarks and tests that require private items
2587-
2588- extern crate test;
2589- use test:: Bencher ;
2590- use super :: { from_str, Parser , StackElement , Stack } ;
2591- use std:: string;
2592-
2593- #[ test]
2594- fn test_stack ( ) {
2595- let mut stack = Stack :: new ( ) ;
2596-
2597- assert ! ( stack. is_empty( ) ) ;
2598- assert ! ( stack. is_empty( ) ) ;
2599- assert ! ( !stack. last_is_index( ) ) ;
2600-
2601- stack. push_index ( 0 ) ;
2602- stack. bump_index ( ) ;
2603-
2604- assert ! ( stack. len( ) == 1 ) ;
2605- assert ! ( stack. is_equal_to( & [ StackElement :: Index ( 1 ) ] ) ) ;
2606- assert ! ( stack. starts_with( & [ StackElement :: Index ( 1 ) ] ) ) ;
2607- assert ! ( stack. ends_with( & [ StackElement :: Index ( 1 ) ] ) ) ;
2608- assert ! ( stack. last_is_index( ) ) ;
2609- assert ! ( stack. get( 0 ) == StackElement :: Index ( 1 ) ) ;
2610-
2611- stack. push_key ( "foo" . to_string ( ) ) ;
2612-
2613- assert ! ( stack. len( ) == 2 ) ;
2614- assert ! ( stack. is_equal_to( & [ StackElement :: Index ( 1 ) , StackElement :: Key ( "foo" ) ] ) ) ;
2615- assert ! ( stack. starts_with( & [ StackElement :: Index ( 1 ) , StackElement :: Key ( "foo" ) ] ) ) ;
2616- assert ! ( stack. starts_with( & [ StackElement :: Index ( 1 ) ] ) ) ;
2617- assert ! ( stack. ends_with( & [ StackElement :: Index ( 1 ) , StackElement :: Key ( "foo" ) ] ) ) ;
2618- assert ! ( stack. ends_with( & [ StackElement :: Key ( "foo" ) ] ) ) ;
2619- assert ! ( !stack. last_is_index( ) ) ;
2620- assert ! ( stack. get( 0 ) == StackElement :: Index ( 1 ) ) ;
2621- assert ! ( stack. get( 1 ) == StackElement :: Key ( "foo" ) ) ;
2622-
2623- stack. push_key ( "bar" . to_string ( ) ) ;
2624-
2625- assert ! ( stack. len( ) == 3 ) ;
2626- assert ! ( stack. is_equal_to( & [ StackElement :: Index ( 1 ) ,
2627- StackElement :: Key ( "foo" ) ,
2628- StackElement :: Key ( "bar" ) ] ) ) ;
2629- assert ! ( stack. starts_with( & [ StackElement :: Index ( 1 ) ] ) ) ;
2630- assert ! ( stack. starts_with( & [ StackElement :: Index ( 1 ) , StackElement :: Key ( "foo" ) ] ) ) ;
2631- assert ! ( stack. starts_with( & [ StackElement :: Index ( 1 ) ,
2632- StackElement :: Key ( "foo" ) ,
2633- StackElement :: Key ( "bar" ) ] ) ) ;
2634- assert ! ( stack. ends_with( & [ StackElement :: Key ( "bar" ) ] ) ) ;
2635- assert ! ( stack. ends_with( & [ StackElement :: Key ( "foo" ) , StackElement :: Key ( "bar" ) ] ) ) ;
2636- assert ! ( stack. ends_with( & [ StackElement :: Index ( 1 ) ,
2637- StackElement :: Key ( "foo" ) ,
2638- StackElement :: Key ( "bar" ) ] ) ) ;
2639- assert ! ( !stack. last_is_index( ) ) ;
2640- assert ! ( stack. get( 0 ) == StackElement :: Index ( 1 ) ) ;
2641- assert ! ( stack. get( 1 ) == StackElement :: Key ( "foo" ) ) ;
2642- assert ! ( stack. get( 2 ) == StackElement :: Key ( "bar" ) ) ;
2643-
2644- stack. pop ( ) ;
2645-
2646- assert ! ( stack. len( ) == 2 ) ;
2647- assert ! ( stack. is_equal_to( & [ StackElement :: Index ( 1 ) , StackElement :: Key ( "foo" ) ] ) ) ;
2648- assert ! ( stack. starts_with( & [ StackElement :: Index ( 1 ) , StackElement :: Key ( "foo" ) ] ) ) ;
2649- assert ! ( stack. starts_with( & [ StackElement :: Index ( 1 ) ] ) ) ;
2650- assert ! ( stack. ends_with( & [ StackElement :: Index ( 1 ) , StackElement :: Key ( "foo" ) ] ) ) ;
2651- assert ! ( stack. ends_with( & [ StackElement :: Key ( "foo" ) ] ) ) ;
2652- assert ! ( !stack. last_is_index( ) ) ;
2653- assert ! ( stack. get( 0 ) == StackElement :: Index ( 1 ) ) ;
2654- assert ! ( stack. get( 1 ) == StackElement :: Key ( "foo" ) ) ;
2655- }
2656-
2657- #[ bench]
2658- fn bench_streaming_small ( b : & mut Bencher ) {
2659- b. iter ( || {
2660- let mut parser = Parser :: new (
2661- r#"{
2662- "a": 1.0,
2663- "b": [
2664- true,
2665- "foo\nbar",
2666- { "c": {"d": null} }
2667- ]
2668- }"# . chars ( )
2669- ) ;
2670- loop {
2671- match parser. next ( ) {
2672- None => return ,
2673- _ => { }
2674- }
2675- }
2676- } ) ;
2677- }
2678- #[ bench]
2679- fn bench_small ( b : & mut Bencher ) {
2680- b. iter ( || {
2681- let _ = from_str ( r#"{
2682- "a": 1.0,
2683- "b": [
2684- true,
2685- "foo\nbar",
2686- { "c": {"d": null} }
2687- ]
2688- }"# ) ;
2689- } ) ;
2690- }
2691-
2692- fn big_json ( ) -> string:: String {
2693- let mut src = "[\n " . to_string ( ) ;
2694- for _ in 0 ..500 {
2695- src. push_str ( r#"{ "a": true, "b": null, "c":3.1415, "d": "Hello world", "e": \
2696- [1,2,3]},"# ) ;
2697- }
2698- src. push_str ( "{}]" ) ;
2699- return src;
2700- }
2701-
2702- #[ bench]
2703- fn bench_streaming_large ( b : & mut Bencher ) {
2704- let src = big_json ( ) ;
2705- b. iter ( || {
2706- let mut parser = Parser :: new ( src. chars ( ) ) ;
2707- loop {
2708- match parser. next ( ) {
2709- None => return ,
2710- _ => { }
2711- }
2712- }
2713- } ) ;
2714- }
2715- #[ bench]
2716- fn bench_large ( b : & mut Bencher ) {
2717- let src = big_json ( ) ;
2718- b. iter ( || { let _ = from_str ( & src) ; } ) ;
2719- }
2720- }
2585+ mod tests;
0 commit comments