From d49944d9a228e54c965d6603296fd7b059d2f04d Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Mon, 15 Oct 2018 22:12:29 +0100 Subject: [PATCH] adding some tests --- src/lib/js/function.rs | 2 +- src/lib/js/object.rs | 2 +- src/lib/js/value.rs | 4 ++-- tests/value_test.rs | 25 +++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tests/value_test.rs diff --git a/src/lib/js/function.rs b/src/lib/js/function.rs index 995670b218..20af23e40e 100644 --- a/src/lib/js/function.rs +++ b/src/lib/js/function.rs @@ -7,7 +7,7 @@ pub type FunctionData = fn(Vec, Value, Value, Value) -> ResultValue; /// https://tc39.github.io/ecma262/#sec-terms-and-definitions-function /// In our implementation, Function is extending Object by holding an object field which some extra data -#[derive(Trace, Finalize)] +#[derive(Trace, Finalize, Debug)] pub struct Function { /// The fields associated with the function pub object: ObjectData, diff --git a/src/lib/js/object.rs b/src/lib/js/object.rs index 67c7bfc2d1..776d2695a9 100644 --- a/src/lib/js/object.rs +++ b/src/lib/js/object.rs @@ -8,7 +8,7 @@ pub type ObjectData = HashMap; /// A Javascript Property AKA The Property Descriptor /// [[SPEC] - The Property Descriptor Specification Type](https://tc39.github.io/ecma262/#sec-property-descriptor-specification-type) /// [[SPEC] - Default Attribute Values](https://tc39.github.io/ecma262/#table-4) -#[derive(Trace, Finalize, Clone)] +#[derive(Trace, Finalize, Clone, Debug)] pub struct Property { /// If the type of this can be changed and this can be deleted pub configurable: bool, diff --git a/src/lib/js/value.rs b/src/lib/js/value.rs index 997e4af126..409fb8d1c8 100644 --- a/src/lib/js/value.rs +++ b/src/lib/js/value.rs @@ -14,14 +14,14 @@ use std::str::FromStr; /// The result of a Javascript expression is represented like this so it can succeed (`Ok`) or fail (`Err`) pub type ResultValue = Result; /// A Garbage-collected Javascript value as represented in the interpreter -#[derive(Trace, Finalize, Clone)] +#[derive(Trace, Finalize, Clone, Debug)] pub struct Value { /// The garbage-collected pointer pub ptr: Gc, } /// A Javascript value -#[derive(Trace, Finalize)] +#[derive(Trace, Finalize, Debug)] pub enum ValueData { /// `null` - A null value, for when a value doesn't exist Null, diff --git a/tests/value_test.rs b/tests/value_test.rs new file mode 100644 index 0000000000..b6b5f6de65 --- /dev/null +++ b/tests/value_test.rs @@ -0,0 +1,25 @@ +extern crate boa; +use boa::js::value::*; + +#[test] +fn check_is_object() { + let val = Value::new_obj(None); + assert_eq!(val.is_object(), true); +} + +#[test] +fn check_string_to_value() { + let s = String::from("Hello"); + let v = s.to_value(); + assert_eq!(v.is_string(), true); + assert_eq!(v.is_null(), false); +} + +#[test] +fn check_get_set_field() { + let obj = Value::new_obj(None); + // Create string and convert it to a Value + let s = String::from("bar").to_value(); + obj.set_field_slice("foo", s); + assert_eq!(obj.get_field_slice("foo").to_string(), "bar"); +}