servo/components/layout_2020/tests/text.rs
Martin Robinson d8b326528b
layout: Add initial support for text-transform (#31396)
This adds basic support for `text-transform` in a way that is more
complete than legacy layout. There are still many missing elements of
proper `text-transform` support such as:

1. Support for `full-width` and `full-size-kana`
2. Support for grapheme based uppercasing, lowercasing, and
   capitalization. These are all done per-code point right now.
3. Support for the language-specific `SpecialCasing.txt` cases for case
   mapping such as the ones for Irish and Turkish.

Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2024-02-22 14:15:59 +00:00

55 lines
2 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
mod text {
use layout_2020::flow::text_run::WhitespaceCollapse;
use style::computed_values::white_space::T as WhiteSpace;
#[test]
fn test_collapse_whitespace() {
let collapse = |input: &str, white_space, trim_beginning_white_space| {
WhitespaceCollapse::new(input.chars(), white_space, trim_beginning_white_space)
.collect::<String>()
};
let output = collapse("H ", WhiteSpace::Normal, false);
assert_eq!(output, "H ");
let output = collapse(" W", WhiteSpace::Normal, true);
assert_eq!(output, "W");
let output = collapse(" W", WhiteSpace::Normal, false);
assert_eq!(output, " W");
let output = collapse(" H W", WhiteSpace::Normal, false);
assert_eq!(output, " H W");
let output = collapse("\n H \n \t W", WhiteSpace::Normal, false);
assert_eq!(output, " H W");
let output = collapse("\n H \n \t W \n", WhiteSpace::Pre, false);
assert_eq!(output, "\n H \n \t W \n");
let output = collapse("\n H \n \t W \n ", WhiteSpace::PreLine, false);
assert_eq!(output, "\nH\nW\n");
let output = collapse("Hello \n World", WhiteSpace::PreLine, true);
assert_eq!(output, "Hello\nWorld");
let output = collapse(" \n World", WhiteSpace::PreLine, true);
assert_eq!(output, "\nWorld");
let output = collapse(" ", WhiteSpace::Normal, true);
assert_eq!(output, "");
let output = collapse(" ", WhiteSpace::Normal, false);
assert_eq!(output, " ");
let output = collapse("\n ", WhiteSpace::Normal, true);
assert_eq!(output, "");
let output = collapse("\n ", WhiteSpace::Normal, false);
assert_eq!(output, " ");
}
}