json_parser_unittest.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. use base::{JsonOptions, NewValueSlotForTesting, ValueSlotRef};
  2. use rust_gtest_interop::prelude::*;
  3. #[gtest(RustJsonParserTest, ChromiumExtensions)]
  4. fn test_chromium_extensions() {
  5. let opts = JsonOptions::with_chromium_extensions(101);
  6. expect_eq!(opts.allow_trailing_commas, false);
  7. expect_eq!(opts.replace_invalid_characters, false);
  8. expect_eq!(opts.allow_comments, true);
  9. expect_eq!(opts.allow_control_chars, true);
  10. expect_eq!(opts.allow_vert_tab, true);
  11. expect_eq!(opts.allow_x_escapes, true);
  12. expect_eq!(opts.max_depth, 101);
  13. }
  14. #[gtest(RustJsonParserTest, DecodeJson)]
  15. fn test_decode_json() {
  16. // Exhaustively tested by existing C++ JSON tests.
  17. // This test is almost pointless but it seems wise to have a single
  18. // Rust-side test for the basics.
  19. let options = JsonOptions {
  20. max_depth: 128,
  21. allow_trailing_commas: false,
  22. replace_invalid_characters: false,
  23. allow_comments: false,
  24. allow_control_chars: false,
  25. allow_vert_tab: false,
  26. allow_x_escapes: false,
  27. };
  28. let mut value_slot = NewValueSlotForTesting();
  29. base::decode_json(b"{ \"a\": 4 }", options, ValueSlotRef::from(&mut value_slot)).unwrap();
  30. expect_eq!(format!("{:?}", ValueSlotRef::from(&mut value_slot)), "{\n \"a\": 4\n}\n");
  31. }