Browse Source

adding some tests

pull/5/head
Jason Williams 6 years ago
parent
commit
d49944d9a2
  1. 2
      src/lib/js/function.rs
  2. 2
      src/lib/js/object.rs
  3. 4
      src/lib/js/value.rs
  4. 25
      tests/value_test.rs

2
src/lib/js/function.rs

@ -7,7 +7,7 @@ pub type FunctionData = fn(Vec<Value>, Value, Value, Value) -> ResultValue;
/// https://tc39.github.io/ecma262/#sec-terms-and-definitions-function /// 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 /// 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 { pub struct Function {
/// The fields associated with the function /// The fields associated with the function
pub object: ObjectData, pub object: ObjectData,

2
src/lib/js/object.rs

@ -8,7 +8,7 @@ pub type ObjectData = HashMap<String, Property>;
/// A Javascript Property AKA The Property Descriptor /// A Javascript Property AKA The Property Descriptor
/// [[SPEC] - The Property Descriptor Specification Type](https://tc39.github.io/ecma262/#sec-property-descriptor-specification-type) /// [[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) /// [[SPEC] - Default Attribute Values](https://tc39.github.io/ecma262/#table-4)
#[derive(Trace, Finalize, Clone)] #[derive(Trace, Finalize, Clone, Debug)]
pub struct Property { pub struct Property {
/// If the type of this can be changed and this can be deleted /// If the type of this can be changed and this can be deleted
pub configurable: bool, pub configurable: bool,

4
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`) /// The result of a Javascript expression is represented like this so it can succeed (`Ok`) or fail (`Err`)
pub type ResultValue = Result<Value, Value>; pub type ResultValue = Result<Value, Value>;
/// A Garbage-collected Javascript value as represented in the interpreter /// A Garbage-collected Javascript value as represented in the interpreter
#[derive(Trace, Finalize, Clone)] #[derive(Trace, Finalize, Clone, Debug)]
pub struct Value { pub struct Value {
/// The garbage-collected pointer /// The garbage-collected pointer
pub ptr: Gc<ValueData>, pub ptr: Gc<ValueData>,
} }
/// A Javascript value /// A Javascript value
#[derive(Trace, Finalize)] #[derive(Trace, Finalize, Debug)]
pub enum ValueData { pub enum ValueData {
/// `null` - A null value, for when a value doesn't exist /// `null` - A null value, for when a value doesn't exist
Null, Null,

25
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");
}
Loading…
Cancel
Save