diff --git a/cli/src/main.rs b/cli/src/main.rs index cdbd59263..7b9611830 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -395,7 +395,7 @@ impl SystemWorld { Self { root, - library: Prehashed::new(typst_library::new()), + library: Prehashed::new(typst_library::build()), book: Prehashed::new(searcher.book), fonts: searcher.fonts, hashes: RefCell::default(), diff --git a/library/src/structure/heading.rs b/library/src/basics/heading.rs similarity index 100% rename from library/src/structure/heading.rs rename to library/src/basics/heading.rs diff --git a/library/src/structure/list.rs b/library/src/basics/list.rs similarity index 98% rename from library/src/structure/list.rs rename to library/src/basics/list.rs index b51284a8f..c73ffea63 100644 --- a/library/src/structure/list.rs +++ b/library/src/basics/list.rs @@ -1,7 +1,7 @@ -use crate::base::NumberingPattern; -use crate::layout::{BlockNode, GridNode, HNode, Spacing, TrackSizing}; +use crate::compute::NumberingPattern; +use crate::layout::{BlockNode, GridNode, HNode, ParNode, Spacing, TrackSizing}; use crate::prelude::*; -use crate::text::{ParNode, SpaceNode, TextNode}; +use crate::text::{SpaceNode, TextNode}; /// An unordered (bulleted) or ordered (numbered) list. #[derive(Debug, Hash)] diff --git a/library/src/basics/mod.rs b/library/src/basics/mod.rs new file mode 100644 index 000000000..5916df6bc --- /dev/null +++ b/library/src/basics/mod.rs @@ -0,0 +1,9 @@ +//! Common document elements. + +mod heading; +mod list; +mod table; + +pub use self::heading::*; +pub use self::list::*; +pub use self::table::*; diff --git a/library/src/structure/table.rs b/library/src/basics/table.rs similarity index 100% rename from library/src/structure/table.rs rename to library/src/basics/table.rs diff --git a/library/src/base/calc.rs b/library/src/compute/calc.rs similarity index 100% rename from library/src/base/calc.rs rename to library/src/compute/calc.rs diff --git a/library/src/base/create.rs b/library/src/compute/create.rs similarity index 95% rename from library/src/base/create.rs rename to library/src/compute/create.rs index be8e822fe..4fd27499c 100644 --- a/library/src/base/create.rs +++ b/library/src/compute/create.rs @@ -106,12 +106,6 @@ pub fn str(_: &Vm, args: &mut Args) -> SourceResult { })) } -/// Create a blind text string. -pub fn lorem(_: &Vm, args: &mut Args) -> SourceResult { - let words: usize = args.expect("number of words")?; - Ok(Value::Str(lipsum::lipsum(words).into())) -} - /// Create a label from a string. pub fn label(_: &Vm, args: &mut Args) -> SourceResult { Ok(Value::Label(Label(args.expect("string")?))) diff --git a/library/src/base/data.rs b/library/src/compute/data.rs similarity index 100% rename from library/src/base/data.rs rename to library/src/compute/data.rs diff --git a/library/src/base/mod.rs b/library/src/compute/foundations.rs similarity index 80% rename from library/src/base/mod.rs rename to library/src/compute/foundations.rs index 501edd712..3e4101850 100644 --- a/library/src/base/mod.rs +++ b/library/src/compute/foundations.rs @@ -1,20 +1,9 @@ -//! Foundational functions. - -mod calc; -mod create; -mod data; -mod numbering; - -pub use self::calc::*; -pub use self::create::*; -pub use self::data::*; -pub use self::numbering::*; +use crate::prelude::*; use comemo::Track; -use typst::model::{self, Route, Vm}; -use typst::syntax::Source; -use crate::prelude::*; +use typst::model; +use typst::syntax::Source; /// The name of a value's type. pub fn type_(_: &Vm, args: &mut Args) -> SourceResult { @@ -39,7 +28,7 @@ pub fn assert(_: &Vm, args: &mut Args) -> SourceResult { pub fn eval(vm: &Vm, args: &mut Args) -> SourceResult { let Spanned { v: text, span } = args.expect::>("source")?; let source = Source::synthesized(text, span); - let route = Route::default(); + let route = model::Route::default(); let module = model::eval(vm.world(), route.track(), &source)?; Ok(Value::Content(module.content)) } diff --git a/library/src/compute/mod.rs b/library/src/compute/mod.rs new file mode 100644 index 000000000..70690d440 --- /dev/null +++ b/library/src/compute/mod.rs @@ -0,0 +1,13 @@ +//! Computational functions. + +mod calc; +mod create; +mod data; +mod foundations; +mod utility; + +pub use self::calc::*; +pub use self::create::*; +pub use self::data::*; +pub use self::foundations::*; +pub use self::utility::*; diff --git a/library/src/base/numbering.rs b/library/src/compute/utility.rs similarity index 90% rename from library/src/base/numbering.rs rename to library/src/compute/utility.rs index ea45fbc6d..2b04dfd6f 100644 --- a/library/src/base/numbering.rs +++ b/library/src/compute/utility.rs @@ -4,6 +4,12 @@ use unscanny::Scanner; use crate::prelude::*; +/// Create a blind text string. +pub fn lorem(_: &Vm, args: &mut Args) -> SourceResult { + let words: usize = args.expect("number of words")?; + Ok(Value::Str(lipsum::lipsum(words).into())) +} + /// Apply a numbering pattern to a number. pub fn numbering(_: &Vm, args: &mut Args) -> SourceResult { let number = args.expect::("number")?; @@ -11,7 +17,15 @@ pub fn numbering(_: &Vm, args: &mut Args) -> SourceResult { Ok(Value::Str(pattern.apply(number).into())) } -/// A numbering pattern for lists or headings. +/// How to turn a number into text. +/// +/// A pattern consists of a prefix, followed by one of `1`, `a`, `A`, `i`, `I` +/// or `*`, and then a suffix. +/// +/// Examples of valid patterns: +/// - `1)` +/// - `a.` +/// - `(I)` #[derive(Debug, Clone, Eq, PartialEq, Hash)] pub struct NumberingPattern { prefix: EcoString, @@ -60,7 +74,7 @@ castable! { /// Different kinds of numberings. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum NumberingKind { +enum NumberingKind { Arabic, Letter, Roman, diff --git a/library/src/layout/align.rs b/library/src/layout/align.rs index d8b6d92e8..a06f7edb4 100644 --- a/library/src/layout/align.rs +++ b/library/src/layout/align.rs @@ -1,5 +1,5 @@ +use super::{HorizontalAlign, ParNode}; use crate::prelude::*; -use crate::text::{HorizontalAlign, ParNode}; /// Align content along the layouting axes. #[derive(Debug, Hash)] diff --git a/library/src/layout/flow.rs b/library/src/layout/flow.rs index 07c3e0121..b644d73f6 100644 --- a/library/src/layout/flow.rs +++ b/library/src/layout/flow.rs @@ -1,8 +1,7 @@ use typst::model::Style; -use super::{AlignNode, BlockNode, ColbreakNode, PlaceNode, Spacing, VNode}; +use super::{AlignNode, BlockNode, ColbreakNode, ParNode, PlaceNode, Spacing, VNode}; use crate::prelude::*; -use crate::text::ParNode; /// Arrange spacing, paragraphs and block-level nodes into a flow. /// diff --git a/library/src/graphics/hide.rs b/library/src/layout/hide.rs similarity index 100% rename from library/src/graphics/hide.rs rename to library/src/layout/hide.rs diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index 7edc88ad5..8f9337ba4 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -5,9 +5,12 @@ mod columns; mod container; mod flow; mod grid; +mod hide; mod pad; mod page; +mod par; mod place; +mod repeat; mod spacing; mod stack; mod transform; @@ -17,9 +20,12 @@ pub use self::columns::*; pub use self::container::*; pub use self::flow::*; pub use self::grid::*; +pub use self::hide::*; pub use self::pad::*; pub use self::page::*; +pub use self::par::*; pub use self::place::*; +pub use self::repeat::*; pub use self::spacing::*; pub use self::stack::*; pub use self::transform::*; @@ -36,14 +42,11 @@ use typst::model::{ }; use typst::World; +use crate::basics::{DescNode, EnumNode, ListItem, ListNode, DESC, ENUM, LIST}; +use crate::meta::DocumentNode; use crate::prelude::*; use crate::shared::BehavedBuilder; -use crate::structure::{ - DescNode, DocumentNode, EnumNode, ListItem, ListNode, DESC, ENUM, LIST, -}; -use crate::text::{ - LinebreakNode, ParNode, ParbreakNode, SmartQuoteNode, SpaceNode, TextNode, -}; +use crate::text::{LinebreakNode, SmartQuoteNode, SpaceNode, TextNode}; /// Root-level layout. #[capability] diff --git a/library/src/text/par.rs b/library/src/layout/par.rs similarity index 98% rename from library/src/text/par.rs rename to library/src/layout/par.rs index 3c722d84b..82bea1b5a 100644 --- a/library/src/text/par.rs +++ b/library/src/layout/par.rs @@ -4,12 +4,11 @@ use xi_unicode::LineBreakIterator; use typst::model::Key; -use super::{ - shape, Lang, LinebreakNode, Quoter, Quotes, ShapedText, SmartQuoteNode, SpaceNode, - TextNode, -}; -use crate::layout::{HNode, Spacing}; +use super::{HNode, RepeatNode, Spacing}; use crate::prelude::*; +use crate::text::{ + shape, LinebreakNode, Quoter, Quotes, ShapedText, SmartQuoteNode, SpaceNode, TextNode, +}; /// Arrange text, spacing and inline-level nodes into a paragraph. #[derive(Hash)] @@ -129,30 +128,6 @@ impl ParbreakNode { impl Unlabellable for ParbreakNode {} -/// Repeats content to fill a line. -#[derive(Debug, Hash)] -pub struct RepeatNode(pub Content); - -#[node(Layout, Inline)] -impl RepeatNode { - fn construct(_: &Vm, args: &mut Args) -> SourceResult { - Ok(Self(args.expect("body")?).pack()) - } -} - -impl Layout for RepeatNode { - fn layout( - &self, - world: Tracked, - styles: StyleChain, - regions: &Regions, - ) -> SourceResult { - self.0.layout(world, styles, regions) - } -} - -impl Inline for RepeatNode {} - /// Range of a substring of text. type Range = std::ops::Range; diff --git a/library/src/layout/repeat.rs b/library/src/layout/repeat.rs new file mode 100644 index 000000000..d9323e1df --- /dev/null +++ b/library/src/layout/repeat.rs @@ -0,0 +1,25 @@ +use crate::prelude::*; + +/// Repeats content to fill a line. +#[derive(Debug, Hash)] +pub struct RepeatNode(pub Content); + +#[node(Layout, Inline)] +impl RepeatNode { + fn construct(_: &Vm, args: &mut Args) -> SourceResult { + Ok(Self(args.expect("body")?).pack()) + } +} + +impl Layout for RepeatNode { + fn layout( + &self, + world: Tracked, + styles: StyleChain, + regions: &Regions, + ) -> SourceResult { + self.0.layout(world, styles, regions) + } +} + +impl Inline for RepeatNode {} diff --git a/library/src/layout/stack.rs b/library/src/layout/stack.rs index 7de1d34a6..c1073b261 100644 --- a/library/src/layout/stack.rs +++ b/library/src/layout/stack.rs @@ -1,8 +1,7 @@ use typst::model::StyledNode; -use super::{AlignNode, Spacing}; +use super::{AlignNode, ParNode, Spacing}; use crate::prelude::*; -use crate::text::ParNode; /// Arrange content and spacing along an axis. #[derive(Debug, Hash)] diff --git a/library/src/lib.rs b/library/src/lib.rs index cf8cb4903..e15401333 100644 --- a/library/src/lib.rs +++ b/library/src/lib.rs @@ -1,13 +1,14 @@ //! Typst's standard library. -pub mod base; -pub mod graphics; +pub mod basics; +pub mod compute; pub mod layout; pub mod math; +pub mod meta; pub mod prelude; pub mod shared; -pub mod structure; pub mod text; +pub mod visualize; use typst::geom::{Align, Color, Dir, GenAlign}; use typst::model::{LangItems, Library, Node, NodeId, Scope, StyleMap}; @@ -15,7 +16,7 @@ use typst::model::{LangItems, Library, Node, NodeId, Scope, StyleMap}; use self::layout::LayoutRoot; /// Construct the standard library. -pub fn new() -> Library { +pub fn build() -> Library { Library { scope: scope(), styles: styles(), items: items() } } @@ -23,97 +24,102 @@ pub fn new() -> Library { fn scope() -> Scope { let mut std = Scope::new(); + // Basics. + std.def_node::("heading"); + std.def_node::("list"); + std.def_node::("enum"); + std.def_node::("desc"); + std.def_node::("table"); + // Text. + std.def_node::("text"); std.def_node::("linebreak"); std.def_node::("smartquote"); - std.def_node::("text"); - std.def_node::("par"); - std.def_node::("parbreak"); std.def_node::("strong"); std.def_node::("emph"); - std.def_node::("raw"); - std.def_node::("underline"); - std.def_node::("strike"); - std.def_node::("overline"); - std.def_node::("super"); - std.def_node::("sub"); - std.def_node::("link"); - std.def_node::("repeat"); std.def_fn("lower", text::lower); std.def_fn("upper", text::upper); std.def_fn("smallcaps", text::smallcaps); - - // Structure. - std.def_node::("document"); - std.def_node::("ref"); - std.def_node::("heading"); - std.def_node::("list"); - std.def_node::("enum"); - std.def_node::("desc"); - std.def_node::("table"); - - // Layout. - std.def_node::("page"); - std.def_node::("pagebreak"); - std.def_node::("h"); - std.def_node::("v"); - std.def_node::("box"); - std.def_node::("block"); - std.def_node::("align"); - std.def_node::("pad"); - std.def_node::("stack"); - std.def_node::("grid"); - std.def_node::("columns"); - std.def_node::("colbreak"); - std.def_node::("place"); - std.def_node::("move"); - std.def_node::("scale"); - std.def_node::("rotate"); - - // Graphics. - std.def_node::("image"); - std.def_node::("line"); - std.def_node::("rect"); - std.def_node::("square"); - std.def_node::("ellipse"); - std.def_node::("circle"); - std.def_node::("hide"); + std.def_node::("sub"); + std.def_node::("super"); + std.def_node::("underline"); + std.def_node::("strike"); + std.def_node::("overline"); + std.def_node::("raw"); // Math. std.def_node::("math"); + std.def_node::("atom"); + std.def_node::("frac"); std.define("sum", "∑"); std.define("in", "∈"); std.define("arrow", "→"); std.define("NN", "ℕ"); std.define("RR", "ℝ"); - // Base. - std.def_fn("type", base::type_); - std.def_fn("repr", base::repr); - std.def_fn("assert", base::assert); - std.def_fn("eval", base::eval); - std.def_fn("int", base::int); - std.def_fn("float", base::float); - std.def_fn("luma", base::luma); - std.def_fn("rgb", base::rgb); - std.def_fn("cmyk", base::cmyk); - std.def_fn("str", base::str); - std.def_fn("lorem", base::lorem); - std.def_fn("label", base::label); - std.def_fn("regex", base::regex); - std.def_fn("range", base::range); - std.def_fn("numbering", base::numbering); - std.def_fn("abs", base::abs); - std.def_fn("min", base::min); - std.def_fn("max", base::max); - std.def_fn("even", base::even); - std.def_fn("odd", base::odd); - std.def_fn("mod", base::mod_); - std.def_fn("csv", base::csv); - std.def_fn("json", base::json); - std.def_fn("xml", base::xml); + // Layout. + std.def_node::("page"); + std.def_node::("pagebreak"); + std.def_node::("flow"); + std.def_node::("v"); + std.def_node::("par"); + std.def_node::("parbreak"); + std.def_node::("h"); + std.def_node::("box"); + std.def_node::("block"); + std.def_node::("stack"); + std.def_node::("grid"); + std.def_node::("columns"); + std.def_node::("colbreak"); + std.def_node::("place"); + std.def_node::("align"); + std.def_node::("pad"); + std.def_node::("repeat"); + std.def_node::("move"); + std.def_node::("scale"); + std.def_node::("rotate"); + std.def_node::("hide"); - // Predefined colors. + // Visualize. + std.def_node::("image"); + std.def_node::("line"); + std.def_node::("rect"); + std.def_node::("square"); + std.def_node::("ellipse"); + std.def_node::("circle"); + + // Meta. + std.def_node::("document"); + std.def_node::("ref"); + std.def_node::("link"); + + // Compute. + std.def_fn("type", compute::type_); + std.def_fn("repr", compute::repr); + std.def_fn("assert", compute::assert); + std.def_fn("eval", compute::eval); + std.def_fn("int", compute::int); + std.def_fn("float", compute::float); + std.def_fn("luma", compute::luma); + std.def_fn("rgb", compute::rgb); + std.def_fn("cmyk", compute::cmyk); + std.def_fn("str", compute::str); + std.def_fn("label", compute::label); + std.def_fn("regex", compute::regex); + std.def_fn("range", compute::range); + std.def_fn("abs", compute::abs); + std.def_fn("min", compute::min); + std.def_fn("max", compute::max); + std.def_fn("even", compute::even); + std.def_fn("odd", compute::odd); + std.def_fn("mod", compute::mod_); + std.def_fn("csv", compute::csv); + std.def_fn("json", compute::json); + std.def_fn("xml", compute::xml); + std.def_fn("lorem", compute::lorem); + std.def_fn("numbering", compute::numbering); + + // Colors. std.define("black", Color::BLACK); std.define("gray", Color::GRAY); std.define("silver", Color::SILVER); @@ -167,7 +173,7 @@ fn items() -> LangItems { text_id: NodeId::of::(), text_str: |content| Some(&content.to::()?.0), smart_quote: |double| text::SmartQuoteNode { double }.pack(), - parbreak: || text::ParbreakNode.pack(), + parbreak: || layout::ParbreakNode.pack(), strong: |body| text::StrongNode(body).pack(), emph: |body| text::EmphNode(body).pack(), raw: |text, lang, block| { @@ -177,15 +183,13 @@ fn items() -> LangItems { None => content, } }, - link: |url| text::LinkNode::from_url(url).pack(), - ref_: |target| structure::RefNode(target).pack(), - heading: |level, body| structure::HeadingNode { level, body }.pack(), - list_item: |body| structure::ListItem::List(Box::new(body)).pack(), - enum_item: |number, body| { - structure::ListItem::Enum(number, Box::new(body)).pack() - }, + link: |url| meta::LinkNode::from_url(url).pack(), + ref_: |target| meta::RefNode(target).pack(), + heading: |level, body| basics::HeadingNode { level, body }.pack(), + list_item: |body| basics::ListItem::List(Box::new(body)).pack(), + enum_item: |number, body| basics::ListItem::Enum(number, Box::new(body)).pack(), desc_item: |term, body| { - structure::ListItem::Desc(Box::new(structure::DescItem { term, body })).pack() + basics::ListItem::Desc(Box::new(basics::DescItem { term, body })).pack() }, math: |children, display| math::MathNode { children, display }.pack(), math_atom: |atom| math::AtomNode(atom).pack(), diff --git a/library/src/structure/document.rs b/library/src/meta/document.rs similarity index 96% rename from library/src/structure/document.rs rename to library/src/meta/document.rs index e52c92ad2..309e1bda7 100644 --- a/library/src/structure/document.rs +++ b/library/src/meta/document.rs @@ -1,7 +1,7 @@ use crate::layout::{LayoutRoot, PageNode}; use crate::prelude::*; -/// The root node of the model. +/// The root node that represents a full document. #[derive(Hash)] pub struct DocumentNode(pub StyleVec); diff --git a/library/src/text/link.rs b/library/src/meta/link.rs similarity index 98% rename from library/src/text/link.rs rename to library/src/meta/link.rs index 1b87def2a..44da9c5d7 100644 --- a/library/src/text/link.rs +++ b/library/src/meta/link.rs @@ -1,5 +1,5 @@ -use super::TextNode; use crate::prelude::*; +use crate::text::TextNode; /// Link text and other elements to a destination. #[derive(Debug, Hash)] diff --git a/library/src/meta/mod.rs b/library/src/meta/mod.rs new file mode 100644 index 000000000..31a69cccf --- /dev/null +++ b/library/src/meta/mod.rs @@ -0,0 +1,9 @@ +//! Interaction between document parts. + +mod document; +mod link; +mod reference; + +pub use self::document::*; +pub use self::link::*; +pub use self::reference::*; diff --git a/library/src/structure/reference.rs b/library/src/meta/reference.rs similarity index 100% rename from library/src/structure/reference.rs rename to library/src/meta/reference.rs diff --git a/library/src/structure/mod.rs b/library/src/structure/mod.rs deleted file mode 100644 index a1c27eed1..000000000 --- a/library/src/structure/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Document structuring. - -mod document; -mod heading; -mod list; -mod reference; -mod table; - -pub use self::document::*; -pub use self::heading::*; -pub use self::list::*; -pub use self::reference::*; -pub use self::table::*; diff --git a/library/src/text/deco.rs b/library/src/text/deco.rs index 33c13e904..e81b219c1 100644 --- a/library/src/text/deco.rs +++ b/library/src/text/deco.rs @@ -12,7 +12,7 @@ pub struct DecoNode(pub Content); pub type UnderlineNode = DecoNode; /// Typeset stricken-through text. -pub type StrikethroughNode = DecoNode; +pub type StrikeNode = DecoNode; /// Typeset overlined text. pub type OverlineNode = DecoNode; @@ -65,7 +65,7 @@ impl Show for DecoNode { /// /// For more details, see [`DecoNode`]. #[derive(Debug, Clone, Eq, PartialEq, Hash)] -pub(super) struct Decoration { +pub struct Decoration { pub line: DecoLine, pub stroke: PartialStroke, pub offset: Smart, diff --git a/library/src/text/misc.rs b/library/src/text/misc.rs new file mode 100644 index 000000000..15ef9a63a --- /dev/null +++ b/library/src/text/misc.rs @@ -0,0 +1,146 @@ +use super::TextNode; +use crate::prelude::*; + +/// A text space. +#[derive(Debug, Hash)] +pub struct SpaceNode; + +#[node(Unlabellable, Behave)] +impl SpaceNode { + fn construct(_: &Vm, _: &mut Args) -> SourceResult { + Ok(Self.pack()) + } +} + +impl Unlabellable for SpaceNode {} + +impl Behave for SpaceNode { + fn behaviour(&self) -> Behaviour { + Behaviour::Weak(2) + } +} + +/// A line break. +#[derive(Debug, Hash)] +pub struct LinebreakNode { + pub justify: bool, +} + +#[node(Behave)] +impl LinebreakNode { + fn construct(_: &Vm, args: &mut Args) -> SourceResult { + let justify = args.named("justify")?.unwrap_or(false); + Ok(Self { justify }.pack()) + } +} + +impl Behave for LinebreakNode { + fn behaviour(&self) -> Behaviour { + Behaviour::Destructive + } +} + +/// Strong content, rendered in boldface by default. +#[derive(Debug, Hash)] +pub struct StrongNode(pub Content); + +#[node(Show)] +impl StrongNode { + fn construct(_: &Vm, args: &mut Args) -> SourceResult { + Ok(Self(args.expect("body")?).pack()) + } + + fn field(&self, name: &str) -> Option { + match name { + "body" => Some(Value::Content(self.0.clone())), + _ => None, + } + } +} + +impl Show for StrongNode { + fn show(&self, _: Tracked, _: StyleChain) -> Content { + self.0.clone().styled(TextNode::BOLD, Toggle) + } +} + +/// Emphasized content, rendered with an italic font by default. +#[derive(Debug, Hash)] +pub struct EmphNode(pub Content); + +#[node(Show)] +impl EmphNode { + fn construct(_: &Vm, args: &mut Args) -> SourceResult { + Ok(Self(args.expect("body")?).pack()) + } + + fn field(&self, name: &str) -> Option { + match name { + "body" => Some(Value::Content(self.0.clone())), + _ => None, + } + } +} + +impl Show for EmphNode { + fn show(&self, _: Tracked, _: StyleChain) -> Content { + self.0.clone().styled(TextNode::ITALIC, Toggle) + } +} + +/// A toggle that turns on and off alternatingly if folded. +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub struct Toggle; + +impl Fold for Toggle { + type Output = bool; + + fn fold(self, outer: Self::Output) -> Self::Output { + !outer + } +} + +/// Convert a string or content to lowercase. +pub fn lower(_: &Vm, args: &mut Args) -> SourceResult { + case(Case::Lower, args) +} + +/// Convert a string or content to uppercase. +pub fn upper(_: &Vm, args: &mut Args) -> SourceResult { + case(Case::Upper, args) +} + +/// Change the case of text. +fn case(case: Case, args: &mut Args) -> SourceResult { + let Spanned { v, span } = args.expect("string or content")?; + Ok(match v { + Value::Str(v) => Value::Str(case.apply(&v).into()), + Value::Content(v) => Value::Content(v.styled(TextNode::CASE, Some(case))), + v => bail!(span, "expected string or content, found {}", v.type_name()), + }) +} + +/// A case transformation on text. +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +pub enum Case { + /// Everything is lowercased. + Lower, + /// Everything is uppercased. + Upper, +} + +impl Case { + /// Apply the case to a string. + pub fn apply(self, text: &str) -> String { + match self { + Self::Lower => text.to_lowercase(), + Self::Upper => text.to_uppercase(), + } + } +} + +/// Display text in small capitals. +pub fn smallcaps(_: &Vm, args: &mut Args) -> SourceResult { + let body: Content = args.expect("content")?; + Ok(Value::Content(body.styled(TextNode::SMALLCAPS, true))) +} diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs index 3fd30e9e9..c9298feee 100644 --- a/library/src/text/mod.rs +++ b/library/src/text/mod.rs @@ -1,16 +1,15 @@ -//! Text handling and paragraph layout. +//! Text handling. mod deco; -mod link; -mod par; +mod misc; mod quotes; mod raw; mod shaping; mod shift; pub use self::deco::*; -pub use self::link::*; -pub use self::par::*; +pub use self::misc::*; +pub use self::quotes::*; pub use self::raw::*; pub use self::shaping::*; pub use self::shift::*; @@ -21,7 +20,7 @@ use rustybuzz::Tag; use typst::font::{FontMetrics, FontStretch, FontStyle, FontWeight, VerticalFontMetric}; use typst::util::EcoString; -use self::quotes::*; +use crate::layout::ParNode; use crate::prelude::*; /// A single run of text with the same style. @@ -114,19 +113,19 @@ impl TextNode { /// Whether the font weight should be increased by 300. #[property(skip, fold)] - const BOLD: Toggle = false; + pub const BOLD: Toggle = false; /// Whether the font style should be inverted. #[property(skip, fold)] - const ITALIC: Toggle = false; + pub const ITALIC: Toggle = false; /// A case transformation that should be applied to the text. #[property(skip)] - const CASE: Option = None; + pub const CASE: Option = None; /// Whether small capital glyphs should be used. ("smcp") #[property(skip)] - const SMALLCAPS: bool = false; + pub const SMALLCAPS: bool = false; /// Decorative lines. #[property(skip, fold)] - const DECO: Decoration = vec![]; + pub const DECO: Decoration = vec![]; fn construct(_: &Vm, args: &mut Args) -> SourceResult { // The text constructor is special: It doesn't create a text node. @@ -409,161 +408,3 @@ impl Fold for FontFeatures { self } } - -/// A text space. -#[derive(Debug, Hash)] -pub struct SpaceNode; - -#[node(Unlabellable, Behave)] -impl SpaceNode { - fn construct(_: &Vm, _: &mut Args) -> SourceResult { - Ok(Self.pack()) - } -} - -impl Unlabellable for SpaceNode {} - -impl Behave for SpaceNode { - fn behaviour(&self) -> Behaviour { - Behaviour::Weak(2) - } -} - -/// A line break. -#[derive(Debug, Hash)] -pub struct LinebreakNode { - pub justify: bool, -} - -#[node(Behave)] -impl LinebreakNode { - fn construct(_: &Vm, args: &mut Args) -> SourceResult { - let justify = args.named("justify")?.unwrap_or(false); - Ok(Self { justify }.pack()) - } -} - -impl Behave for LinebreakNode { - fn behaviour(&self) -> Behaviour { - Behaviour::Destructive - } -} - -/// A smart quote. -#[derive(Debug, Hash)] -pub struct SmartQuoteNode { - pub double: bool, -} - -#[node] -impl SmartQuoteNode { - fn construct(_: &Vm, args: &mut Args) -> SourceResult { - let double = args.named("double")?.unwrap_or(true); - Ok(Self { double }.pack()) - } -} - -/// Convert a string or content to lowercase. -pub fn lower(_: &Vm, args: &mut Args) -> SourceResult { - case(Case::Lower, args) -} - -/// Convert a string or content to uppercase. -pub fn upper(_: &Vm, args: &mut Args) -> SourceResult { - case(Case::Upper, args) -} - -/// Change the case of text. -fn case(case: Case, args: &mut Args) -> SourceResult { - let Spanned { v, span } = args.expect("string or content")?; - Ok(match v { - Value::Str(v) => Value::Str(case.apply(&v).into()), - Value::Content(v) => Value::Content(v.styled(TextNode::CASE, Some(case))), - v => bail!(span, "expected string or content, found {}", v.type_name()), - }) -} - -/// A case transformation on text. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum Case { - /// Everything is uppercased. - Upper, - /// Everything is lowercased. - Lower, -} - -impl Case { - /// Apply the case to a string. - pub fn apply(self, text: &str) -> String { - match self { - Self::Upper => text.to_uppercase(), - Self::Lower => text.to_lowercase(), - } - } -} - -/// Display text in small capitals. -pub fn smallcaps(_: &Vm, args: &mut Args) -> SourceResult { - let body: Content = args.expect("content")?; - Ok(Value::Content(body.styled(TextNode::SMALLCAPS, true))) -} - -/// Strong content, rendered in boldface by default. -#[derive(Debug, Hash)] -pub struct StrongNode(pub Content); - -#[node(Show)] -impl StrongNode { - fn construct(_: &Vm, args: &mut Args) -> SourceResult { - Ok(Self(args.expect("body")?).pack()) - } - - fn field(&self, name: &str) -> Option { - match name { - "body" => Some(Value::Content(self.0.clone())), - _ => None, - } - } -} - -impl Show for StrongNode { - fn show(&self, _: Tracked, _: StyleChain) -> Content { - self.0.clone().styled(TextNode::BOLD, Toggle) - } -} - -/// Emphasized content, rendered with an italic font by default. -#[derive(Debug, Hash)] -pub struct EmphNode(pub Content); - -#[node(Show)] -impl EmphNode { - fn construct(_: &Vm, args: &mut Args) -> SourceResult { - Ok(Self(args.expect("body")?).pack()) - } - - fn field(&self, name: &str) -> Option { - match name { - "body" => Some(Value::Content(self.0.clone())), - _ => None, - } - } -} - -impl Show for EmphNode { - fn show(&self, _: Tracked, _: StyleChain) -> Content { - self.0.clone().styled(TextNode::ITALIC, Toggle) - } -} - -/// A toggle that turns on and off alternatingly if folded. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub struct Toggle; - -impl Fold for Toggle { - type Output = bool; - - fn fold(self, outer: Self::Output) -> Self::Output { - !outer - } -} diff --git a/library/src/text/quotes.rs b/library/src/text/quotes.rs index 87a965af1..95cf1ad9b 100644 --- a/library/src/text/quotes.rs +++ b/library/src/text/quotes.rs @@ -1,10 +1,24 @@ use typst::syntax::is_newline; -use super::{Lang, Region}; +use crate::prelude::*; + +/// A smart quote. +#[derive(Debug, Hash)] +pub struct SmartQuoteNode { + pub double: bool, +} + +#[node] +impl SmartQuoteNode { + fn construct(_: &Vm, args: &mut Args) -> SourceResult { + let double = args.named("double")?.unwrap_or(true); + Ok(Self { double }.pack()) + } +} /// State machine for smart quote subtitution. #[derive(Debug, Clone)] -pub(super) struct Quoter { +pub struct Quoter { /// How many quotes have been opened. quote_depth: usize, /// Whether an opening quote might follow. @@ -68,7 +82,7 @@ fn is_opening_bracket(c: char) -> bool { } /// Decides which quotes to subtitute smart quotes with. -pub(super) struct Quotes<'s> { +pub struct Quotes<'s> { /// The opening single quote. pub single_open: &'s str, /// The closing single quote. diff --git a/library/src/text/shaping.rs b/library/src/text/shaping.rs index 6ce4d671e..687f2a870 100644 --- a/library/src/text/shaping.rs +++ b/library/src/text/shaping.rs @@ -6,6 +6,7 @@ use typst::font::{Font, FontVariant}; use typst::util::SliceExt; use super::*; +use crate::meta::LinkNode; use crate::prelude::*; /// The result of shaping text. @@ -13,7 +14,7 @@ use crate::prelude::*; /// This type contains owned or borrowed shaped text runs, which can be /// measured, used to reshape substrings more quickly and converted into a /// frame. -pub(super) struct ShapedText<'a> { +pub struct ShapedText<'a> { /// The text that was shaped. pub text: &'a str, /// The text direction. @@ -32,7 +33,7 @@ pub(super) struct ShapedText<'a> { /// A single glyph resulting from shaping. #[derive(Debug, Clone)] -pub(super) struct ShapedGlyph { +pub struct ShapedGlyph { /// The font the glyph is contained in. pub font: Font, /// The glyph's index in the font. @@ -314,7 +315,7 @@ struct ShapingContext<'a> { } /// Shape text into [`ShapedText`]. -pub(super) fn shape<'a>( +pub fn shape<'a>( world: Tracked, text: &'a str, styles: StyleChain<'a>, diff --git a/library/src/graphics/image.rs b/library/src/visualize/image.rs similarity index 99% rename from library/src/graphics/image.rs rename to library/src/visualize/image.rs index 2c58496cc..6e8b6147f 100644 --- a/library/src/graphics/image.rs +++ b/library/src/visualize/image.rs @@ -2,8 +2,8 @@ use std::ffi::OsStr; use typst::image::{Image, ImageFormat, RasterFormat, VectorFormat}; +use crate::meta::LinkNode; use crate::prelude::*; -use crate::text::LinkNode; /// Show a raster or vector graphic. #[derive(Debug, Hash)] diff --git a/library/src/graphics/line.rs b/library/src/visualize/line.rs similarity index 100% rename from library/src/graphics/line.rs rename to library/src/visualize/line.rs diff --git a/library/src/graphics/mod.rs b/library/src/visualize/mod.rs similarity index 60% rename from library/src/graphics/mod.rs rename to library/src/visualize/mod.rs index d77dfe360..1c87eeb32 100644 --- a/library/src/graphics/mod.rs +++ b/library/src/visualize/mod.rs @@ -1,11 +1,9 @@ -//! Graphical elements and effects. +//! Drawing and visualization. -mod hide; mod image; mod line; mod shape; -pub use self::hide::*; pub use self::image::*; pub use self::line::*; pub use self::shape::*; diff --git a/library/src/graphics/shape.rs b/library/src/visualize/shape.rs similarity index 99% rename from library/src/graphics/shape.rs rename to library/src/visualize/shape.rs index 114182e5f..daecd580b 100644 --- a/library/src/graphics/shape.rs +++ b/library/src/visualize/shape.rs @@ -1,7 +1,7 @@ use std::f64::consts::SQRT_2; +use crate::meta::LinkNode; use crate::prelude::*; -use crate::text::LinkNode; /// A sizable and fillable shape with optional content. #[derive(Debug, Hash)] diff --git a/src/model/mod.rs b/src/model/mod.rs index 6943217b7..fa0477464 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1,4 +1,4 @@ -//! Document and computation model. +//! Content and computation model. #[macro_use] mod library; diff --git a/tests/README.md b/tests/README.md index 7ad0535cb..5356cf657 100644 --- a/tests/README.md +++ b/tests/README.md @@ -3,7 +3,9 @@ ## Directory structure Top level directory structure: - `src`: Testing code. -- `typ`: Input files. +- `typ`: Input files. The tests in `compiler` specifically test the compiler + while the others test the standard library (but also the compiler + indirectly). - `ref`: Reference images which the output is compared with to determine whether a test passed or failed. - `png`: PNG files produced by tests. diff --git a/tests/ref/base/blind.png b/tests/ref/base/blind.png deleted file mode 100644 index e972567e0..000000000 Binary files a/tests/ref/base/blind.png and /dev/null differ diff --git a/tests/ref/base/color.png b/tests/ref/base/color.png deleted file mode 100644 index 496013bb7..000000000 Binary files a/tests/ref/base/color.png and /dev/null differ diff --git a/tests/ref/base/data.png b/tests/ref/base/data.png deleted file mode 100644 index 69e0ae38d..000000000 Binary files a/tests/ref/base/data.png and /dev/null differ diff --git a/tests/ref/base/eval.png b/tests/ref/base/eval.png deleted file mode 100644 index 38c1d64eb..000000000 Binary files a/tests/ref/base/eval.png and /dev/null differ diff --git a/tests/ref/base/numbering.png b/tests/ref/base/numbering.png deleted file mode 100644 index aa34de296..000000000 Binary files a/tests/ref/base/numbering.png and /dev/null differ diff --git a/tests/ref/basics/desc.png b/tests/ref/basics/desc.png new file mode 100644 index 000000000..e186ec8c8 Binary files /dev/null and b/tests/ref/basics/desc.png differ diff --git a/tests/ref/basics/enum.png b/tests/ref/basics/enum.png new file mode 100644 index 000000000..0c9c94878 Binary files /dev/null and b/tests/ref/basics/enum.png differ diff --git a/tests/ref/structure/heading.png b/tests/ref/basics/heading.png similarity index 100% rename from tests/ref/structure/heading.png rename to tests/ref/basics/heading.png diff --git a/tests/ref/structure/attach.png b/tests/ref/basics/list-attach.png similarity index 100% rename from tests/ref/structure/attach.png rename to tests/ref/basics/list-attach.png diff --git a/tests/ref/structure/list.png b/tests/ref/basics/list.png similarity index 100% rename from tests/ref/structure/list.png rename to tests/ref/basics/list.png diff --git a/tests/ref/structure/table.png b/tests/ref/basics/table.png similarity index 100% rename from tests/ref/structure/table.png rename to tests/ref/basics/table.png diff --git a/tests/ref/code/block.png b/tests/ref/code/block.png deleted file mode 100644 index 9cd0ba36f..000000000 Binary files a/tests/ref/code/block.png and /dev/null differ diff --git a/tests/ref/code/if.png b/tests/ref/code/if.png deleted file mode 100644 index 177e61bdf..000000000 Binary files a/tests/ref/code/if.png and /dev/null differ diff --git a/tests/ref/code/import.png b/tests/ref/code/import.png deleted file mode 100644 index 00d3b2ee8..000000000 Binary files a/tests/ref/code/import.png and /dev/null differ diff --git a/tests/ref/code/include.png b/tests/ref/code/include.png deleted file mode 100644 index d3d660328..000000000 Binary files a/tests/ref/code/include.png and /dev/null differ diff --git a/tests/ref/code/let.png b/tests/ref/code/let.png deleted file mode 100644 index 07afcb96e..000000000 Binary files a/tests/ref/code/let.png and /dev/null differ diff --git a/tests/ref/code/ops.png b/tests/ref/code/ops.png deleted file mode 100644 index abcab1376..000000000 Binary files a/tests/ref/code/ops.png and /dev/null differ diff --git a/tests/ref/code/return.png b/tests/ref/code/return.png deleted file mode 100644 index 504108872..000000000 Binary files a/tests/ref/code/return.png and /dev/null differ diff --git a/tests/ref/code/while.png b/tests/ref/code/while.png deleted file mode 100644 index 026f99436..000000000 Binary files a/tests/ref/code/while.png and /dev/null differ diff --git a/tests/ref/coma.png b/tests/ref/coma.png index 62edb5e08..8bfbc203b 100644 Binary files a/tests/ref/coma.png and b/tests/ref/coma.png differ diff --git a/tests/ref/code/array.png b/tests/ref/compiler/array.png similarity index 100% rename from tests/ref/code/array.png rename to tests/ref/compiler/array.png diff --git a/tests/ref/compiler/bench.png b/tests/ref/compiler/bench.png new file mode 100644 index 000000000..cadc0914b Binary files /dev/null and b/tests/ref/compiler/bench.png differ diff --git a/tests/ref/compiler/block.png b/tests/ref/compiler/block.png new file mode 100644 index 000000000..c5782da5d Binary files /dev/null and b/tests/ref/compiler/block.png differ diff --git a/tests/ref/code/break-continue.png b/tests/ref/compiler/break-continue.png similarity index 100% rename from tests/ref/code/break-continue.png rename to tests/ref/compiler/break-continue.png diff --git a/tests/ref/code/call.png b/tests/ref/compiler/call.png similarity index 100% rename from tests/ref/code/call.png rename to tests/ref/compiler/call.png diff --git a/tests/ref/code/closure.png b/tests/ref/compiler/closure.png similarity index 100% rename from tests/ref/code/closure.png rename to tests/ref/compiler/closure.png diff --git a/tests/ref/code/comment.png b/tests/ref/compiler/comment.png similarity index 100% rename from tests/ref/code/comment.png rename to tests/ref/compiler/comment.png diff --git a/tests/ref/style/construct.png b/tests/ref/compiler/construct.png similarity index 100% rename from tests/ref/style/construct.png rename to tests/ref/compiler/construct.png diff --git a/tests/ref/code/dict.png b/tests/ref/compiler/dict.png similarity index 100% rename from tests/ref/code/dict.png rename to tests/ref/compiler/dict.png diff --git a/tests/ref/code/for.png b/tests/ref/compiler/for.png similarity index 95% rename from tests/ref/code/for.png rename to tests/ref/compiler/for.png index 60c505ec0..8c08ab041 100644 Binary files a/tests/ref/code/for.png and b/tests/ref/compiler/for.png differ diff --git a/tests/ref/compiler/if.png b/tests/ref/compiler/if.png new file mode 100644 index 000000000..cca9a5702 Binary files /dev/null and b/tests/ref/compiler/if.png differ diff --git a/tests/ref/compiler/import.png b/tests/ref/compiler/import.png new file mode 100644 index 000000000..dddbe408e Binary files /dev/null and b/tests/ref/compiler/import.png differ diff --git a/tests/ref/compiler/include.png b/tests/ref/compiler/include.png new file mode 100644 index 000000000..09ff7498b Binary files /dev/null and b/tests/ref/compiler/include.png differ diff --git a/tests/ref/style/label.png b/tests/ref/compiler/label.png similarity index 100% rename from tests/ref/style/label.png rename to tests/ref/compiler/label.png diff --git a/tests/ref/compiler/let.png b/tests/ref/compiler/let.png new file mode 100644 index 000000000..7a45eca1f Binary files /dev/null and b/tests/ref/compiler/let.png differ diff --git a/tests/ref/base/collection.png b/tests/ref/compiler/methods-collection.png similarity index 100% rename from tests/ref/base/collection.png rename to tests/ref/compiler/methods-collection.png diff --git a/tests/ref/compiler/methods-color.png b/tests/ref/compiler/methods-color.png new file mode 100644 index 000000000..9b65c16d3 Binary files /dev/null and b/tests/ref/compiler/methods-color.png differ diff --git a/tests/ref/compiler/ops.png b/tests/ref/compiler/ops.png new file mode 100644 index 000000000..ef6ffb4ae Binary files /dev/null and b/tests/ref/compiler/ops.png differ diff --git a/tests/ref/code/repr.png b/tests/ref/compiler/repr.png similarity index 100% rename from tests/ref/code/repr.png rename to tests/ref/compiler/repr.png diff --git a/tests/ref/compiler/return.png b/tests/ref/compiler/return.png new file mode 100644 index 000000000..6d558e622 Binary files /dev/null and b/tests/ref/compiler/return.png differ diff --git a/tests/ref/style/set.png b/tests/ref/compiler/set.png similarity index 100% rename from tests/ref/style/set.png rename to tests/ref/compiler/set.png diff --git a/tests/ref/text/shorthands.png b/tests/ref/compiler/shorthand.png similarity index 100% rename from tests/ref/text/shorthands.png rename to tests/ref/compiler/shorthand.png diff --git a/tests/ref/style/show-bare.png b/tests/ref/compiler/show-bare.png similarity index 100% rename from tests/ref/style/show-bare.png rename to tests/ref/compiler/show-bare.png diff --git a/tests/ref/style/show-node.png b/tests/ref/compiler/show-node.png similarity index 100% rename from tests/ref/style/show-node.png rename to tests/ref/compiler/show-node.png diff --git a/tests/ref/style/show-recursive.png b/tests/ref/compiler/show-recursive.png similarity index 100% rename from tests/ref/style/show-recursive.png rename to tests/ref/compiler/show-recursive.png diff --git a/tests/ref/style/show-selector.png b/tests/ref/compiler/show-selector.png similarity index 100% rename from tests/ref/style/show-selector.png rename to tests/ref/compiler/show-selector.png diff --git a/tests/ref/style/show-text.png b/tests/ref/compiler/show-text.png similarity index 100% rename from tests/ref/style/show-text.png rename to tests/ref/compiler/show-text.png diff --git a/tests/ref/compiler/while.png b/tests/ref/compiler/while.png new file mode 100644 index 000000000..236be4261 Binary files /dev/null and b/tests/ref/compiler/while.png differ diff --git a/tests/ref/compute/create.png b/tests/ref/compute/create.png new file mode 100644 index 000000000..600e61741 Binary files /dev/null and b/tests/ref/compute/create.png differ diff --git a/tests/ref/compute/data.png b/tests/ref/compute/data.png new file mode 100644 index 000000000..678a1fd10 Binary files /dev/null and b/tests/ref/compute/data.png differ diff --git a/tests/ref/compute/utility.png b/tests/ref/compute/utility.png new file mode 100644 index 000000000..035ce431d Binary files /dev/null and b/tests/ref/compute/utility.png differ diff --git a/tests/ref/empty.png b/tests/ref/empty.png index 87c06b0a8..db3a66950 100644 Binary files a/tests/ref/empty.png and b/tests/ref/empty.png differ diff --git a/tests/ref/graphics/hide.png b/tests/ref/graphics/hide.png deleted file mode 100644 index 8a60cf904..000000000 Binary files a/tests/ref/graphics/hide.png and /dev/null differ diff --git a/tests/ref/graphics/shape-circle.png b/tests/ref/graphics/shape-circle.png deleted file mode 100644 index 040c6f0b2..000000000 Binary files a/tests/ref/graphics/shape-circle.png and /dev/null differ diff --git a/tests/ref/graphics/shape-ellipse.png b/tests/ref/graphics/shape-ellipse.png deleted file mode 100644 index 296fc14ee..000000000 Binary files a/tests/ref/graphics/shape-ellipse.png and /dev/null differ diff --git a/tests/ref/graphics/shape-fill-stroke.png b/tests/ref/graphics/shape-fill-stroke.png deleted file mode 100644 index 91cddcc2e..000000000 Binary files a/tests/ref/graphics/shape-fill-stroke.png and /dev/null differ diff --git a/tests/ref/graphics/shape-rect.png b/tests/ref/graphics/shape-rect.png deleted file mode 100644 index e2ea05029..000000000 Binary files a/tests/ref/graphics/shape-rect.png and /dev/null differ diff --git a/tests/ref/graphics/shape-square.png b/tests/ref/graphics/shape-square.png deleted file mode 100644 index 00a0c8488..000000000 Binary files a/tests/ref/graphics/shape-square.png and /dev/null differ diff --git a/tests/ref/layout/columns.png b/tests/ref/layout/columns.png index 6f2105100..df7b7084b 100644 Binary files a/tests/ref/layout/columns.png and b/tests/ref/layout/columns.png differ diff --git a/tests/ref/layout/container.png b/tests/ref/layout/container.png index 87484c250..f82df1086 100644 Binary files a/tests/ref/layout/container.png and b/tests/ref/layout/container.png differ diff --git a/tests/ref/layout/flow-orphan.png b/tests/ref/layout/flow-orphan.png new file mode 100644 index 000000000..1e5fade4c Binary files /dev/null and b/tests/ref/layout/flow-orphan.png differ diff --git a/tests/ref/layout/grid-1.png b/tests/ref/layout/grid-1.png index 2c57e28c7..99a97bb72 100644 Binary files a/tests/ref/layout/grid-1.png and b/tests/ref/layout/grid-1.png differ diff --git a/tests/ref/layout/grid-2.png b/tests/ref/layout/grid-2.png index 649867972..8bc22660b 100644 Binary files a/tests/ref/layout/grid-2.png and b/tests/ref/layout/grid-2.png differ diff --git a/tests/ref/layout/grid-4.png b/tests/ref/layout/grid-4.png index c78eb7210..2bbc84cc7 100644 Binary files a/tests/ref/layout/grid-4.png and b/tests/ref/layout/grid-4.png differ diff --git a/tests/ref/layout/grid-5.png b/tests/ref/layout/grid-5.png index 8afe9446f..532700b1f 100644 Binary files a/tests/ref/layout/grid-5.png and b/tests/ref/layout/grid-5.png differ diff --git a/tests/ref/layout/hide.png b/tests/ref/layout/hide.png new file mode 100644 index 000000000..6450d6695 Binary files /dev/null and b/tests/ref/layout/hide.png differ diff --git a/tests/ref/layout/locate-break.png b/tests/ref/layout/locate-break.png deleted file mode 100644 index 25abb4a09..000000000 Binary files a/tests/ref/layout/locate-break.png and /dev/null differ diff --git a/tests/ref/layout/locate-group.png b/tests/ref/layout/locate-group.png deleted file mode 100644 index c9fe40657..000000000 Binary files a/tests/ref/layout/locate-group.png and /dev/null differ diff --git a/tests/ref/layout/locate.png b/tests/ref/layout/locate.png deleted file mode 100644 index 015c5a6dd..000000000 Binary files a/tests/ref/layout/locate.png and /dev/null differ diff --git a/tests/ref/layout/orphan-heading.png b/tests/ref/layout/orphan-heading.png deleted file mode 100644 index aa5a78385..000000000 Binary files a/tests/ref/layout/orphan-heading.png and /dev/null differ diff --git a/tests/ref/layout/orphan-widow.png b/tests/ref/layout/orphan-widow.png deleted file mode 100644 index 8fc523a6e..000000000 Binary files a/tests/ref/layout/orphan-widow.png and /dev/null differ diff --git a/tests/ref/layout/page-margin.png b/tests/ref/layout/page-margin.png index 211f881c2..6952189bd 100644 Binary files a/tests/ref/layout/page-margin.png and b/tests/ref/layout/page-margin.png differ diff --git a/tests/ref/layout/page-style.png b/tests/ref/layout/page-style.png index 7132d20ba..ac6b602c1 100644 Binary files a/tests/ref/layout/page-style.png and b/tests/ref/layout/page-style.png differ diff --git a/tests/ref/layout/page.png b/tests/ref/layout/page.png index 35716e4de..4168d201b 100644 Binary files a/tests/ref/layout/page.png and b/tests/ref/layout/page.png differ diff --git a/tests/ref/text/bidi.png b/tests/ref/layout/par-bidi.png similarity index 100% rename from tests/ref/text/bidi.png rename to tests/ref/layout/par-bidi.png diff --git a/tests/ref/layout/par-indent.png b/tests/ref/layout/par-indent.png new file mode 100644 index 000000000..7a0bd4b64 Binary files /dev/null and b/tests/ref/layout/par-indent.png differ diff --git a/tests/ref/text/justify.png b/tests/ref/layout/par-justify.png similarity index 100% rename from tests/ref/text/justify.png rename to tests/ref/layout/par-justify.png diff --git a/tests/ref/layout/par-knuth.png b/tests/ref/layout/par-knuth.png new file mode 100644 index 000000000..fca0892e7 Binary files /dev/null and b/tests/ref/layout/par-knuth.png differ diff --git a/tests/ref/layout/par-simple.png b/tests/ref/layout/par-simple.png new file mode 100644 index 000000000..92f98b363 Binary files /dev/null and b/tests/ref/layout/par-simple.png differ diff --git a/tests/ref/text/par.png b/tests/ref/layout/par.png similarity index 100% rename from tests/ref/text/par.png rename to tests/ref/layout/par.png diff --git a/tests/ref/layout/repeat.png b/tests/ref/layout/repeat.png new file mode 100644 index 000000000..fcd52987c Binary files /dev/null and b/tests/ref/layout/repeat.png differ diff --git a/tests/ref/layout/stack-2.png b/tests/ref/layout/stack-2.png index 52b75bbda..af58d9c4f 100644 Binary files a/tests/ref/layout/stack-2.png and b/tests/ref/layout/stack-2.png differ diff --git a/tests/ref/graphics/transform.png b/tests/ref/layout/transform.png similarity index 100% rename from tests/ref/graphics/transform.png rename to tests/ref/layout/transform.png diff --git a/tests/ref/layout/math.png b/tests/ref/math/simple.png similarity index 100% rename from tests/ref/layout/math.png rename to tests/ref/math/simple.png diff --git a/tests/ref/meta/document.png b/tests/ref/meta/document.png new file mode 100644 index 000000000..bc0a95bfa Binary files /dev/null and b/tests/ref/meta/document.png differ diff --git a/tests/ref/meta/link.png b/tests/ref/meta/link.png new file mode 100644 index 000000000..604e09d0a Binary files /dev/null and b/tests/ref/meta/link.png differ diff --git a/tests/ref/structure/desc.png b/tests/ref/structure/desc.png deleted file mode 100644 index e8b1d151a..000000000 Binary files a/tests/ref/structure/desc.png and /dev/null differ diff --git a/tests/ref/structure/enum.png b/tests/ref/structure/enum.png deleted file mode 100644 index 39227b5b4..000000000 Binary files a/tests/ref/structure/enum.png and /dev/null differ diff --git a/tests/ref/style/closure.png b/tests/ref/style/closure.png deleted file mode 100644 index 77d88d0c2..000000000 Binary files a/tests/ref/style/closure.png and /dev/null differ diff --git a/tests/ref/text/baseline.png b/tests/ref/text/baseline.png index 37bb19499..f011c8c41 100644 Binary files a/tests/ref/text/baseline.png and b/tests/ref/text/baseline.png differ diff --git a/tests/ref/text/chinese.png b/tests/ref/text/chinese.png index aa8801c0d..89ee357b4 100644 Binary files a/tests/ref/text/chinese.png and b/tests/ref/text/chinese.png differ diff --git a/tests/ref/text/emph-strong.png b/tests/ref/text/emph-strong.png deleted file mode 100644 index cce98812c..000000000 Binary files a/tests/ref/text/emph-strong.png and /dev/null differ diff --git a/tests/ref/text/emphasis.png b/tests/ref/text/emphasis.png new file mode 100644 index 000000000..c004421df Binary files /dev/null and b/tests/ref/text/emphasis.png differ diff --git a/tests/ref/text/features.png b/tests/ref/text/features.png index 36609d89f..1c3b030c0 100644 Binary files a/tests/ref/text/features.png and b/tests/ref/text/features.png differ diff --git a/tests/ref/text/hyphenate.png b/tests/ref/text/hyphenate.png index 47a8ffa54..e304cb8c8 100644 Binary files a/tests/ref/text/hyphenate.png and b/tests/ref/text/hyphenate.png differ diff --git a/tests/ref/text/indent.png b/tests/ref/text/indent.png deleted file mode 100644 index 9cf2ace5a..000000000 Binary files a/tests/ref/text/indent.png and /dev/null differ diff --git a/tests/ref/text/knuth.png b/tests/ref/text/knuth.png deleted file mode 100644 index 8595fe291..000000000 Binary files a/tests/ref/text/knuth.png and /dev/null differ diff --git a/tests/ref/text/link.png b/tests/ref/text/link.png deleted file mode 100644 index 9d5cb0547..000000000 Binary files a/tests/ref/text/link.png and /dev/null differ diff --git a/tests/ref/text/microtype.png b/tests/ref/text/microtype.png index 7edc61ccb..e0d149e60 100644 Binary files a/tests/ref/text/microtype.png and b/tests/ref/text/microtype.png differ diff --git a/tests/ref/text/plain.png b/tests/ref/text/plain.png deleted file mode 100644 index bfdf47a26..000000000 Binary files a/tests/ref/text/plain.png and /dev/null differ diff --git a/tests/ref/text/quotes.png b/tests/ref/text/quotes.png index 058055aec..1054daca9 100644 Binary files a/tests/ref/text/quotes.png and b/tests/ref/text/quotes.png differ diff --git a/tests/ref/text/code.png b/tests/ref/text/raw-highlight.png similarity index 100% rename from tests/ref/text/code.png rename to tests/ref/text/raw-highlight.png diff --git a/tests/ref/text/raw.png b/tests/ref/text/raw.png index 3a7691fd7..f7912051d 100644 Binary files a/tests/ref/text/raw.png and b/tests/ref/text/raw.png differ diff --git a/tests/ref/text/repeat.png b/tests/ref/text/repeat.png deleted file mode 100644 index d7786befa..000000000 Binary files a/tests/ref/text/repeat.png and /dev/null differ diff --git a/tests/ref/text/shifts.png b/tests/ref/text/shift.png similarity index 100% rename from tests/ref/text/shifts.png rename to tests/ref/text/shift.png diff --git a/tests/ref/text/space.png b/tests/ref/text/space.png new file mode 100644 index 000000000..09efda70e Binary files /dev/null and b/tests/ref/text/space.png differ diff --git a/tests/ref/text/tracking-spacing.png b/tests/ref/text/tracking-spacing.png index 69fc1eefd..2ce0d5495 100644 Binary files a/tests/ref/text/tracking-spacing.png and b/tests/ref/text/tracking-spacing.png differ diff --git a/tests/ref/text/whitespace.png b/tests/ref/text/whitespace.png deleted file mode 100644 index 9a1ed3cda..000000000 Binary files a/tests/ref/text/whitespace.png and /dev/null differ diff --git a/tests/ref/graphics/image.png b/tests/ref/visualize/image.png similarity index 100% rename from tests/ref/graphics/image.png rename to tests/ref/visualize/image.png diff --git a/tests/ref/graphics/line.png b/tests/ref/visualize/line.png similarity index 100% rename from tests/ref/graphics/line.png rename to tests/ref/visualize/line.png diff --git a/tests/ref/graphics/shape-aspect.png b/tests/ref/visualize/shape-aspect.png similarity index 100% rename from tests/ref/graphics/shape-aspect.png rename to tests/ref/visualize/shape-aspect.png diff --git a/tests/ref/visualize/shape-circle.png b/tests/ref/visualize/shape-circle.png new file mode 100644 index 000000000..6cbbc0e33 Binary files /dev/null and b/tests/ref/visualize/shape-circle.png differ diff --git a/tests/ref/visualize/shape-ellipse.png b/tests/ref/visualize/shape-ellipse.png new file mode 100644 index 000000000..50467dce6 Binary files /dev/null and b/tests/ref/visualize/shape-ellipse.png differ diff --git a/tests/ref/visualize/shape-fill-stroke.png b/tests/ref/visualize/shape-fill-stroke.png new file mode 100644 index 000000000..b8c78a55a Binary files /dev/null and b/tests/ref/visualize/shape-fill-stroke.png differ diff --git a/tests/ref/visualize/shape-rect.png b/tests/ref/visualize/shape-rect.png new file mode 100644 index 000000000..b3311ba58 Binary files /dev/null and b/tests/ref/visualize/shape-rect.png differ diff --git a/tests/ref/visualize/shape-square.png b/tests/ref/visualize/shape-square.png new file mode 100644 index 000000000..1f5303b9c Binary files /dev/null and b/tests/ref/visualize/shape-square.png differ diff --git a/tests/src/benches.rs b/tests/src/benches.rs index 1ae012eb5..4cd7d9c33 100644 --- a/tests/src/benches.rs +++ b/tests/src/benches.rs @@ -10,7 +10,7 @@ use typst::util::Buffer; use typst::World; use unscanny::Scanner; -const TEXT: &str = include_str!("../typ/benches/bench.typ"); +const TEXT: &str = include_str!("../typ/compiler/bench.typ"); const FONT: &[u8] = include_bytes!("../fonts/IBMPlexSans-Regular.ttf"); main!( @@ -111,7 +111,7 @@ impl BenchWorld { let book = FontBook::from_fonts([&font]); Self { - library: Prehashed::new(typst_library::new()), + library: Prehashed::new(typst_library::build()), book: Prehashed::new(book), font, source: Source::detached(TEXT), diff --git a/tests/src/tests.rs b/tests/src/tests.rs index 215d7fe75..e7c630f6a 100644 --- a/tests/src/tests.rs +++ b/tests/src/tests.rs @@ -145,7 +145,7 @@ impl Args { } fn library() -> Library { - let mut lib = typst_library::new(); + let mut lib = typst_library::build(); // Set page width to 120pt with 10pt margins, so that the inner page is // exactly 100pt wide. Page height is unbounded and font size is 10pt so diff --git a/tests/typ/base/assert.typ b/tests/typ/base/assert.typ deleted file mode 100644 index b0c8aafd4..000000000 --- a/tests/typ/base/assert.typ +++ /dev/null @@ -1,23 +0,0 @@ -// Test the `assert` function. -// Ref: false - ---- -#assert(1 + 1 == 2) -#assert(range(2, 5) == (2, 3, 4)) -#assert(not false) - ---- -// Test failing assertions. -// Error: 9-15 assertion failed -#assert(1 == 2) - ---- -// Test failing assertions. -// Error: 9-15 expected boolean, found string -#assert("true") - ---- -// Test the `type` function. -#test(type(1), "integer") -#test(type(ltr), "direction") -#test(type(10 / 3), "float") diff --git a/tests/typ/base/numbering.typ b/tests/typ/base/numbering.typ deleted file mode 100644 index 200850bcd..000000000 --- a/tests/typ/base/numbering.typ +++ /dev/null @@ -1,13 +0,0 @@ -// Test integrated numbering patterns. - ---- -#for i in range(9) { - numbering(i, "* and ") - numbering(i, "I") - [ for #i] - parbreak() -} - ---- -// Error: 12-14 must be at least zero -#numbering(-1, "1") diff --git a/tests/typ/base/type.typ b/tests/typ/base/type.typ deleted file mode 100644 index 37cf86239..000000000 --- a/tests/typ/base/type.typ +++ /dev/null @@ -1,7 +0,0 @@ -// Test the `type` function. -// Ref: false - ---- -#test(type(1), "integer") -#test(type(ltr), "direction") -#test(type(10 / 3), "float") diff --git a/tests/typ/structure/desc.typ b/tests/typ/basics/desc.typ similarity index 100% rename from tests/typ/structure/desc.typ rename to tests/typ/basics/desc.typ diff --git a/tests/typ/structure/enum.typ b/tests/typ/basics/enum.typ similarity index 100% rename from tests/typ/structure/enum.typ rename to tests/typ/basics/enum.typ diff --git a/tests/typ/structure/heading.typ b/tests/typ/basics/heading.typ similarity index 100% rename from tests/typ/structure/heading.typ rename to tests/typ/basics/heading.typ diff --git a/tests/typ/structure/attach.typ b/tests/typ/basics/list-attach.typ similarity index 100% rename from tests/typ/structure/attach.typ rename to tests/typ/basics/list-attach.typ diff --git a/tests/typ/structure/list.typ b/tests/typ/basics/list.typ similarity index 100% rename from tests/typ/structure/list.typ rename to tests/typ/basics/list.typ diff --git a/tests/typ/structure/table.typ b/tests/typ/basics/table.typ similarity index 100% rename from tests/typ/structure/table.typ rename to tests/typ/basics/table.typ diff --git a/tests/typ/code/array.typ b/tests/typ/compiler/array.typ similarity index 100% rename from tests/typ/code/array.typ rename to tests/typ/compiler/array.typ diff --git a/tests/typ/benches/bench.typ b/tests/typ/compiler/bench.typ similarity index 100% rename from tests/typ/benches/bench.typ rename to tests/typ/compiler/bench.typ diff --git a/tests/typ/code/block.typ b/tests/typ/compiler/block.typ similarity index 98% rename from tests/typ/code/block.typ rename to tests/typ/compiler/block.typ index d82d497f9..45f63f8e5 100644 --- a/tests/typ/code/block.typ +++ b/tests/typ/compiler/block.typ @@ -79,7 +79,7 @@ --- // Double block creates a scope. {{ - import b from "target.typ" + import b from "module.typ" test(b, 1) }} diff --git a/tests/typ/code/break-continue.typ b/tests/typ/compiler/break-continue.typ similarity index 100% rename from tests/typ/code/break-continue.typ rename to tests/typ/compiler/break-continue.typ diff --git a/tests/typ/code/call.typ b/tests/typ/compiler/call.typ similarity index 100% rename from tests/typ/code/call.typ rename to tests/typ/compiler/call.typ diff --git a/tests/typ/code/closure.typ b/tests/typ/compiler/closure.typ similarity index 99% rename from tests/typ/code/closure.typ rename to tests/typ/compiler/closure.typ index e9389e131..2c6c1ea08 100644 --- a/tests/typ/code/closure.typ +++ b/tests/typ/compiler/closure.typ @@ -60,7 +60,7 @@ --- // Import bindings. { - let b = "target.typ" + let b = "module.typ" let f() = { import b from b b diff --git a/tests/typ/code/comment.typ b/tests/typ/compiler/comment.typ similarity index 100% rename from tests/typ/code/comment.typ rename to tests/typ/compiler/comment.typ diff --git a/tests/typ/style/construct.typ b/tests/typ/compiler/construct.typ similarity index 100% rename from tests/typ/style/construct.typ rename to tests/typ/compiler/construct.typ diff --git a/tests/typ/code/dict.typ b/tests/typ/compiler/dict.typ similarity index 100% rename from tests/typ/code/dict.typ rename to tests/typ/compiler/dict.typ diff --git a/tests/typ/code/field.typ b/tests/typ/compiler/field.typ similarity index 100% rename from tests/typ/code/field.typ rename to tests/typ/compiler/field.typ diff --git a/tests/typ/code/for.typ b/tests/typ/compiler/for.typ similarity index 100% rename from tests/typ/code/for.typ rename to tests/typ/compiler/for.typ diff --git a/tests/typ/code/if.typ b/tests/typ/compiler/if.typ similarity index 100% rename from tests/typ/code/if.typ rename to tests/typ/compiler/if.typ diff --git a/tests/typ/code/import.typ b/tests/typ/compiler/import.typ similarity index 74% rename from tests/typ/code/import.typ rename to tests/typ/compiler/import.typ index 5291af395..0620403dd 100644 --- a/tests/typ/code/import.typ +++ b/tests/typ/compiler/import.typ @@ -4,45 +4,45 @@ // Test importing semantics. // A named import. -#import item from "target.typ" +#import item from "module.typ" #test(item(1, 2), 3) // Test that this will be overwritten. #let value = [foo] // Import multiple things. -#import fn, value from "target.typ" +#import fn, value from "module.typ" #fn[Like and Subscribe!] #value // Code mode { - import b from "target.typ" + import b from "module.typ" test(b, 1) } // A wildcard import. -#import * from "target.typ" +#import * from "module.typ" // It exists now! #d // Who needs whitespace anyways? -#import*from"target.typ" +#import*from"module.typ" // Should output `bye`. // Stop at semicolon. -#import a, c from "target.typ";bye +#import a, c from "module.typ";bye // Allow the trailing comma. -#import a, c, from "target.typ" +#import a, c, from "module.typ" --- // Error: 19-21 failed to load file (is a directory) #import name from "" --- -// Error: 16-27 file not found (searched at typ/code/lib/0.2.1) +// Error: 16-27 file not found (searched at typ/compiler/lib/0.2.1) #import * from "lib/0.2.1" --- @@ -53,7 +53,7 @@ --- // Unresolved import. // Error: 9-21 unresolved import -#import non_existing from "target.typ" +#import non_existing from "module.typ" --- // Cyclic import of this very file. @@ -62,7 +62,7 @@ --- // Cyclic import in other file. -#import * from "./importable/cycle1.typ" +#import * from "./modules/cycle1.typ" This is never reached. @@ -80,36 +80,36 @@ This is never reached. #import afrom, "b", c // Error: 9 expected import items -#import from "target.typ" +#import from "module.typ" // Error: 9-10 expected expression, found assignment operator // Error: 10 expected import items -#import = from "target.typ" +#import = from "module.typ" // Error: 15 expected expression #import * from // An additional trailing comma. // Error: 17-18 expected expression, found comma -#import a, b, c,, from "target.typ" +#import a, b, c,, from "module.typ" // Error: 1-6 unexpected keyword `from` -#from "target.typ" +#from "module.typ" // Error: 2:2 expected semicolon or line break -#import * from "target.typ +#import * from "module.typ "target // Error: 28 expected semicolon or line break -#import * from "target.typ" § 0.2.1 +#import * from "module.typ" § 0.2.1 // A star in the list. // Error: 12-13 expected expression, found star -#import a, *, b from "target.typ" +#import a, *, b from "module.typ" // An item after a star. // Error: 10 expected keyword `from` -#import *, a from "target.typ" +#import *, a from "module.typ" --- // Error: 9-13 expected identifier, found named pair diff --git a/tests/typ/code/include.typ b/tests/typ/compiler/include.typ similarity index 57% rename from tests/typ/code/include.typ rename to tests/typ/compiler/include.typ index e862adac7..289fea217 100644 --- a/tests/typ/code/include.typ +++ b/tests/typ/compiler/include.typ @@ -6,22 +6,22 @@ = Document // Include a file -#include "/typ/code/importable/chap1.typ" +#include "/typ/compiler/modules/chap1.typ" // Expression as a file name. -#let chap2 = include "import" + "able/chap" + "2.typ" +#let chap2 = include "modu" + "les/chap" + "2.typ" -- _Intermission_ -- #chap2 --- { - // Error: 19-41 file not found (searched at typ/code/importable/chap3.typ) - let x = include "importable/chap3.typ" + // Error: 19-38 file not found (searched at typ/compiler/modules/chap3.typ) + let x = include "modules/chap3.typ" } --- -#include "importable/chap1.typ" +#include "modules/chap1.typ" // The variables of the file should not appear in this scope. // Error: 1-6 unknown variable diff --git a/tests/typ/style/label.typ b/tests/typ/compiler/label.typ similarity index 100% rename from tests/typ/style/label.typ rename to tests/typ/compiler/label.typ diff --git a/tests/typ/code/let.typ b/tests/typ/compiler/let.typ similarity index 100% rename from tests/typ/code/let.typ rename to tests/typ/compiler/let.typ diff --git a/tests/typ/base/collection.typ b/tests/typ/compiler/methods-collection.typ similarity index 98% rename from tests/typ/base/collection.typ rename to tests/typ/compiler/methods-collection.typ index 46ff97abe..fcebf6400 100644 --- a/tests/typ/base/collection.typ +++ b/tests/typ/compiler/methods-collection.typ @@ -1,4 +1,4 @@ -// Test collection functions. +// Test the collection methods. // Ref: false --- diff --git a/tests/typ/compiler/methods-color.typ b/tests/typ/compiler/methods-color.typ new file mode 100644 index 000000000..1188030ac --- /dev/null +++ b/tests/typ/compiler/methods-color.typ @@ -0,0 +1,22 @@ +// Test color modification methods. + +--- +// Test gray color modification. +#test(luma(20%).lighten(50%), luma(60%)) +#test(luma(80%).darken(20%), luma(63.9%)) +#test(luma(80%).negate(), luma(20%)) + +--- +// Test CMYK color conversion. +// Ref: true +#let c = cmyk(50%, 64%, 16%, 17%) +#rect(width: 1cm, fill: cmyk(69%, 11%, 69%, 41%)) +#rect(width: 1cm, fill: c) +#rect(width: 1cm, fill: c.negate()) + +#for x in range(0, 11) { + square(width: 9pt, fill: c.lighten(x * 10%)) +} +#for x in range(0, 11) { + square(width: 9pt, fill: c.darken(x * 10%)) +} diff --git a/tests/typ/base/string.typ b/tests/typ/compiler/methods-str.typ similarity index 86% rename from tests/typ/base/string.typ rename to tests/typ/compiler/methods-str.typ index e724f5632..aead4aa4b 100644 --- a/tests/typ/base/string.typ +++ b/tests/typ/compiler/methods-str.typ @@ -1,18 +1,6 @@ -// Test string related methods. +// Test the string methods. // Ref: false ---- -// Test conversion to string. -#test(str(123), "123") -#test(str(50.14), "50.14") -#test(str(10 / 3).len() > 10, true) -#test(repr(ltr), "ltr") -#test(repr((1, 2, false, )), "(1, 2, false)") - ---- -// Error: 6-8 cannot convert content to string -#str([]) - --- // Test the `slice` method. #test("abc".slice(1, 2), "b") @@ -127,14 +115,3 @@ #test("abc".split("b"), ("a", "c")) #test("a123c".split(regex("\d")), ("a", "", "", "c")) #test("a123c".split(regex("\d+")), ("a", "c")) - ---- -// Test the `upper` and `lower` functions. -#let memes = "ArE mEmEs gReAt?"; -#test(lower(memes), "are memes great?") -#test(upper(memes), "ARE MEMES GREAT?") -#test(upper("Ελλάδα"), "ΕΛΛΆΔΑ") - ---- -// Error: 8-9 expected string or content, found integer -#upper(1) diff --git a/tests/typ/code/methods.typ b/tests/typ/compiler/methods.typ similarity index 94% rename from tests/typ/code/methods.typ rename to tests/typ/compiler/methods.typ index f5db8ca03..07f6e4106 100644 --- a/tests/typ/code/methods.typ +++ b/tests/typ/compiler/methods.typ @@ -41,10 +41,6 @@ #let numbers = (1, 2, 3) { numbers.sorted() = 1 } ---- -// Error: 3-6 cannot mutate a constant -{ box = 1 } - --- // Error: 3-6 cannot mutate a constant { box.push(1) } diff --git a/tests/typ/code/target.typ b/tests/typ/compiler/module.typ similarity index 100% rename from tests/typ/code/target.typ rename to tests/typ/compiler/module.typ diff --git a/tests/typ/code/importable/chap1.typ b/tests/typ/compiler/modules/chap1.typ similarity index 100% rename from tests/typ/code/importable/chap1.typ rename to tests/typ/compiler/modules/chap1.typ diff --git a/tests/typ/code/importable/chap2.typ b/tests/typ/compiler/modules/chap2.typ similarity index 100% rename from tests/typ/code/importable/chap2.typ rename to tests/typ/compiler/modules/chap2.typ diff --git a/tests/typ/code/importable/cycle1.typ b/tests/typ/compiler/modules/cycle1.typ similarity index 100% rename from tests/typ/code/importable/cycle1.typ rename to tests/typ/compiler/modules/cycle1.typ diff --git a/tests/typ/code/importable/cycle2.typ b/tests/typ/compiler/modules/cycle2.typ similarity index 100% rename from tests/typ/code/importable/cycle2.typ rename to tests/typ/compiler/modules/cycle2.typ diff --git a/tests/typ/code/ops-assoc.typ b/tests/typ/compiler/ops-assoc.typ similarity index 100% rename from tests/typ/code/ops-assoc.typ rename to tests/typ/compiler/ops-assoc.typ diff --git a/tests/typ/code/ops-invalid.typ b/tests/typ/compiler/ops-invalid.typ similarity index 100% rename from tests/typ/code/ops-invalid.typ rename to tests/typ/compiler/ops-invalid.typ diff --git a/tests/typ/code/ops-prec.typ b/tests/typ/compiler/ops-prec.typ similarity index 100% rename from tests/typ/code/ops-prec.typ rename to tests/typ/compiler/ops-prec.typ diff --git a/tests/typ/code/ops.typ b/tests/typ/compiler/ops.typ similarity index 98% rename from tests/typ/code/ops.typ rename to tests/typ/compiler/ops.typ index c382f34d9..a38a527ce 100644 --- a/tests/typ/code/ops.typ +++ b/tests/typ/compiler/ops.typ @@ -188,6 +188,10 @@ { x = "some" } #test(x, "some") { x += "thing" } #test(x, "something") +--- +// Error: 3-6 cannot mutate a constant +{ box = 1 } + --- // Test `in` operator. #test("hi" in "worship", true) diff --git a/tests/typ/code/repr.typ b/tests/typ/compiler/repr.typ similarity index 100% rename from tests/typ/code/repr.typ rename to tests/typ/compiler/repr.typ diff --git a/tests/typ/code/return.typ b/tests/typ/compiler/return.typ similarity index 100% rename from tests/typ/code/return.typ rename to tests/typ/compiler/return.typ diff --git a/tests/typ/style/set.typ b/tests/typ/compiler/set.typ similarity index 100% rename from tests/typ/style/set.typ rename to tests/typ/compiler/set.typ diff --git a/tests/typ/text/shorthands.typ b/tests/typ/compiler/shorthand.typ similarity index 100% rename from tests/typ/text/shorthands.typ rename to tests/typ/compiler/shorthand.typ diff --git a/tests/typ/style/show-bare.typ b/tests/typ/compiler/show-bare.typ similarity index 100% rename from tests/typ/style/show-bare.typ rename to tests/typ/compiler/show-bare.typ diff --git a/tests/typ/style/show-node.typ b/tests/typ/compiler/show-node.typ similarity index 100% rename from tests/typ/style/show-node.typ rename to tests/typ/compiler/show-node.typ diff --git a/tests/typ/style/show-recursive.typ b/tests/typ/compiler/show-recursive.typ similarity index 100% rename from tests/typ/style/show-recursive.typ rename to tests/typ/compiler/show-recursive.typ diff --git a/tests/typ/style/show-selector.typ b/tests/typ/compiler/show-selector.typ similarity index 100% rename from tests/typ/style/show-selector.typ rename to tests/typ/compiler/show-selector.typ diff --git a/tests/typ/style/show-text.typ b/tests/typ/compiler/show-text.typ similarity index 100% rename from tests/typ/style/show-text.typ rename to tests/typ/compiler/show-text.typ diff --git a/tests/typ/code/spread.typ b/tests/typ/compiler/spread.typ similarity index 100% rename from tests/typ/code/spread.typ rename to tests/typ/compiler/spread.typ diff --git a/tests/typ/code/while.typ b/tests/typ/compiler/while.typ similarity index 100% rename from tests/typ/code/while.typ rename to tests/typ/compiler/while.typ diff --git a/tests/typ/base/calc.typ b/tests/typ/compute/calc.typ similarity index 100% rename from tests/typ/base/calc.typ rename to tests/typ/compute/calc.typ diff --git a/tests/typ/base/color.typ b/tests/typ/compute/create.typ similarity index 61% rename from tests/typ/base/color.typ rename to tests/typ/compute/create.typ index aecd86b88..462f06e94 100644 --- a/tests/typ/base/color.typ +++ b/tests/typ/compute/create.typ @@ -1,4 +1,4 @@ -// Test color creation functions and modification methods. +// Test creation and conversion functions. // Ref: false --- @@ -20,27 +20,6 @@ #rect(fill: luma(0)) #rect(fill: luma(80%)) ---- -// Test gray color modification. -#test(luma(20%).lighten(50%), luma(60%)) -#test(luma(80%).darken(20%), luma(63.9%)) -#test(luma(80%).negate(), luma(20%)) - ---- -// Test CMYK color conversion. -// Ref: true -#let c = cmyk(50%, 64%, 16%, 17%) -#rect(width: 1cm, fill: cmyk(69%, 11%, 69%, 41%)) -#rect(width: 1cm, fill: c) -#rect(width: 1cm, fill: c.negate()) - -#for x in range(0, 11) { - square(width: 9pt, fill: c.lighten(x * 10%)) -} -#for x in range(0, 11) { - square(width: 9pt, fill: c.darken(x * 10%)) -} - --- // Error for values that are out of range. // Error: 11-14 must be between 0 and 255 @@ -61,3 +40,16 @@ --- // Error: 21-26 expected integer or ratio, found boolean #rgb(10%, 20%, 30%, false) + +--- +// Test conversion to string. +#test(str(123), "123") +#test(str(50.14), "50.14") +#test(str(10 / 3).len() > 10, true) + +--- +// Error: 6-8 cannot convert content to string +#str([]) + +--- +#assert(range(2, 5) == (2, 3, 4)) diff --git a/tests/typ/base/data.typ b/tests/typ/compute/data.typ similarity index 94% rename from tests/typ/base/data.typ rename to tests/typ/compute/data.typ index 96b12ff5b..c1def7d55 100644 --- a/tests/typ/base/data.typ +++ b/tests/typ/compute/data.typ @@ -10,7 +10,7 @@ #table(columns: data(0).len(), ..cells) --- -// Error: 6-16 file not found (searched at typ/base/nope.csv) +// Error: 6-16 file not found (searched at typ/compute/nope.csv) #csv("nope.csv") --- diff --git a/tests/typ/base/eval.typ b/tests/typ/compute/foundations.typ similarity index 61% rename from tests/typ/base/eval.typ rename to tests/typ/compute/foundations.typ index 80235c0c8..6fc93a750 100644 --- a/tests/typ/base/eval.typ +++ b/tests/typ/compute/foundations.typ @@ -1,4 +1,30 @@ -// Test the `eval` function. +// Test foundational functions. +// Ref: false + +--- +#test(type(1), "integer") +#test(type(ltr), "direction") +#test(type(10 / 3), "float") + +--- +#test(repr(ltr), "ltr") +#test(repr((1, 2, false, )), "(1, 2, false)") + +--- +// Test failing assertions. +// Error: 9-15 assertion failed +#assert(1 == 2) + +--- +// Test failing assertions. +// Error: 9-15 expected boolean, found string +#assert("true") + +--- +// Test the `type` function. +#test(type(1), "integer") +#test(type(ltr), "direction") +#test(type(10 / 3), "float") --- #eval("_Hello" + " World!_") diff --git a/tests/typ/base/blind.typ b/tests/typ/compute/utility.typ similarity index 67% rename from tests/typ/base/blind.typ rename to tests/typ/compute/utility.typ index 17452decf..f042c7697 100644 --- a/tests/typ/base/blind.typ +++ b/tests/typ/compute/utility.typ @@ -1,4 +1,4 @@ -// Test blind text. +// Test integrated numbering patterns. --- // Test basic call. @@ -30,3 +30,15 @@ --- // Error: 7-9 missing argument: number of words #lorem() + +--- +#for i in range(9) { + numbering(i, "* and ") + numbering(i, "I") + [ for #i] + parbreak() +} + +--- +// Error: 12-14 must be at least zero +#numbering(-1, "1") diff --git a/tests/typ/layout/orphan-widow.typ b/tests/typ/layout/flow-orphan.typ similarity index 74% rename from tests/typ/layout/orphan-widow.typ rename to tests/typ/layout/flow-orphan.typ index 445b44e3e..a51da2b22 100644 --- a/tests/typ/layout/orphan-widow.typ +++ b/tests/typ/layout/flow-orphan.typ @@ -1,4 +1,11 @@ -// Test widow and orphan prevention. +// Test that a heading doesn't become an orphan. + +--- +#set page(height: 100pt) +#lorem(12) + += Introduction +This is the start and it goes on. --- #set page("a8", height: 150pt) diff --git a/tests/typ/graphics/hide.typ b/tests/typ/layout/hide.typ similarity index 100% rename from tests/typ/graphics/hide.typ rename to tests/typ/layout/hide.typ diff --git a/tests/typ/layout/orphan-heading.typ b/tests/typ/layout/orphan-heading.typ deleted file mode 100644 index ef3de8859..000000000 --- a/tests/typ/layout/orphan-heading.typ +++ /dev/null @@ -1,8 +0,0 @@ -// Test that a heading doesn't become an orphan. - ---- -#set page(height: 100pt) -#lorem(12) - -= Introduction -This is the start and it goes on. diff --git a/tests/typ/text/bidi.typ b/tests/typ/layout/par-bidi.typ similarity index 100% rename from tests/typ/text/bidi.typ rename to tests/typ/layout/par-bidi.typ diff --git a/tests/typ/text/indent.typ b/tests/typ/layout/par-indent.typ similarity index 100% rename from tests/typ/text/indent.typ rename to tests/typ/layout/par-indent.typ diff --git a/tests/typ/text/justify.typ b/tests/typ/layout/par-justify.typ similarity index 100% rename from tests/typ/text/justify.typ rename to tests/typ/layout/par-justify.typ diff --git a/tests/typ/text/knuth.typ b/tests/typ/layout/par-knuth.typ similarity index 100% rename from tests/typ/text/knuth.typ rename to tests/typ/layout/par-knuth.typ diff --git a/tests/typ/text/plain.typ b/tests/typ/layout/par-simple.typ similarity index 100% rename from tests/typ/text/plain.typ rename to tests/typ/layout/par-simple.typ diff --git a/tests/typ/text/par.typ b/tests/typ/layout/par.typ similarity index 100% rename from tests/typ/text/par.typ rename to tests/typ/layout/par.typ diff --git a/tests/typ/text/repeat.typ b/tests/typ/layout/repeat.typ similarity index 100% rename from tests/typ/text/repeat.typ rename to tests/typ/layout/repeat.typ diff --git a/tests/typ/graphics/transform.typ b/tests/typ/layout/transform.typ similarity index 100% rename from tests/typ/graphics/transform.typ rename to tests/typ/layout/transform.typ diff --git a/tests/typ/layout/math.typ b/tests/typ/math/simple.typ similarity index 100% rename from tests/typ/layout/math.typ rename to tests/typ/math/simple.typ diff --git a/tests/typ/style/document.typ b/tests/typ/meta/document.typ similarity index 100% rename from tests/typ/style/document.typ rename to tests/typ/meta/document.typ diff --git a/tests/typ/text/link.typ b/tests/typ/meta/link.typ similarity index 100% rename from tests/typ/text/link.typ rename to tests/typ/meta/link.typ diff --git a/tests/typ/text/case.typ b/tests/typ/text/case.typ new file mode 100644 index 000000000..75574f215 --- /dev/null +++ b/tests/typ/text/case.typ @@ -0,0 +1,12 @@ +// Test the `upper` and `lower` functions. +// Ref: false + +--- +#let memes = "ArE mEmEs gReAt?"; +#test(lower(memes), "are memes great?") +#test(upper(memes), "ARE MEMES GREAT?") +#test(upper("Ελλάδα"), "ΕΛΛΆΔΑ") + +--- +// Error: 8-9 expected string or content, found integer +#upper(1) diff --git a/tests/typ/text/emph-strong.typ b/tests/typ/text/emphasis.typ similarity index 100% rename from tests/typ/text/emph-strong.typ rename to tests/typ/text/emphasis.typ diff --git a/tests/typ/text/code.typ b/tests/typ/text/raw-highlight.typ similarity index 100% rename from tests/typ/text/code.typ rename to tests/typ/text/raw-highlight.typ diff --git a/tests/typ/text/shifts.typ b/tests/typ/text/shift.typ similarity index 100% rename from tests/typ/text/shifts.typ rename to tests/typ/text/shift.typ diff --git a/tests/typ/text/whitespace.typ b/tests/typ/text/space.typ similarity index 100% rename from tests/typ/text/whitespace.typ rename to tests/typ/text/space.typ diff --git a/tests/typ/graphics/image.typ b/tests/typ/visualize/image.typ similarity index 94% rename from tests/typ/graphics/image.typ rename to tests/typ/visualize/image.typ index e97365cd1..6a2c37e17 100644 --- a/tests/typ/graphics/image.typ +++ b/tests/typ/visualize/image.typ @@ -51,7 +51,7 @@ A #image("/res/tiger.jpg", height: 1cm, width: 80%) B #image("/res/pattern.svg") --- -// Error: 8-29 file not found (searched at typ/graphics/path/does/not/exist) +// Error: 8-29 file not found (searched at typ/visualize/path/does/not/exist) #image("path/does/not/exist") --- diff --git a/tests/typ/graphics/line.typ b/tests/typ/visualize/line.typ similarity index 100% rename from tests/typ/graphics/line.typ rename to tests/typ/visualize/line.typ diff --git a/tests/typ/graphics/shape-aspect.typ b/tests/typ/visualize/shape-aspect.typ similarity index 100% rename from tests/typ/graphics/shape-aspect.typ rename to tests/typ/visualize/shape-aspect.typ diff --git a/tests/typ/graphics/shape-circle.typ b/tests/typ/visualize/shape-circle.typ similarity index 100% rename from tests/typ/graphics/shape-circle.typ rename to tests/typ/visualize/shape-circle.typ diff --git a/tests/typ/graphics/shape-ellipse.typ b/tests/typ/visualize/shape-ellipse.typ similarity index 100% rename from tests/typ/graphics/shape-ellipse.typ rename to tests/typ/visualize/shape-ellipse.typ diff --git a/tests/typ/graphics/shape-fill-stroke.typ b/tests/typ/visualize/shape-fill-stroke.typ similarity index 100% rename from tests/typ/graphics/shape-fill-stroke.typ rename to tests/typ/visualize/shape-fill-stroke.typ diff --git a/tests/typ/graphics/shape-rect.typ b/tests/typ/visualize/shape-rect.typ similarity index 100% rename from tests/typ/graphics/shape-rect.typ rename to tests/typ/visualize/shape-rect.typ diff --git a/tests/typ/graphics/shape-square.typ b/tests/typ/visualize/shape-square.typ similarity index 100% rename from tests/typ/graphics/shape-square.typ rename to tests/typ/visualize/shape-square.typ