Skip to content

Commit ed98eaf

Browse files
test: generate size table directly
1 parent e94cb6f commit ed98eaf

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ For reference here are the sizes associated with their different functions
8686
| ---: | ---: | ---: |
8787
| [`acknowledgement::listing()`](https://docs.rs/two-face/latest/two_face/acknowledgement/fn.listing.html) | 10 | - |
8888
| [`syntax::extra_newlines()`](https://docs.rs/two-face/latest/two_face/syntax/fn.extra_newlines.html) (onig) | 939 | 360 |
89-
| ^^ (fancy) | 884 | 360 |
89+
| ^^ (fancy) | 884 | ^^ |
9090
| [`syntax::extra_no_newlines()`](https://docs.rs/two-face/latest/two_face/syntax/fn.extra_no_newlines.html) (onig) | 938 | 359 |
91-
| ^^ (fancy) | 883 | 359 |
91+
| ^^ (fancy) | 883 | ^^ |
9292
| [`theme::extra()`](https://docs.rs/two-face/latest/two_face/theme/index.html) | 62 | 5 |
9393

9494
In short the syntax definitions are the real chonky part, and if you're

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@
7979
//! | ---: | ---: | ---: |
8080
//! | [`acknowledgement::listing()`] | 10 | - |
8181
//! | [`syntax::extra_newlines()`] (onig) | 939 | 360 |
82-
//! | ^^ (fancy) | 884 | 360 |
82+
//! | ^^ (fancy) | 884 | ^^ |
8383
//! | [`syntax::extra_no_newlines()`] (onig) | 938 | 359 |
84-
//! | ^^ (fancy) | 883 | 359 |
84+
//! | ^^ (fancy) | 883 | ^^ |
8585
//! | [`theme::extra()`] | 62 | 5 |
8686
//!
8787
//! In short the syntax definitions are the real chonky part, and if you're

tests/docs_watchdog/readme.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,52 @@
1-
use std::{collections::BTreeSet, fs};
1+
use std::collections::BTreeSet;
22

3-
use crate::utils::TwoFaceAsset;
3+
use crate::utils::{Asset, AssetFingerprint, SyntectAsset, TwoFaceAsset};
44

55
#[test]
66
fn embedded_asset_sizes() {
77
#[track_caller]
8-
fn kib(gen: TwoFaceAsset) -> usize {
9-
let meta = fs::metadata(gen.rel_path()).unwrap();
10-
(meta.len() as f64 / 1_024.0).round() as usize
8+
fn kib(gen: Asset) -> usize {
9+
let fingerprint: AssetFingerprint = gen.into();
10+
(fingerprint.size as f64 / 1_024.0).round() as usize
1111
}
1212

13-
assert_eq!(10, kib(TwoFaceAsset::AckFull));
13+
let tf_ack = kib(TwoFaceAsset::AckFull.into());
14+
let tf_son = kib(TwoFaceAsset::SynOnigNewlines.into());
15+
let tf_sfn = kib(TwoFaceAsset::SynFancyNewlines.into());
16+
let tf_sonn = kib(TwoFaceAsset::SynOnigNoNewlines.into());
17+
let tf_sfnn = kib(TwoFaceAsset::SynFancyNoNewlines.into());
18+
let tf_themes = kib(TwoFaceAsset::Themes.into());
1419

15-
assert_eq!(939, kib(TwoFaceAsset::SynOnigNewlines));
16-
assert_eq!(884, kib(TwoFaceAsset::SynFancyNewlines));
20+
let syn_sn = kib(SyntectAsset::SynNewlines.into());
21+
let syn_snn = kib(SyntectAsset::SynNoNewlines.into());
22+
let syn_themes = kib(SyntectAsset::Themes.into());
1723

18-
assert_eq!(938, kib(TwoFaceAsset::SynOnigNoNewlines));
19-
assert_eq!(883, kib(TwoFaceAsset::SynFancyNoNewlines));
24+
let table = format!(
25+
"\
26+
| function | `two-face` (KiB) | `syntect` (KiB) |\n\
27+
| ---: | ---: | ---: |\n\
28+
| [`acknowledgement::listing()`] | {tf_ack} | - |\n\
29+
| [`syntax::extra_newlines()`] (onig) | {tf_son} | {syn_sn} |\n\
30+
| ^^ (fancy) | {tf_sfn} | ^^ |\n\
31+
| [`syntax::extra_no_newlines()`] (onig) | {tf_sonn} | {syn_snn} |\n\
32+
| ^^ (fancy) | {tf_sfnn} | ^^ |\n\
33+
| [`theme::extra()`] | {tf_themes} | {syn_themes} |\n\
34+
"
35+
);
2036

21-
assert_eq!(62, kib(TwoFaceAsset::Themes));
37+
insta::assert_snapshot!(
38+
table,
39+
@r"
40+
| function | `two-face` (KiB) | `syntect` (KiB) |
41+
| ---: | ---: | ---: |
42+
| [`acknowledgement::listing()`] | 10 | - |
43+
| [`syntax::extra_newlines()`] (onig) | 939 | 360 |
44+
| ^^ (fancy) | 884 | ^^ |
45+
| [`syntax::extra_no_newlines()`] (onig) | 938 | 359 |
46+
| ^^ (fancy) | 883 | ^^ |
47+
| [`theme::extra()`] | 62 | 5 |
48+
"
49+
);
2250
}
2351

2452
#[rustfmt::skip]

tests/utils/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ pub enum SyntectAsset {
107107

108108
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
109109
pub struct AssetFingerprint {
110-
prefix: Vec<u8>,
111-
hash: u32,
112-
size: usize,
110+
pub prefix: Vec<u8>,
111+
pub hash: u32,
112+
pub size: usize,
113113
}
114114

115115
impl AssetFingerprint {

0 commit comments

Comments
 (0)