MCPcopy Create free account
hub / github.com/csskit/csskit / allocation_test

Function allocation_test

crates/css_parse/tests/allocations.rs:13–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12#[test]
13fn allocation_test() {
14 let simple_bump_size = 960;
15 let simple_bump = Bump::with_capacity(simple_bump_size);
16 let simple_str = "body{color:blue}";
17 let simple_lexer = Lexer::new(&EmptyAtomSet::ATOMS, simple_str);
18 let mut simple_parser = Parser::new(&simple_bump, simple_str, simple_lexer);
19
20 let escaped_bump_size = 960;
21 let escaped_bump = Bump::with_capacity(escaped_bump_size);
22 let escaped_str = "bo\\d y{background-image:\\75\\52\\6c(a);width:1\\70\\78}";
23 let escaped_lexer = Lexer::new(&EmptyAtomSet::ATOMS, escaped_str);
24 let mut escape_parser = Parser::new(&escaped_bump, escaped_str, escaped_lexer);
25
26 let big_bump_size = 100_003_776;
27 let big_bump = Bump::with_capacity(big_bump_size);
28 let big_str = read_to_string("../../coverage/popular/tailwind.2.2.19.min.css").unwrap();
29 let big_lexer = Lexer::new(&EmptyAtomSet::ATOMS, &big_str);
30 let mut big_parser = Parser::new(&big_bump, &big_str, big_lexer);
31
32 #[cfg(feature = "_dhat-heap-testing")]
33 let _profiler = Profiler::builder()
34 .testing()
35 .file_name(format!("../../target/css_parse_allocations_test-{}.json", std::process::id()))
36 .build();
37
38 simple_parser.parse_entirely::<ComponentValues>();
39 #[cfg(feature = "_dhat-heap-testing")]
40 {
41 let stats = HeapStats::get();
42 assert_eq!(stats.total_blocks, 0);
43 assert_eq!(stats.total_bytes, 0);
44 }
45
46 escape_parser.parse_entirely::<ComponentValues>();
47 #[cfg(feature = "_dhat-heap-testing")]
48 {
49 let stats = HeapStats::get();
50 assert_eq!(stats.total_blocks, 0);
51 assert_eq!(stats.total_bytes, 0);
52 }
53
54 big_parser.parse_entirely::<ComponentValues>();
55 #[cfg(feature = "_dhat-heap-testing")]
56 {
57 let stats = HeapStats::get();
58 assert_eq!(stats.total_blocks, 0);
59 assert_eq!(stats.total_bytes, 0);
60 }
61
62 // XXX: If these fail because the numbers go down, great! If they go up, investigate why.
63 assert_eq!(simple_bump.allocated_bytes(), simple_bump_size);
64 assert_eq!(escaped_bump.allocated_bytes(), escaped_bump_size);
65 assert_eq!(big_bump.allocated_bytes(), big_bump_size);
66}

Callers

nothing calls this directly

Calls 1

getFunction · 0.85

Tested by

no test coverage detected