mirror of
https://github.com/typst/typst
synced 2025-08-19 01:18:32 +08:00
Miri test
This commit is contained in:
parent
d12cad6e46
commit
19559466e5
12
.github/workflows/ci.yml
vendored
12
.github/workflows/ci.yml
vendored
@ -103,3 +103,15 @@ jobs:
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo install --locked cargo-fuzz@0.12.0
|
||||
- run: cd tests/fuzz && cargo fuzz build --dev
|
||||
|
||||
miri:
|
||||
name: Check unsafe code
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
components: miri
|
||||
toolchain: nightly-2024-10-29
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo miri test -p typst-library test_miri
|
||||
|
@ -385,3 +385,42 @@ fn ref_count_overflow(ptr: NonNull<Header>, elem: Element, span: Span) -> ! {
|
||||
drop(RawContent { ptr, elem, span });
|
||||
panic!("reference count overflow");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::foundations::{NativeElement, Repr, StyleChain, Value};
|
||||
use crate::introspection::Location;
|
||||
use crate::model::HeadingElem;
|
||||
use crate::text::TextElem;
|
||||
|
||||
#[test]
|
||||
fn test_miri() {
|
||||
let styles = StyleChain::default();
|
||||
|
||||
let mut first = HeadingElem::new(TextElem::packed("Hi!")).with_offset(2).pack();
|
||||
let hash1 = typst_utils::hash128(&first);
|
||||
first.set_location(Location::new(10));
|
||||
let _ = format!("{first:?}");
|
||||
let _ = first.repr();
|
||||
|
||||
assert!(first.is::<HeadingElem>());
|
||||
assert!(!first.is::<TextElem>());
|
||||
assert_eq!(first.to_packed::<TextElem>(), None);
|
||||
assert_eq!(first.location(), Some(Location::new(10)));
|
||||
assert_eq!(first.field_by_name("offset"), Ok(Value::Int(2)));
|
||||
assert!(!first.has("depth".into()));
|
||||
|
||||
let second = first.clone();
|
||||
first.materialize(styles);
|
||||
|
||||
let first_packed = first.to_packed::<HeadingElem>().unwrap();
|
||||
let second_packed = second.to_packed::<HeadingElem>().unwrap();
|
||||
|
||||
assert!(first.has("depth".into()));
|
||||
assert!(!second.has("depth".into()));
|
||||
assert!(first_packed.depth.is_set());
|
||||
assert!(!second_packed.depth.is_set());
|
||||
assert_ne!(first, second);
|
||||
assert_ne!(hash1, typst_utils::hash128(&first));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user