summaryrefslogtreecommitdiff
path: root/chromium/base/json/json_parser_unittest.rs
blob: 6bb9b733538591a03531ed9928fcd5ab6288929b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use base::{JsonOptions, NewValueSlotForTesting, ValueSlotRef};
use rust_gtest_interop::prelude::*;

#[gtest(RustJsonParserTest, ChromiumExtensions)]
fn test_chromium_extensions() {
    let opts = JsonOptions::with_chromium_extensions(101);
    expect_eq!(opts.allow_trailing_commas, false);
    expect_eq!(opts.replace_invalid_characters, false);
    expect_eq!(opts.allow_comments, true);
    expect_eq!(opts.allow_control_chars, true);
    expect_eq!(opts.allow_vert_tab, true);
    expect_eq!(opts.allow_x_escapes, true);
    expect_eq!(opts.max_depth, 101);
}

#[gtest(RustJsonParserTest, DecodeJson)]
fn test_decode_json() {
    // Exhaustively tested by existing C++ JSON tests.
    // This test is almost pointless but it seems wise to have a single
    // Rust-side test for the basics.
    let options = JsonOptions {
        max_depth: 128,
        allow_trailing_commas: false,
        replace_invalid_characters: false,
        allow_comments: false,
        allow_control_chars: false,
        allow_vert_tab: false,
        allow_x_escapes: false,
    };
    let mut value_slot = NewValueSlotForTesting();
    base::decode_json(b"{ \"a\": 4 }", options, ValueSlotRef::from(&mut value_slot)).unwrap();
    expect_eq!(format!("{:?}", ValueSlotRef::from(&mut value_slot)), "{\n   \"a\": 4\n}\n");
}