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

Function allocation_test

crates/css_ast/tests/allocations.rs:14–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

getFunction · 0.85

Tested by

no test coverage detected