Format remaining files

This commit is contained in:
Pyfisch 2018-11-06 13:01:35 +01:00
parent bf47f90da6
commit cb07debcb6
252 changed files with 5944 additions and 3744 deletions

View file

@ -34,7 +34,8 @@ fn test_normalize_non_empty_no_whitespace_bytestring() {
#[test]
fn test_normalize_non_empty_leading_whitespace_bytestring() {
// Non-empty, leading whitespace, no trailing whitespace ByteString test
let leading_whitespace_bytestring = ByteString::new(vec![b'\t', b'\n', b' ', b'\r', b'S', b'!']);
let leading_whitespace_bytestring =
ByteString::new(vec![b'\t', b'\n', b' ', b'\r', b'S', b'!']);
let actual = normalize_value(leading_whitespace_bytestring);
let expected = ByteString::new(vec![b'S', b'!']);
assert_eq!(actual, expected);
@ -43,7 +44,8 @@ fn test_normalize_non_empty_leading_whitespace_bytestring() {
#[test]
fn test_normalize_non_empty_no_leading_whitespace_trailing_whitespace_bytestring() {
// Non-empty, no leading whitespace, but with trailing whitespace ByteString test
let trailing_whitespace_bytestring = ByteString::new(vec![b'S', b'!', b'\t', b'\n', b' ', b'\r']);
let trailing_whitespace_bytestring =
ByteString::new(vec![b'S', b'!', b'\t', b'\n', b' ', b'\r']);
let actual = normalize_value(trailing_whitespace_bytestring);
let expected = ByteString::new(vec![b'S', b'!']);
assert_eq!(actual, expected);
@ -52,8 +54,9 @@ fn test_normalize_non_empty_no_leading_whitespace_trailing_whitespace_bytestring
#[test]
fn test_normalize_non_empty_leading_and_trailing_whitespace_bytestring() {
// Non-empty, leading whitespace, and trailing whitespace ByteString test
let whitespace_sandwich_bytestring =
ByteString::new(vec![b'\t', b'\n', b' ', b'\r', b'S', b'!', b'\t', b'\n', b' ', b'\r']);
let whitespace_sandwich_bytestring = ByteString::new(vec![
b'\t', b'\n', b' ', b'\r', b'S', b'!', b'\t', b'\n', b' ', b'\r',
]);
let actual = normalize_value(whitespace_sandwich_bytestring);
let expected = ByteString::new(vec![b'S', b'!']);
assert_eq!(actual, expected);
@ -63,10 +66,9 @@ fn test_normalize_non_empty_leading_and_trailing_whitespace_bytestring() {
fn test_normalize_non_empty_leading_trailing_and_internal_whitespace_bytestring() {
// Non-empty, leading whitespace, trailing whitespace,
// and internal whitespace ByteString test
let whitespace_bigmac_bytestring =
ByteString::new(vec![b'\t', b'\n', b' ', b'\r', b'S',
b'\t', b'\n', b' ', b'\r', b'!',
b'\t', b'\n', b' ', b'\r']);
let whitespace_bigmac_bytestring = ByteString::new(vec![
b'\t', b'\n', b' ', b'\r', b'S', b'\t', b'\n', b' ', b'\r', b'!', b'\t', b'\n', b' ', b'\r',
]);
let actual = normalize_value(whitespace_bigmac_bytestring);
let expected = ByteString::new(vec![b'S', b'\t', b'\n', b' ', b'\r', b'!']);
assert_eq!(actual, expected);

View file

@ -28,14 +28,26 @@ fn delimiter_input() {
// Area::Circle tests
#[test]
fn valid_circle_inputs() {
assert_eq!(Area::parse("10.2, 3.4, 5.2", Shape::Circle),
Some(Area::Circle { left: 10.2, top: 3.4, radius: 5.2 }));
assert_eq!(
Area::parse("10.2, 3.4, 5.2", Shape::Circle),
Some(Area::Circle {
left: 10.2,
top: 3.4,
radius: 5.2
})
);
}
#[test]
fn valid_negative_circle_inputs() {
assert_eq!(Area::parse("-10.2, -3.4, 5.2", Shape::Circle),
Some(Area::Circle { left: -10.2, top: -3.4, radius: 5.2 }));
assert_eq!(
Area::parse("-10.2, -3.4, 5.2", Shape::Circle),
Some(Area::Circle {
left: -10.2,
top: -3.4,
radius: 5.2
})
);
}
#[test]
@ -46,77 +58,133 @@ fn invalid_negative_circle_radius() {
// Area::Rectangle tests
#[test]
fn rectangle_valid_input() {
assert_eq!(Area::parse("5.2, 1.1, 10.2, 3.4", Shape::Rectangle),
Some(Area::Rectangle { top_left: (5.2, 1.1),
bottom_right: (10.2, 3.4) }));
assert_eq!(
Area::parse("5.2, 1.1, 10.2, 3.4", Shape::Rectangle),
Some(Area::Rectangle {
top_left: (5.2, 1.1),
bottom_right: (10.2, 3.4)
})
);
}
#[test]
fn rectangle_valid_negative_input() {
assert_eq!(Area::parse("-10.2, -3.4, -5.2, -1.1", Shape::Rectangle),
Some(Area::Rectangle { top_left: (-10.2, -3.4),
bottom_right: (-5.2, -1.1) }));
assert_eq!(
Area::parse("-10.2, -3.4, -5.2, -1.1", Shape::Rectangle),
Some(Area::Rectangle {
top_left: (-10.2, -3.4),
bottom_right: (-5.2, -1.1)
})
);
}
#[test]
fn rectangle_invalid_input() {
assert_eq!(Area::parse("5.2, 4.3, 10.2, 1.1.2", Shape::Rectangle),
Some(Area::Rectangle { top_left: (5.2, 0.0),
bottom_right: (10.2, 4.3) }));
assert_eq!(
Area::parse("5.2, 4.3, 10.2, 1.1.2", Shape::Rectangle),
Some(Area::Rectangle {
top_left: (5.2, 0.0),
bottom_right: (10.2, 4.3)
})
);
}
#[test]
fn rectangle_unordered_input() {
assert_eq!(Area::parse("5.2, 1.1, 10.2, 4.3", Shape::Rectangle),
Some(Area::Rectangle { top_left: (5.2, 1.1),
bottom_right: (10.2, 4.3) }));
assert_eq!(
Area::parse("5.2, 1.1, 10.2, 4.3", Shape::Rectangle),
Some(Area::Rectangle {
top_left: (5.2, 1.1),
bottom_right: (10.2, 4.3)
})
);
}
// Area::Polygon tests
#[test]
fn polygon_six_points_valid_input() {
assert_eq!(Area::parse("1.1, 1.1, 6.1, 1.1, 3.1, 3.1", Shape::Polygon),
Some(Area::Polygon { points: vec![1.1, 1.1, 6.1, 1.1, 3.1, 3.1] }));
assert_eq!(
Area::parse("1.1, 1.1, 6.1, 1.1, 3.1, 3.1", Shape::Polygon),
Some(Area::Polygon {
points: vec![1.1, 1.1, 6.1, 1.1, 3.1, 3.1]
})
);
}
#[test]
fn polygon_six_points_valid_negative_input() {
assert_eq!(Area::parse("1.1, -1.1, 6.1, -1.1, 3.1, -3.1", Shape::Polygon),
Some(Area::Polygon { points: vec![1.1, -1.1, 6.1, -1.1, 3.1, -3.1] }));
assert_eq!(
Area::parse("1.1, -1.1, 6.1, -1.1, 3.1, -3.1", Shape::Polygon),
Some(Area::Polygon {
points: vec![1.1, -1.1, 6.1, -1.1, 3.1, -3.1]
})
);
}
#[test]
fn polygon_six_points_invalid_input() {
assert_eq!(Area::parse(";1.1, 1.1,'; 6.1,(*^() 1.1, 3.1, 3.1, 100.1 %$,;", Shape::Polygon),
Some(Area::Polygon { points: vec![1.1, 1.1, 6.1, 1.1, 3.1, 3.1] }));
assert_eq!(
Area::parse(
";1.1, 1.1,'; 6.1,(*^() 1.1, 3.1, 3.1, 100.1 %$,;",
Shape::Polygon
),
Some(Area::Polygon {
points: vec![1.1, 1.1, 6.1, 1.1, 3.1, 3.1]
})
);
}
#[test]
fn polygon_eight_points_invalid_input() {
assert_eq!(Area::parse("1.1, -1.1, 6.1, -1.1, 1.1, -3.1, 6.1, -3.1.2, 12.1", Shape::Polygon),
Some(Area::Polygon { points: vec![1.1, -1.1, 6.1, -1.1, 1.1, -3.1, 6.1, 0.0] }));
assert_eq!(
Area::parse(
"1.1, -1.1, 6.1, -1.1, 1.1, -3.1, 6.1, -3.1.2, 12.1",
Shape::Polygon
),
Some(Area::Polygon {
points: vec![1.1, -1.1, 6.1, -1.1, 1.1, -3.1, 6.1, 0.0]
})
);
}
#[test]
fn test_hit_test_circle() {
let circ1 = Area::Circle { left: 20.0, top: 10.0, radius: 5.0 };
assert!(!circ1.hit_test(&Point2D::new(10.0, 20.0)));
let circ2 = Area::Circle { left: 10.0, top: 10.0, radius: 5.0 };
assert!(circ2.hit_test(&Point2D::new(10.0, 12.0)));
let circ1 = Area::Circle {
left: 20.0,
top: 10.0,
radius: 5.0,
};
assert!(!circ1.hit_test(&Point2D::new(10.0, 20.0)));
let circ2 = Area::Circle {
left: 10.0,
top: 10.0,
radius: 5.0,
};
assert!(circ2.hit_test(&Point2D::new(10.0, 12.0)));
}
#[test]
fn test_hit_test_rectangle() {
let rect1 = Area::Rectangle { top_left: (1.0, 7.0), bottom_right: (15.0, 10.0) };
assert!(!rect1.hit_test(&Point2D::new(10.0, 5.0)));
let rect2 = Area::Rectangle { top_left: (8.0, 10.0), bottom_right: (20.0, 12.0) };
assert!(rect2.hit_test(&Point2D::new(10.0, 12.0)));
let rect1 = Area::Rectangle {
top_left: (1.0, 7.0),
bottom_right: (15.0, 10.0),
};
assert!(!rect1.hit_test(&Point2D::new(10.0, 5.0)));
let rect2 = Area::Rectangle {
top_left: (8.0, 10.0),
bottom_right: (20.0, 12.0),
};
assert!(rect2.hit_test(&Point2D::new(10.0, 12.0)));
}
#[test]
fn test_hit_test_polygon() {
let poly1 = Area::Polygon { points: vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0] };
assert!(!poly1.hit_test(&Point2D::new(10.0, 5.0)));
let poly2 = Area::Polygon { points: vec![7.0, 7.5, 8.2, 9.0, 11.0, 12.0] };
assert!(!poly2.hit_test(&Point2D::new(10.0, 5.0)));
let poly1 = Area::Polygon {
points: vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
};
assert!(!poly1.hit_test(&Point2D::new(10.0, 5.0)));
let poly2 = Area::Polygon {
points: vec![7.0, 7.5, 8.2, 9.0, 11.0, 12.0],
};
assert!(!poly2.hit_test(&Point2D::new(10.0, 5.0)));
}

View file

@ -12,48 +12,104 @@ fn no_value() {
#[test]
fn width_one_value() {
let first_descriptor = Descriptor { wid: Some(320), den: None };
let first_imagesource = ImageSource { url: "small-image.jpg".to_string(), descriptor: first_descriptor };
let first_descriptor = Descriptor {
wid: Some(320),
den: None,
};
let first_imagesource = ImageSource {
url: "small-image.jpg".to_string(),
descriptor: first_descriptor,
};
let sources = &[first_imagesource];
assert_eq!(parse_a_srcset_attribute("small-image.jpg, 320w"), sources);
}
#[test]
fn width_two_value() {
let first_descriptor = Descriptor { wid: Some(320), den: None };
let first_imagesource = ImageSource { url: "small-image.jpg".to_string(), descriptor: first_descriptor };
let second_descriptor = Descriptor { wid: Some(480), den: None };
let second_imagesource = ImageSource { url: "medium-image.jpg".to_string(), descriptor: second_descriptor };
let first_descriptor = Descriptor {
wid: Some(320),
den: None,
};
let first_imagesource = ImageSource {
url: "small-image.jpg".to_string(),
descriptor: first_descriptor,
};
let second_descriptor = Descriptor {
wid: Some(480),
den: None,
};
let second_imagesource = ImageSource {
url: "medium-image.jpg".to_string(),
descriptor: second_descriptor,
};
let sources = &[first_imagesource, second_imagesource];
assert_eq!(parse_a_srcset_attribute("small-image.jpg 320w, medium-image.jpg 480w"), sources);
assert_eq!(
parse_a_srcset_attribute("small-image.jpg 320w, medium-image.jpg 480w"),
sources
);
}
#[test]
fn width_three_value() {
let first_descriptor = Descriptor { wid: Some(320), den: None };
let first_imagesource = ImageSource { url: "smallImage.jpg".to_string(), descriptor: first_descriptor };
let second_descriptor = Descriptor { wid: Some(480), den: None };
let second_imagesource = ImageSource { url: "mediumImage.jpg".to_string(), descriptor: second_descriptor };
let third_descriptor = Descriptor { wid: Some(800), den: None };
let third_imagesource = ImageSource { url: "largeImage.jpg".to_string(), descriptor: third_descriptor };
let first_descriptor = Descriptor {
wid: Some(320),
den: None,
};
let first_imagesource = ImageSource {
url: "smallImage.jpg".to_string(),
descriptor: first_descriptor,
};
let second_descriptor = Descriptor {
wid: Some(480),
den: None,
};
let second_imagesource = ImageSource {
url: "mediumImage.jpg".to_string(),
descriptor: second_descriptor,
};
let third_descriptor = Descriptor {
wid: Some(800),
den: None,
};
let third_imagesource = ImageSource {
url: "largeImage.jpg".to_string(),
descriptor: third_descriptor,
};
let sources = &[first_imagesource, second_imagesource, third_imagesource];
assert_eq!(parse_a_srcset_attribute("smallImage.jpg 320w,
assert_eq!(
parse_a_srcset_attribute(
"smallImage.jpg 320w,
mediumImage.jpg 480w,
largeImage.jpg 800w"), sources);
largeImage.jpg 800w"
),
sources
);
}
#[test]
fn density_value() {
let first_descriptor = Descriptor { wid: None, den: Some(1.0) };
let first_imagesource = ImageSource { url: "small-image.jpg".to_string(), descriptor: first_descriptor };
let first_descriptor = Descriptor {
wid: None,
den: Some(1.0),
};
let first_imagesource = ImageSource {
url: "small-image.jpg".to_string(),
descriptor: first_descriptor,
};
let sources = &[first_imagesource];
assert_eq!(parse_a_srcset_attribute("small-image.jpg 1x"), sources);
}
#[test]
fn without_descriptor() {
let first_descriptor = Descriptor { wid: None, den: None };
let first_imagesource = ImageSource { url: "small-image.jpg".to_string(), descriptor: first_descriptor };
let first_descriptor = Descriptor {
wid: None,
den: None,
};
let first_imagesource = ImageSource {
url: "small-image.jpg".to_string(),
descriptor: first_descriptor,
};
let sources = &[first_imagesource];
assert_eq!(parse_a_srcset_attribute("small-image.jpg"), sources);
}
@ -62,23 +118,47 @@ fn without_descriptor() {
#[test]
fn two_descriptor() {
let empty_vec = Vec::new();
assert_eq!(parse_a_srcset_attribute("small-image.jpg 320w 1.1x"), empty_vec);
assert_eq!(
parse_a_srcset_attribute("small-image.jpg 320w 1.1x"),
empty_vec
);
}
#[test]
fn decimal_descriptor() {
let first_descriptor = Descriptor { wid: None, den: Some(2.2) };
let first_imagesource = ImageSource { url: "small-image.jpg".to_string(), descriptor: first_descriptor };
let first_descriptor = Descriptor {
wid: None,
den: Some(2.2),
};
let first_imagesource = ImageSource {
url: "small-image.jpg".to_string(),
descriptor: first_descriptor,
};
let sources = &[first_imagesource];
assert_eq!(parse_a_srcset_attribute("small-image.jpg 2.2x"), sources);
}
#[test]
fn different_descriptor() {
let first_descriptor = Descriptor { wid: Some(320), den: None };
let first_imagesource = ImageSource { url: "small-image.jpg".to_string(), descriptor: first_descriptor };
let second_descriptor = Descriptor { wid: None, den: Some(2.2) };
let second_imagesource = ImageSource { url: "medium-image.jpg".to_string(), descriptor: second_descriptor };
let first_descriptor = Descriptor {
wid: Some(320),
den: None,
};
let first_imagesource = ImageSource {
url: "small-image.jpg".to_string(),
descriptor: first_descriptor,
};
let second_descriptor = Descriptor {
wid: None,
den: Some(2.2),
};
let second_imagesource = ImageSource {
url: "medium-image.jpg".to_string(),
descriptor: second_descriptor,
};
let sources = &[first_imagesource, second_imagesource];
assert_eq!(parse_a_srcset_attribute("small-image.jpg 320w, medium-image.jpg 2.2x"), sources);
assert_eq!(
parse_a_srcset_attribute("small-image.jpg 320w, medium-image.jpg 2.2x"),
sources
);
}

View file

@ -2,19 +2,29 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#[cfg(test)] extern crate euclid;
#[cfg(test)] extern crate keyboard_types;
#[cfg(test)] extern crate script;
#[cfg(test)] extern crate servo_url;
#[cfg(test)] mod origin;
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;
#[cfg(test)] mod textinput;
#[cfg(test)] mod headers;
#[cfg(test)] mod htmlareaelement;
#[cfg(test)] mod htmlimageelement;
#[cfg(test)] mod timeranges;
#[cfg(test)]
extern crate euclid;
#[cfg(test)]
extern crate keyboard_types;
#[cfg(test)]
extern crate script;
#[cfg(test)]
extern crate servo_url;
#[cfg(test)]
mod headers;
#[cfg(test)]
mod htmlareaelement;
#[cfg(test)]
mod htmlimageelement;
#[cfg(test)]
mod origin;
#[cfg(all(test, target_pointer_width = "64"))]
mod size_of;
#[cfg(test)]
mod textinput;
#[cfg(test)]
mod timeranges;
/**
```compile_fail,E0277

View file

@ -6,29 +6,57 @@ use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
#[test]
fn same_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
let b = MutableOrigin::new(ServoUrl::parse("http://example.com/b.html").unwrap().origin());
let a = MutableOrigin::new(
ServoUrl::parse("http://example.com/a.html")
.unwrap()
.origin(),
);
let b = MutableOrigin::new(
ServoUrl::parse("http://example.com/b.html")
.unwrap()
.origin(),
);
assert!(a.same_origin(&b));
assert_eq!(a.is_tuple(), true);
}
#[test]
fn identical_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
let a = MutableOrigin::new(
ServoUrl::parse("http://example.com/a.html")
.unwrap()
.origin(),
);
assert!(a.same_origin(&a));
}
#[test]
fn cross_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
let b = MutableOrigin::new(ServoUrl::parse("http://example.org/b.html").unwrap().origin());
let a = MutableOrigin::new(
ServoUrl::parse("http://example.com/a.html")
.unwrap()
.origin(),
);
let b = MutableOrigin::new(
ServoUrl::parse("http://example.org/b.html")
.unwrap()
.origin(),
);
assert!(!a.same_origin(&b));
}
#[test]
fn clone_same_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
let b = MutableOrigin::new(ServoUrl::parse("http://example.com/b.html").unwrap().origin());
let a = MutableOrigin::new(
ServoUrl::parse("http://example.com/a.html")
.unwrap()
.origin(),
);
let b = MutableOrigin::new(
ServoUrl::parse("http://example.com/b.html")
.unwrap()
.origin(),
);
let c = b.clone();
assert!(a.same_origin(&c));
assert!(b.same_origin(&b));
@ -38,8 +66,16 @@ fn clone_same_origin() {
#[test]
fn clone_cross_origin() {
let a = MutableOrigin::new(ServoUrl::parse("http://example.com/a.html").unwrap().origin());
let b = MutableOrigin::new(ServoUrl::parse("http://example.org/b.html").unwrap().origin());
let a = MutableOrigin::new(
ServoUrl::parse("http://example.com/a.html")
.unwrap()
.origin(),
);
let b = MutableOrigin::new(
ServoUrl::parse("http://example.org/b.html")
.unwrap()
.origin(),
);
let c = b.clone();
assert!(!a.same_origin(&c));
assert!(b.same_origin(&c));

View file

@ -13,18 +13,25 @@ use script::test::DOMString;
use script::textinput::{TextInput, TextPoint, Selection, Lines, Direction, SelectionDirection};
fn text_input(lines: Lines, s: &str) -> TextInput<DummyClipboardContext> {
TextInput::new(lines,
DOMString::from(s),
DummyClipboardContext::new(""),
None,
None,
SelectionDirection::None)
TextInput::new(
lines,
DOMString::from(s),
DummyClipboardContext::new(""),
None,
None,
SelectionDirection::None,
)
}
#[test]
fn test_set_content_ignores_max_length() {
let mut textinput = TextInput::new(
Lines::Single, DOMString::from(""), DummyClipboardContext::new(""), Some(1), None, SelectionDirection::None
Lines::Single,
DOMString::from(""),
DummyClipboardContext::new(""),
Some(1),
None,
SelectionDirection::None,
);
textinput.set_content(DOMString::from("mozilla rocks"));
@ -64,7 +71,7 @@ fn test_textinput_when_inserting_multiple_lines_still_respects_max_length() {
DummyClipboardContext::new(""),
Some(17),
None,
SelectionDirection::None
SelectionDirection::None,
);
textinput.adjust_vertical(1, Selection::NotSelected);
@ -74,7 +81,8 @@ fn test_textinput_when_inserting_multiple_lines_still_respects_max_length() {
}
#[test]
fn test_textinput_when_content_is_already_longer_than_max_length_and_theres_no_selection_dont_insert_anything() {
fn test_textinput_when_content_is_already_longer_than_max_length_and_theres_no_selection_dont_insert_anything(
) {
let mut textinput = TextInput::new(
Lines::Single,
DOMString::from("abc"),
@ -90,7 +98,8 @@ fn test_textinput_when_content_is_already_longer_than_max_length_and_theres_no_s
}
#[test]
fn test_multi_line_textinput_with_maxlength_doesnt_allow_appending_characters_when_input_spans_lines() {
fn test_multi_line_textinput_with_maxlength_doesnt_allow_appending_characters_when_input_spans_lines(
) {
let mut textinput = TextInput::new(
Lines::Multiple,
DOMString::from("abc\nd"),
@ -106,7 +115,8 @@ fn test_multi_line_textinput_with_maxlength_doesnt_allow_appending_characters_wh
}
#[test]
fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_when_replacing_a_selection() {
fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_when_replacing_a_selection(
) {
let mut textinput = TextInput::new(
Lines::Single,
DOMString::from("abcde"),
@ -183,7 +193,8 @@ fn test_single_line_textinput_with_max_length_inside_char() {
}
#[test]
fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_after_max_length_is_reached() {
fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_after_max_length_is_reached(
) {
let mut textinput = TextInput::new(
Lines::Single,
DOMString::from("a"),
@ -430,23 +441,39 @@ fn test_navigation_keyboard_shortcuts() {
textinput.handle_keydown_aux(Key::ArrowLeft, Modifiers::META, true);
assert_eq!(textinput.edit_point().index, 0);
// Test that CTRL + ALT + E moves to the end of the current line also.
textinput.handle_keydown_aux(Key::Character("e".to_owned()), Modifiers::CONTROL | Modifiers::ALT, true);
textinput.handle_keydown_aux(
Key::Character("e".to_owned()),
Modifiers::CONTROL | Modifiers::ALT,
true,
);
assert_eq!(textinput.edit_point().index, 11);
// Test that CTRL + ALT + A moves to the beginning of the current line also.
textinput.handle_keydown_aux(Key::Character("a".to_owned()), Modifiers::CONTROL | Modifiers::ALT, true);
textinput.handle_keydown_aux(
Key::Character("a".to_owned()),
Modifiers::CONTROL | Modifiers::ALT,
true,
);
assert_eq!(textinput.edit_point().index, 0);
// Test that ALT + Right moves to the end of the word.
textinput.handle_keydown_aux(Key::ArrowRight, Modifiers::ALT, true);
assert_eq!(textinput.edit_point().index, 5);
// Test that CTRL + ALT + F moves to the end of the word also.
textinput.handle_keydown_aux(Key::Character("f".to_owned()), Modifiers::CONTROL | Modifiers::ALT, true);
textinput.handle_keydown_aux(
Key::Character("f".to_owned()),
Modifiers::CONTROL | Modifiers::ALT,
true,
);
assert_eq!(textinput.edit_point().index, 11);
// Test that ALT + Left moves to the end of the word.
textinput.handle_keydown_aux(Key::ArrowLeft, Modifiers::ALT, true);
assert_eq!(textinput.edit_point().index, 6);
// Test that CTRL + ALT + B moves to the end of the word also.
textinput.handle_keydown_aux(Key::Character("b".to_owned()), Modifiers::CONTROL | Modifiers::ALT, true);
textinput.handle_keydown_aux(
Key::Character("b".to_owned()),
Modifiers::CONTROL | Modifiers::ALT,
true,
);
assert_eq!(textinput.edit_point().index, 0);
}
@ -510,12 +537,14 @@ fn test_clipboard_paste() {
#[cfg(not(target_os = "macos"))]
const MODIFIERS: Modifiers = Modifiers::CONTROL;
let mut textinput = TextInput::new(Lines::Single,
DOMString::from("defg"),
DummyClipboardContext::new("abc"),
None,
None,
SelectionDirection::None);
let mut textinput = TextInput::new(
Lines::Single,
DOMString::from("defg"),
DummyClipboardContext::new("abc"),
None,
None,
SelectionDirection::None,
);
assert_eq!(textinput.get_content(), "defg");
assert_eq!(textinput.edit_point().index, 0);
textinput.handle_keydown_aux(Key::Character("v".to_owned()), MODIFIERS, false);
@ -547,7 +576,6 @@ fn test_textinput_cursor_position_correct_after_clearing_selection() {
textinput.adjust_horizontal_by_one(Direction::Backward, Selection::NotSelected);
assert_eq!(textinput.edit_point().index, 0);
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
// Multiline - Forward
@ -576,7 +604,6 @@ fn test_textinput_cursor_position_correct_after_clearing_selection() {
assert_eq!(textinput.edit_point().line, 0);
}
#[test]
fn test_textinput_set_selection_with_direction() {
let mut textinput = text_input(Lines::Single, "abcdef");
@ -592,7 +619,10 @@ fn test_textinput_set_selection_with_direction() {
textinput.set_selection_range(2, 6, SelectionDirection::Backward);
assert_eq!(textinput.edit_point().line, 0);
assert_eq!(textinput.edit_point().index, 2);
assert_eq!(textinput.selection_direction(), SelectionDirection::Backward);
assert_eq!(
textinput.selection_direction(),
SelectionDirection::Backward
);
assert!(textinput.selection_origin().is_some());
assert_eq!(textinput.selection_origin().unwrap().line, 0);
@ -617,7 +647,6 @@ fn test_textinput_set_selection_with_direction() {
assert!(textinput.selection_origin().is_some());
assert_eq!(textinput.selection_origin().unwrap().line, 0);
assert_eq!(textinput.selection_origin().unwrap().index, 0);
}
#[test]
@ -634,19 +663,28 @@ fn test_textinput_unicode_handling() {
fn test_selection_bounds() {
let mut textinput = text_input(Lines::Single, "abcdef");
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_origin_or_edit_point());
assert_eq!(
TextPoint { line: 0, index: 0 },
textinput.selection_origin_or_edit_point()
);
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_start());
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_end());
textinput.set_selection_range(2, 5, SelectionDirection::Forward);
assert_eq!(TextPoint { line: 0, index: 2 }, textinput.selection_origin_or_edit_point());
assert_eq!(
TextPoint { line: 0, index: 2 },
textinput.selection_origin_or_edit_point()
);
assert_eq!(TextPoint { line: 0, index: 2 }, textinput.selection_start());
assert_eq!(TextPoint { line: 0, index: 5 }, textinput.selection_end());
assert_eq!(2, textinput.selection_start_offset());
assert_eq!(5, textinput.selection_end_offset());
textinput.set_selection_range(3, 6, SelectionDirection::Backward);
assert_eq!(TextPoint { line: 0, index: 6 }, textinput.selection_origin_or_edit_point());
assert_eq!(
TextPoint { line: 0, index: 6 },
textinput.selection_origin_or_edit_point()
);
assert_eq!(TextPoint { line: 0, index: 3 }, textinput.selection_start());
assert_eq!(TextPoint { line: 0, index: 6 }, textinput.selection_end());
assert_eq!(3, textinput.selection_start_offset());
@ -654,8 +692,10 @@ fn test_selection_bounds() {
textinput = text_input(Lines::Multiple, "\n\n");
textinput.set_selection_range(0, 1, SelectionDirection::Forward);
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_origin_or_edit_point());
assert_eq!(
TextPoint { line: 0, index: 0 },
textinput.selection_origin_or_edit_point()
);
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_start());
assert_eq!(TextPoint { line: 1, index: 0 }, textinput.selection_end());
}