Skip to content

Commit

Permalink
add failing test icu_collator
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Feb 12, 2021
1 parent b7bffb8 commit ce43805
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fslock = "0.1"

[dev-dependencies]
trybuild = "1.0.35"
align-data = "0.1.0"

[[example]]
name = "hello_world"
Expand Down
45 changes: 23 additions & 22 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Copyright 2019-2020 the Deno authors. All rights reserved. MIT license.

#[macro_use]
extern crate lazy_static;

use lazy_static::lazy_static;
use std::any::type_name;
use std::cell::RefCell;
use std::collections::hash_map::DefaultHasher;
Expand All @@ -11,16 +8,11 @@ use std::ffi::c_void;
use std::hash::Hash;
use std::ptr::NonNull;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;

use rusty_v8 as v8;
// TODO(piscisaureus): Ideally there would be no need to import this trait.
use v8::MapFnTo;

lazy_static! {
static ref INIT_LOCK: Mutex<u32> = Mutex::new(0);
}

#[must_use]
struct SetupGuard {}

Expand All @@ -31,13 +23,17 @@ impl Drop for SetupGuard {
}

fn setup() -> SetupGuard {
let mut g = INIT_LOCK.lock().unwrap();
*g += 1;
if *g == 1 {
static START: std::sync::Once = std::sync::Once::new();
START.call_once(|| {
assert!(v8::icu::set_common_data(align_data::include_aligned!(
align_data::Align16,
"../third_party/icu/common/icudtl.dat"
))
.is_ok());
v8::V8::set_flags_from_string("--expose_gc --harmony-import-assertions");
v8::V8::initialize_platform(v8::new_default_platform().unwrap());
v8::V8::initialize();
}
});
SetupGuard {}
}

Expand Down Expand Up @@ -4718,13 +4714,8 @@ fn prepare_stack_trace_callback() {
}
}

const ICU_DATA: &[u8; 10413584] =
include_bytes!("../third_party/icu/common/icudtl.dat");

#[test]
fn icu_date() {
assert!(v8::icu::set_common_data(ICU_DATA).is_ok());

let _setup_guard = setup();
let isolate = &mut v8::Isolate::new(Default::default());
{
Expand All @@ -4748,14 +4739,12 @@ fn icu_date() {

#[test]
fn icu_set_common_data_fail() {
const BAD_DATA: &[u8; 3] = &[1, 2, 3];
assert!(v8::icu::set_common_data(BAD_DATA).is_err());
let _setup_guard = setup();
assert!(v8::icu::set_common_data(&[1, 2, 3]).is_err());
}

#[test]
fn icu_format() {
assert!(v8::icu::set_common_data(ICU_DATA).is_ok());

let _setup_guard = setup();
let isolate = &mut v8::Isolate::new(Default::default());
{
Expand All @@ -4773,3 +4762,15 @@ fn icu_format() {
assert!(value.strict_equals(currency_jpy_val.into()));
}
}

#[test]
fn icu_collator() {
let _setup_guard = setup();
let isolate = &mut v8::Isolate::new(Default::default());
let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
let source = v8::String::new(scope, "new Intl.Collator('en-US')").unwrap();
let script = v8::Script::compile(scope, source, None).unwrap();
assert!(script.run(scope).is_some());
}

0 comments on commit ce43805

Please sign in to comment.