From 9c040a9d2b6aa0400df868c8a8581a9e168b9d14 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 29 Mar 2021 14:51:54 +0200 Subject: =?UTF-8?q?Move=20around=20test=20cases=20=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/base.rs | 65 ----------------------------------------- src/library/basic.rs | 65 +++++++++++++++++++++++++++++++++++++++++ src/library/mod.rs | 4 +-- tests/ref/markup/basic.png | Bin 0 -> 3827 bytes tests/ref/markup/linebreak.png | Bin 3574 -> 0 bytes tests/ref/markup/nbsp.png | Bin 1664 -> 0 bytes tests/ref/markup/parbreak.png | Bin 1682 -> 0 bytes tests/ref/text/complex.png | Bin 12273 -> 0 bytes tests/ref/text/shaping.png | Bin 0 -> 12273 bytes tests/typ/library/base.typ | 25 ---------------- tests/typ/library/basic.typ | 25 ++++++++++++++++ tests/typ/markup/basic.typ | 22 ++++++++++++++ tests/typ/markup/linebreak.typ | 25 ---------------- tests/typ/markup/nbsp.typ | 4 --- tests/typ/markup/parbreak.typ | 11 ------- tests/typ/text/complex.typ | 38 ------------------------ tests/typ/text/shaping.typ | 38 ++++++++++++++++++++++++ 17 files changed, 152 insertions(+), 170 deletions(-) delete mode 100644 src/library/base.rs create mode 100644 src/library/basic.rs create mode 100644 tests/ref/markup/basic.png delete mode 100644 tests/ref/markup/linebreak.png delete mode 100644 tests/ref/markup/nbsp.png delete mode 100644 tests/ref/markup/parbreak.png delete mode 100644 tests/ref/text/complex.png create mode 100644 tests/ref/text/shaping.png delete mode 100644 tests/typ/library/base.typ create mode 100644 tests/typ/library/basic.typ create mode 100644 tests/typ/markup/basic.typ delete mode 100644 tests/typ/markup/linebreak.typ delete mode 100644 tests/typ/markup/nbsp.typ delete mode 100644 tests/typ/markup/parbreak.typ delete mode 100644 tests/typ/text/complex.typ create mode 100644 tests/typ/text/shaping.typ diff --git a/src/library/base.rs b/src/library/base.rs deleted file mode 100644 index 48925122..00000000 --- a/src/library/base.rs +++ /dev/null @@ -1,65 +0,0 @@ -use crate::color::{Color, RgbaColor}; -use crate::pretty::pretty; - -use super::*; - -/// `type`: The name of a value's type. -/// -/// # Positional parameters -/// - Any value. -/// -/// # Return value -/// The name of the value's type as a string. -pub fn type_(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - match args.require::(ctx, "value") { - Some(value) => value.type_name().into(), - None => Value::Error, - } -} - -/// `repr`: The string representation of a value. -/// -/// # Positional parameters -/// - Any value. -/// -/// # Return value -/// The string representation of the value. -pub fn repr(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - match args.require::(ctx, "value") { - Some(value) => pretty(&value).into(), - None => Value::Error, - } -} - -/// `rgb`: Create an RGB(A) color. -/// -/// # Positional parameters -/// - Red component: of type `float`, between 0.0 and 1.0. -/// - Green component: of type `float`, between 0.0 and 1.0. -/// - Blue component: of type `float`, between 0.0 and 1.0. -/// - Alpha component: optional, of type `float`, between 0.0 and 1.0. -/// -/// # Return value -/// The color with the given components. -pub fn rgb(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - let r = args.require(ctx, "red component"); - let g = args.require(ctx, "green component"); - let b = args.require(ctx, "blue component"); - let a = args.find(ctx); - - let mut clamp = |component: Option>, default| { - component.map_or(default, |c| { - if c.v < 0.0 || c.v > 1.0 { - ctx.diag(warning!(c.span, "should be between 0.0 and 1.0")); - } - (c.v.max(0.0).min(1.0) * 255.0).round() as u8 - }) - }; - - Value::Color(Color::Rgba(RgbaColor::new( - clamp(r, 0), - clamp(g, 0), - clamp(b, 0), - clamp(a, 255), - ))) -} diff --git a/src/library/basic.rs b/src/library/basic.rs new file mode 100644 index 00000000..48925122 --- /dev/null +++ b/src/library/basic.rs @@ -0,0 +1,65 @@ +use crate::color::{Color, RgbaColor}; +use crate::pretty::pretty; + +use super::*; + +/// `type`: The name of a value's type. +/// +/// # Positional parameters +/// - Any value. +/// +/// # Return value +/// The name of the value's type as a string. +pub fn type_(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { + match args.require::(ctx, "value") { + Some(value) => value.type_name().into(), + None => Value::Error, + } +} + +/// `repr`: The string representation of a value. +/// +/// # Positional parameters +/// - Any value. +/// +/// # Return value +/// The string representation of the value. +pub fn repr(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { + match args.require::(ctx, "value") { + Some(value) => pretty(&value).into(), + None => Value::Error, + } +} + +/// `rgb`: Create an RGB(A) color. +/// +/// # Positional parameters +/// - Red component: of type `float`, between 0.0 and 1.0. +/// - Green component: of type `float`, between 0.0 and 1.0. +/// - Blue component: of type `float`, between 0.0 and 1.0. +/// - Alpha component: optional, of type `float`, between 0.0 and 1.0. +/// +/// # Return value +/// The color with the given components. +pub fn rgb(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { + let r = args.require(ctx, "red component"); + let g = args.require(ctx, "green component"); + let b = args.require(ctx, "blue component"); + let a = args.find(ctx); + + let mut clamp = |component: Option>, default| { + component.map_or(default, |c| { + if c.v < 0.0 || c.v > 1.0 { + ctx.diag(warning!(c.span, "should be between 0.0 and 1.0")); + } + (c.v.max(0.0).min(1.0) * 255.0).round() as u8 + }) + }; + + Value::Color(Color::Rgba(RgbaColor::new( + clamp(r, 0), + clamp(g, 0), + clamp(b, 0), + clamp(a, 255), + ))) +} diff --git a/src/library/mod.rs b/src/library/mod.rs index 9c2a661a..738348ee 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -4,7 +4,7 @@ //! definitions. mod align; -mod base; +mod basic; mod font; mod image; mod lang; @@ -17,7 +17,7 @@ mod spacing; pub use self::image::*; pub use align::*; -pub use base::*; +pub use basic::*; pub use font::*; pub use lang::*; pub use markup::*; diff --git a/tests/ref/markup/basic.png b/tests/ref/markup/basic.png new file mode 100644 index 00000000..a43fcbcb Binary files /dev/null and b/tests/ref/markup/basic.png differ diff --git a/tests/ref/markup/linebreak.png b/tests/ref/markup/linebreak.png deleted file mode 100644 index 32236e74..00000000 Binary files a/tests/ref/markup/linebreak.png and /dev/null differ diff --git a/tests/ref/markup/nbsp.png b/tests/ref/markup/nbsp.png deleted file mode 100644 index 8834bb2b..00000000 Binary files a/tests/ref/markup/nbsp.png and /dev/null differ diff --git a/tests/ref/markup/parbreak.png b/tests/ref/markup/parbreak.png deleted file mode 100644 index f100b9d7..00000000 Binary files a/tests/ref/markup/parbreak.png and /dev/null differ diff --git a/tests/ref/text/complex.png b/tests/ref/text/complex.png deleted file mode 100644 index 9af49f16..00000000 Binary files a/tests/ref/text/complex.png and /dev/null differ diff --git a/tests/ref/text/shaping.png b/tests/ref/text/shaping.png new file mode 100644 index 00000000..9af49f16 Binary files /dev/null and b/tests/ref/text/shaping.png differ diff --git a/tests/typ/library/base.typ b/tests/typ/library/base.typ deleted file mode 100644 index cc9f14a0..00000000 --- a/tests/typ/library/base.typ +++ /dev/null @@ -1,25 +0,0 @@ -// Test the base functions. -// Ref: false - ---- -#test(type("hi"), "string") -#test(repr([Hi #rect[there]]), "[Hi []]") - ---- -// Check the output. -#test(rgb(0.0, 0.3, 0.7), #004db3) - -// Alpha channel. -#test(rgb(1.0, 0.0, 0.0, 0.5), #ff000080) - -// Warning: 2:11-2:14 should be between 0.0 and 1.0 -// Warning: 1:16-1:20 should be between 0.0 and 1.0 -#test(rgb(-30, 15.5, 0.5), #00ff80) - -// Error: 11-15 missing argument: blue component -#test(rgb(0, 1), #00ff00) - -// Error: 3:11-3:11 missing argument: red component -// Error: 2:11-2:11 missing argument: green component -// Error: 1:11-1:11 missing argument: blue component -#test(rgb(), #000000) diff --git a/tests/typ/library/basic.typ b/tests/typ/library/basic.typ new file mode 100644 index 00000000..a16215a7 --- /dev/null +++ b/tests/typ/library/basic.typ @@ -0,0 +1,25 @@ +// Test basic functions. +// Ref: false + +--- +#test(type("hi"), "string") +#test(repr([Hi #rect[there]]), "[Hi []]") + +--- +// Check the output. +#test(rgb(0.0, 0.3, 0.7), #004db3) + +// Alpha channel. +#test(rgb(1.0, 0.0, 0.0, 0.5), #ff000080) + +// Warning: 2:11-2:14 should be between 0.0 and 1.0 +// Warning: 1:16-1:20 should be between 0.0 and 1.0 +#test(rgb(-30, 15.5, 0.5), #00ff80) + +// Error: 11-15 missing argument: blue component +#test(rgb(0, 1), #00ff00) + +// Error: 3:11-3:11 missing argument: red component +// Error: 2:11-2:11 missing argument: green component +// Error: 1:11-1:11 missing argument: blue component +#test(rgb(), #000000) diff --git a/tests/typ/markup/basic.typ b/tests/typ/markup/basic.typ new file mode 100644 index 00000000..3e83b911 --- /dev/null +++ b/tests/typ/markup/basic.typ @@ -0,0 +1,22 @@ +// Test basic markup. + +--- +#let linebreak() = [ + // Inside the old line break definition is still active. + #circle(radius: 2pt, fill: #000) \ +] + +A \ B \ C + +--- +// Paragraph breaks don't exist! +#let parbreak() = [ ] + +No more + +paragraph breaks + +for you! + +--- +The non-breaking~space does work. diff --git a/tests/typ/markup/linebreak.typ b/tests/typ/markup/linebreak.typ deleted file mode 100644 index b1b83dcc..00000000 --- a/tests/typ/markup/linebreak.typ +++ /dev/null @@ -1,25 +0,0 @@ -// Test forced line breaks. - ---- -// Directly after word. -Line\ Break - -// Spaces around. -Line \ Break - -// Directly before word does not work. -No \Break - -\ Before - -Multiple \ \ \ - -Times - ---- -#let linebreak() = [ - // Inside the old line break definition is still active. - #circle(radius: 2pt, fill: #000) \ -] - -A \ B \ C diff --git a/tests/typ/markup/nbsp.typ b/tests/typ/markup/nbsp.typ deleted file mode 100644 index 372268eb..00000000 --- a/tests/typ/markup/nbsp.typ +++ /dev/null @@ -1,4 +0,0 @@ -// Test the non breaking space. - ---- -The non-breaking~space does work. diff --git a/tests/typ/markup/parbreak.typ b/tests/typ/markup/parbreak.typ deleted file mode 100644 index b9b8a222..00000000 --- a/tests/typ/markup/parbreak.typ +++ /dev/null @@ -1,11 +0,0 @@ -// Test paragraph breaks. - ---- -// Paragraph breaks don't exist! -#let parbreak() = [ ] - -No more - -paragraph breaks - -for you! diff --git a/tests/typ/text/complex.typ b/tests/typ/text/complex.typ deleted file mode 100644 index 567a208d..00000000 --- a/tests/typ/text/complex.typ +++ /dev/null @@ -1,38 +0,0 @@ -// Test complex text shaping. - ---- -// Test ligatures. - -// This should create an "fi" ligature. -Le fira - -// This should just shape nicely. -#font("Noto Sans Arabic") -منش إلا بسم الله - -// This should form a three-member family. -#font("Twitter Color Emoji") -👩‍👩‍👦 🤚🏿 - -// These two shouldn't be affected by a zero-width joiner. -🏞‍🌋 - ---- -// Test font fallback. - -#font("EB Garamond", "Noto Sans Arabic", "Twitter Color Emoji") - -// Font fallback for emoji. -A😀B - -// Font fallback for entire text. -منش إلا بسم الله - -// Font fallback in right-to-left text. -ب🐈😀سم - -// Multi-layer font fallback. -Aب😀🏞سمB - -// Tofus are rendered with the first font. -A🐈中文B diff --git a/tests/typ/text/shaping.typ b/tests/typ/text/shaping.typ new file mode 100644 index 00000000..567a208d --- /dev/null +++ b/tests/typ/text/shaping.typ @@ -0,0 +1,38 @@ +// Test complex text shaping. + +--- +// Test ligatures. + +// This should create an "fi" ligature. +Le fira + +// This should just shape nicely. +#font("Noto Sans Arabic") +منش إلا بسم الله + +// This should form a three-member family. +#font("Twitter Color Emoji") +👩‍👩‍👦 🤚🏿 + +// These two shouldn't be affected by a zero-width joiner. +🏞‍🌋 + +--- +// Test font fallback. + +#font("EB Garamond", "Noto Sans Arabic", "Twitter Color Emoji") + +// Font fallback for emoji. +A😀B + +// Font fallback for entire text. +منش إلا بسم الله + +// Font fallback in right-to-left text. +ب🐈😀سم + +// Multi-layer font fallback. +Aب😀🏞سمB + +// Tofus are rendered with the first font. +A🐈中文B -- cgit v1.2.3