mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
wrap tests with #[cfg(test)]
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
This commit is contained in:
parent
d18000fee8
commit
be6105a202
6 changed files with 455 additions and 431 deletions
|
@ -130,8 +130,12 @@ impl From<PrefValue> for [f64; 4] {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pref_value_from_str() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::PrefValue;
|
||||
|
||||
#[test]
|
||||
fn test_pref_value_from_str() {
|
||||
let value = PrefValue::from_booleanish_str("21");
|
||||
assert_eq!(value, PrefValue::Int(21));
|
||||
|
||||
|
@ -146,4 +150,5 @@ fn test_pref_value_from_str() {
|
|||
|
||||
let value = PrefValue::from_booleanish_str("true");
|
||||
assert_eq!(value, PrefValue::Bool(true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,8 +81,10 @@ impl DevtoolsOuterWindowId {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub(crate) fn test_id_map() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
pub(crate) fn test_id_map() {
|
||||
use std::thread;
|
||||
|
||||
use base::id::{PipelineNamespace, PipelineNamespaceId};
|
||||
|
@ -172,4 +174,5 @@ pub(crate) fn test_id_map() {
|
|||
|| PipelineId::new(),
|
||||
|id_map: &mut IdMap, id| id_map.outer_window_id(id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,8 +54,10 @@ impl LineBreaker {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_linebreaker_ranges() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_linebreaker_ranges() {
|
||||
let linebreaker = LineBreaker::new("abc def");
|
||||
assert_eq!(linebreaker.linebreaks, [4, 7]);
|
||||
assert_eq!(
|
||||
|
@ -93,10 +95,10 @@ fn test_linebreaker_ranges() {
|
|||
linebreaker.linebreaks_in_range_after_current_offset(5..2);
|
||||
})
|
||||
.expect_err("Reversed range should cause an assertion failure.");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_linebreaker_stateful_advance() {
|
||||
#[test]
|
||||
fn test_linebreaker_stateful_advance() {
|
||||
let mut linebreaker = LineBreaker::new("abc d def");
|
||||
assert_eq!(linebreaker.linebreaks, [4, 6, 9]);
|
||||
assert!(linebreaker.advance_to_linebreaks_in_range(0..7) == &[4, 6]);
|
||||
|
@ -117,4 +119,5 @@ fn test_linebreaker_stateful_advance() {
|
|||
linebreaker.advance_to_linebreaks_in_range(2..0);
|
||||
})
|
||||
.expect_err("Reversed range should cause an assertion failure.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -277,7 +277,9 @@ impl ProgressiveWebMetrics {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn test_metrics() -> ProgressiveWebMetrics {
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_metrics() -> ProgressiveWebMetrics {
|
||||
let (sender, _) = ipc_channel::ipc::channel().unwrap();
|
||||
let profiler_chan = ProfilerChan(sender);
|
||||
let mut metrics = ProgressiveWebMetrics::new(
|
||||
|
@ -294,10 +296,10 @@ fn test_metrics() -> ProgressiveWebMetrics {
|
|||
metrics.set_navigation_start(CrossProcessInstant::now());
|
||||
|
||||
metrics
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_dcl() {
|
||||
#[test]
|
||||
fn test_set_dcl() {
|
||||
let metrics = test_metrics();
|
||||
metrics.maybe_set_tti(InteractiveFlag::DOMContentLoaded);
|
||||
let dcl = metrics.dom_content_loaded();
|
||||
|
@ -307,10 +309,10 @@ fn test_set_dcl() {
|
|||
metrics.maybe_set_tti(InteractiveFlag::DOMContentLoaded);
|
||||
assert_eq!(metrics.dom_content_loaded(), dcl);
|
||||
assert_eq!(metrics.get_tti(), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_mta() {
|
||||
#[test]
|
||||
fn test_set_mta() {
|
||||
let metrics = test_metrics();
|
||||
let now = CrossProcessInstant::now();
|
||||
metrics.maybe_set_tti(InteractiveFlag::TimeToInteractive(now));
|
||||
|
@ -324,10 +326,10 @@ fn test_set_mta() {
|
|||
));
|
||||
assert_eq!(metrics.main_thread_available(), main_thread_available_time);
|
||||
assert_eq!(metrics.get_tti(), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_tti_dcl() {
|
||||
#[test]
|
||||
fn test_set_tti_dcl() {
|
||||
let metrics = test_metrics();
|
||||
let now = CrossProcessInstant::now();
|
||||
metrics.maybe_set_tti(InteractiveFlag::TimeToInteractive(now));
|
||||
|
@ -339,10 +341,10 @@ fn test_set_tti_dcl() {
|
|||
assert!(dom_content_loaded_time.is_some());
|
||||
|
||||
assert_eq!(metrics.get_tti(), dom_content_loaded_time);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_tti_mta() {
|
||||
#[test]
|
||||
fn test_set_tti_mta() {
|
||||
let metrics = test_metrics();
|
||||
metrics.maybe_set_tti(InteractiveFlag::DOMContentLoaded);
|
||||
let dcl = metrics.dom_content_loaded();
|
||||
|
@ -354,18 +356,19 @@ fn test_set_tti_mta() {
|
|||
assert!(mta.is_some());
|
||||
|
||||
assert_eq!(metrics.get_tti(), mta);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_first_paint_setter() {
|
||||
#[test]
|
||||
fn test_first_paint_setter() {
|
||||
let metrics = test_metrics();
|
||||
metrics.set_first_paint(CrossProcessInstant::now(), false);
|
||||
assert!(metrics.first_paint().is_some());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_first_contentful_paint_setter() {
|
||||
#[test]
|
||||
fn test_first_contentful_paint_setter() {
|
||||
let metrics = test_metrics();
|
||||
metrics.set_first_contentful_paint(CrossProcessInstant::now(), false);
|
||||
assert!(metrics.first_contentful_paint().is_some());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -590,8 +590,10 @@ pub trait WebViewDelegate {
|
|||
pub(crate) struct DefaultWebViewDelegate;
|
||||
impl WebViewDelegate for DefaultWebViewDelegate {}
|
||||
|
||||
#[test]
|
||||
fn test_allow_deny_request() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_allow_deny_request() {
|
||||
use ipc_channel::ipc;
|
||||
|
||||
use crate::ServoErrorChannel;
|
||||
|
@ -648,10 +650,10 @@ fn test_allow_deny_request() {
|
|||
drop(request);
|
||||
assert!(errors.try_recv().is_none());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_authentication_request() {
|
||||
#[test]
|
||||
fn test_authentication_request() {
|
||||
use ipc_channel::ipc;
|
||||
|
||||
use crate::ServoErrorChannel;
|
||||
|
@ -697,10 +699,10 @@ fn test_authentication_request() {
|
|||
drop(receiver);
|
||||
drop(request);
|
||||
assert!(errors.try_recv().is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_web_resource_load() {
|
||||
#[test]
|
||||
fn test_web_resource_load() {
|
||||
use http::{HeaderMap, Method, StatusCode};
|
||||
use ipc_channel::ipc;
|
||||
|
||||
|
@ -714,7 +716,9 @@ fn test_web_resource_load() {
|
|||
is_redirect: false,
|
||||
};
|
||||
let web_resource_response = || {
|
||||
WebResourceResponse::new(Url::parse("https://diffie.test").expect("Guaranteed by argument"))
|
||||
WebResourceResponse::new(
|
||||
Url::parse("https://diffie.test").expect("Guaranteed by argument"),
|
||||
)
|
||||
.status_code(StatusCode::IM_A_TEAPOT)
|
||||
};
|
||||
|
||||
|
@ -785,4 +789,5 @@ fn test_web_resource_load() {
|
|||
drop(receiver);
|
||||
drop(request);
|
||||
assert!(errors.try_recv().is_none());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,8 +44,12 @@ pub fn is_cjk(codepoint: char) -> bool {
|
|||
unicode_plane(codepoint) == 2 || unicode_plane(codepoint) == 3
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_cjk() {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::is_cjk;
|
||||
|
||||
#[test]
|
||||
fn test_is_cjk() {
|
||||
// Test characters from different CJK blocks
|
||||
assert_eq!(is_cjk('〇'), true);
|
||||
assert_eq!(is_cjk('㐀'), true);
|
||||
|
@ -61,4 +65,5 @@ fn test_is_cjk() {
|
|||
assert_eq!(is_cjk('a'), false);
|
||||
assert_eq!(is_cjk('🙂'), false);
|
||||
assert_eq!(is_cjk('©'), false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue