Skip to content

Commit

Permalink
Auto merge of #19 - :master, r=mbrubeck
Browse files Browse the repository at this point in the history
Improve specification conformance of unicode bidi library-Initial step

Files changed: src/lib.rs and tools/generate.py

•added code to  tools/generate.py  to download the files: http://www.unicode.org/Public/UNIDATA/BidiTest.txt and http://www.unicode.org/Public/UNIDATA/BidiCharacterTest.txt
•wrote manual rust tests in lib.rs that can be run automatically

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/unicode-bidi/19)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Nov 13, 2015
2 parents 701180a + 2a99bca commit 06dedd1
Show file tree
Hide file tree
Showing 3 changed files with 387 additions and 326 deletions.
51 changes: 49 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,21 +959,68 @@ mod test {
fn test_reorder_line() {
use super::{process_text, reorder_line};
use std::borrow::Cow;

fn reorder(s: &str) -> Cow<str> {
let info = process_text(s, None);
let para = &info.paragraphs[0];
reorder_line(s, para.range.clone(), &info.levels)
}

assert_eq!(reorder("abc123"), "abc123");
assert_eq!(reorder("1.-2"), "1.-2");
assert_eq!(reorder("1-.2"), "1-.2");
assert_eq!(reorder("abc אבג"), "abc גבא");
//Numbers being weak LTR characters, cannot reorder strong RTL
assert_eq!(reorder("123 אבג"), "גבא 123");
//Testing for RLE Character
assert_eq!(reorder("\u{202B}abc אבג\u{202C}"), "\u{202B}\u{202C}גבא abc");
//Testing neutral characters
assert_eq!(reorder("אבג? אבג"), "גבא ?גבא");
//Testing neutral characters with special case
assert_eq!(reorder("A אבג?"), "A גבא?");
//Testing neutral characters with Implicit RTL Marker
//The given test highlights a possible non-conformance issue that will perhaps be fixed in the subsequent steps.
//assert_eq!(reorder("A אבג?\u{202f}"), "A \u{202f}?גבא");
assert_eq!(reorder("אבג abc"), "abc גבא");
assert_eq!(reorder("abc\u{2067}.-\u{2069}ghi"),
"abc\u{2067}-.\u{2069}ghi");
assert_eq!(reorder("Hello, \u{2068}\u{202E}world\u{202C}\u{2069}!"),
"Hello, \u{2068}\u{202E}\u{202C}dlrow\u{2069}!");
}

#[test]
fn test_is_ltr() {
use super::is_ltr;
assert_eq!(is_ltr(10), true);
assert_eq!(is_ltr(11), false);
assert_eq!(is_ltr(20), true);
}

#[test]
fn test_is_rtl() {
use super::is_rtl;
assert_eq!(is_rtl(13), true);
assert_eq!(is_rtl(11), true);
assert_eq!(is_rtl(20), false);
}

#[test]
fn test_removed_by_x9() {
use prepare::removed_by_x9;
let rem_classes = &[RLE, LRE, RLO, LRO, PDF, BN];
let not_classes = &[L, RLI, AL, LRI, PDI];
for x in rem_classes {
assert_eq!(removed_by_x9(*x), true);
}
for x in not_classes {
assert_eq!(removed_by_x9(*x), false);
}
}

#[test]
fn test_not_removed_by_x9() {
use prepare::not_removed_by_x9;
let non_x9_classes = &[L, R, AL, EN, ES, ET, AN, CS, NSM, B, S, WS, ON, LRI, RLI, FSI, PDI];
for x in non_x9_classes {
assert_eq!(not_removed_by_x9(&x), true);
}
}
}
Loading

0 comments on commit 06dedd1

Please sign in to comment.