Skip to content

Commit

Permalink
The parser is now modular.
Browse files Browse the repository at this point in the history
  • Loading branch information
Razican committed Apr 18, 2020
1 parent eb020d7 commit bbc2269
Show file tree
Hide file tree
Showing 38 changed files with 3,887 additions and 2,472 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion boa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gc = "0.3.3"
gc_derive = "0.3.2"
serde_json = "1.0.51"
rand = "0.7.3"
regex = "1.3.6"
regex = "1.3.7"

# Optional Dependencies
wasm-bindgen = { version = "0.2.60", optional = true }
Expand Down
124 changes: 63 additions & 61 deletions boa/src/builtins/math/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::float_cmp)]

use crate::{exec::Executor, forward, forward_val, realm::Realm};
use std::f64;

Expand All @@ -15,8 +17,8 @@ fn abs() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward_val(&mut engine, "b").unwrap();

assert_eq!(a.to_num(), f64::from(2.0));
assert_eq!(b.to_num(), f64::from(6.655_559_999_999_999_5));
assert_eq!(a.to_num(), 2.0);
assert_eq!(b.to_num(), 6.655_559_999_999_999_5);
}

#[test]
Expand All @@ -37,9 +39,9 @@ fn acos() {
let c = forward_val(&mut engine, "c").unwrap();
let d = forward(&mut engine, "d");

assert_eq!(a.to_num(), f64::from(0.643_501_108_793_284_3));
assert_eq!(a.to_num(), 0.643_501_108_793_284_3);
assert_eq!(b, String::from("NaN"));
assert_eq!(c.to_num(), f64::from(0));
assert_eq!(c.to_num(), 0_f64);
assert_eq!(d, String::from("NaN"));
}

Expand All @@ -59,7 +61,7 @@ fn acosh() {
let b = forward(&mut engine, "b");
let c = forward(&mut engine, "c");

assert_eq!(a.to_num(), f64::from(1.316_957_896_924_816_6));
assert_eq!(a.to_num(), 1.316_957_896_924_816_6);
assert_eq!(b, String::from("NaN"));
assert_eq!(c, String::from("NaN"));
}
Expand All @@ -78,7 +80,7 @@ fn asin() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward(&mut engine, "b");

assert_eq!(a.to_num(), f64::from(0.643_501_108_793_284_4));
assert_eq!(a.to_num(), 0.643_501_108_793_284_4);
assert_eq!(b, String::from("NaN"));
}

Expand All @@ -96,8 +98,8 @@ fn asinh() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward_val(&mut engine, "b").unwrap();

assert_eq!(a.to_num(), f64::from(0.881_373_587_019_542_9));
assert_eq!(b.to_num(), f64::from(0));
assert_eq!(a.to_num(), 0.881_373_587_019_542_9);
assert_eq!(b.to_num(), 0_f64);
}

#[test]
Expand All @@ -116,8 +118,8 @@ fn atan() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(0.785_398_163_397_448_3));
assert_eq!(b.to_num(), f64::from(0));
assert_eq!(a.to_num(), f64::consts::FRAC_PI_4);
assert_eq!(b.to_num(), 0_f64);
assert_eq!(c.to_num(), f64::from(-0));
}

Expand All @@ -135,8 +137,8 @@ fn atan2() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward_val(&mut engine, "b").unwrap();

assert_eq!(a.to_num(), f64::from(1.405_647_649_380_269_9));
assert_eq!(b.to_num(), f64::from(0.165_148_677_414_626_83));
assert_eq!(a.to_num(), 1.405_647_649_380_269_9);
assert_eq!(b.to_num(), 0.165_148_677_414_626_83);
}

#[test]
Expand All @@ -155,9 +157,9 @@ fn cbrt() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(4));
assert_eq!(b.to_num(), f64::from(-1));
assert_eq!(c.to_num(), f64::from(1));
assert_eq!(a.to_num(), 4_f64);
assert_eq!(b.to_num(), -1_f64);
assert_eq!(c.to_num(), 1_f64);
}

#[test]
Expand All @@ -176,9 +178,9 @@ fn ceil() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(2));
assert_eq!(b.to_num(), f64::from(4));
assert_eq!(c.to_num(), f64::from(-7));
assert_eq!(a.to_num(), 2_f64);
assert_eq!(b.to_num(), 4_f64);
assert_eq!(c.to_num(), -7_f64);
}

#[test]
Expand All @@ -195,8 +197,8 @@ fn cos() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward_val(&mut engine, "b").unwrap();

assert_eq!(a.to_num(), f64::from(1));
assert_eq!(b.to_num(), f64::from(0.540_302_305_868_139_8));
assert_eq!(a.to_num(), 1_f64);
assert_eq!(b.to_num(), 0.540_302_305_868_139_8);
}

#[test]
Expand All @@ -215,9 +217,9 @@ fn cosh() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(1));
assert_eq!(b.to_num(), f64::from(1.543_080_634_815_243_7));
assert_eq!(c.to_num(), f64::from(1.543_080_634_815_243_7));
assert_eq!(a.to_num(), 1_f64);
assert_eq!(b.to_num(), 1.543_080_634_815_243_7);
assert_eq!(c.to_num(), 1.543_080_634_815_243_7);
}

#[test]
Expand All @@ -236,9 +238,9 @@ fn exp() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(1));
assert_eq!(b.to_num(), f64::from(0.367_879_441_171_442_33));
assert_eq!(c.to_num(), f64::from(7.389_056_098_930_65));
assert_eq!(a.to_num(), 1_f64);
assert_eq!(b.to_num(), 0.367_879_441_171_442_33);
assert_eq!(c.to_num(), 7.389_056_098_930_65);
}

#[test]
Expand All @@ -257,9 +259,9 @@ fn floor() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(1));
assert_eq!(b.to_num(), f64::from(-4));
assert_eq!(c.to_num(), f64::from(3));
assert_eq!(a.to_num(), 1_f64);
assert_eq!(b.to_num(), -4_f64);
assert_eq!(c.to_num(), 3_f64);
}

#[test]
Expand All @@ -278,8 +280,8 @@ fn log() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward(&mut engine, "c");

assert_eq!(a.to_num(), f64::from(0));
assert_eq!(b.to_num(), f64::from(2.302_585_092_994_046));
assert_eq!(a.to_num(), 0_f64);
assert_eq!(b.to_num(), f64::consts::LN_10);
assert_eq!(c, String::from("NaN"));
}

Expand All @@ -299,8 +301,8 @@ fn log10() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward(&mut engine, "c");

assert_eq!(a.to_num(), f64::from(0.301_029_995_663_981_2));
assert_eq!(b.to_num(), f64::from(0));
assert_eq!(a.to_num(), 0.301_029_995_663_981_2);
assert_eq!(b.to_num(), 0_f64);
assert_eq!(c, String::from("NaN"));
}

Expand All @@ -320,8 +322,8 @@ fn log2() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward(&mut engine, "c");

assert_eq!(a.to_num(), f64::from(1.584_962_500_721_156));
assert_eq!(b.to_num(), f64::from(0));
assert_eq!(a.to_num(), 1.584_962_500_721_156);
assert_eq!(b.to_num(), 0_f64);
assert_eq!(c, String::from("NaN"));
}

Expand All @@ -341,9 +343,9 @@ fn max() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(20));
assert_eq!(b.to_num(), f64::from(-10));
assert_eq!(c.to_num(), f64::from(20));
assert_eq!(a.to_num(), 20_f64);
assert_eq!(b.to_num(), -10_f64);
assert_eq!(c.to_num(), 20_f64);
}

#[test]
Expand All @@ -362,9 +364,9 @@ fn min() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(10));
assert_eq!(b.to_num(), f64::from(-20));
assert_eq!(c.to_num(), f64::from(-10));
assert_eq!(a.to_num(), 10_f64);
assert_eq!(b.to_num(), -20_f64);
assert_eq!(c.to_num(), -10_f64);
}

#[test]
Expand All @@ -385,10 +387,10 @@ fn pow() {
let c = forward_val(&mut engine, "c").unwrap();
let d = forward_val(&mut engine, "d").unwrap();

assert_eq!(a.to_num(), f64::from(1024));
assert_eq!(b.to_num(), f64::from(49));
assert_eq!(c.to_num(), f64::from(2.0));
assert_eq!(d.to_num(), f64::from(0.020_408_163_265_306_12));
assert_eq!(a.to_num(), 1_024_f64);
assert_eq!(b.to_num(), 49_f64);
assert_eq!(c.to_num(), 2.0);
assert_eq!(d.to_num(), 0.020_408_163_265_306_12);
}

#[test]
Expand All @@ -405,8 +407,8 @@ fn round() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward_val(&mut engine, "b").unwrap();

assert_eq!(a.to_num(), f64::from(21.0));
assert_eq!(b.to_num(), f64::from(-20.0));
assert_eq!(a.to_num(), 21.0);
assert_eq!(b.to_num(), -20.0);
}

#[test]
Expand All @@ -425,9 +427,9 @@ fn sign() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(1));
assert_eq!(b.to_num(), f64::from(-1));
assert_eq!(c.to_num(), f64::from(0));
assert_eq!(a.to_num(), 1_f64);
assert_eq!(b.to_num(), -1_f64);
assert_eq!(c.to_num(), 0_f64);
}

#[test]
Expand All @@ -444,8 +446,8 @@ fn sin() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward_val(&mut engine, "b").unwrap();

assert_eq!(a.to_num(), f64::from(0));
assert_eq!(b.to_num(), f64::from(0.841_470_984_807_896_5));
assert_eq!(a.to_num(), 0_f64);
assert_eq!(b.to_num(), 0.841_470_984_807_896_5);
}

#[test]
Expand All @@ -462,8 +464,8 @@ fn sinh() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward_val(&mut engine, "b").unwrap();

assert_eq!(a.to_num(), f64::from(0));
assert_eq!(b.to_num(), f64::from(1.175_201_193_643_801_4));
assert_eq!(a.to_num(), 0_f64);
assert_eq!(b.to_num(), 1.175_201_193_643_801_4);
}

#[test]
Expand All @@ -482,9 +484,9 @@ fn sqrt() {
let b = forward_val(&mut engine, "b").unwrap();
let c = forward_val(&mut engine, "c").unwrap();

assert_eq!(a.to_num(), f64::from(0));
assert_eq!(b.to_num(), f64::from(1.414_213_562_373_095_1));
assert_eq!(c.to_num(), f64::from(3));
assert_eq!(a.to_num(), 0_f64);
assert_eq!(b.to_num(), f64::consts::SQRT_2);
assert_eq!(c.to_num(), 3_f64);
}

// TODO: Precision is always off between ci and local. We proably need a better way to compare floats anyways
Expand Down Expand Up @@ -518,8 +520,8 @@ fn tanh() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward_val(&mut engine, "b").unwrap();

assert_eq!(a.to_num(), f64::from(0.761_594_155_955_764_9));
assert_eq!(b.to_num(), f64::from(0));
assert_eq!(a.to_num(), 0.761_594_155_955_764_9);
assert_eq!(b.to_num(), 0_f64);
}

#[test]
Expand All @@ -536,6 +538,6 @@ fn trunc() {
let a = forward_val(&mut engine, "a").unwrap();
let b = forward_val(&mut engine, "b").unwrap();

assert_eq!(a.to_num(), f64::from(13));
assert_eq!(b.to_num(), f64::from(0));
assert_eq!(a.to_num(), 13_f64);
assert_eq!(b.to_num(), 0_f64);
}
27 changes: 14 additions & 13 deletions boa/src/builtins/number/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::float_cmp)]

use super::*;
use crate::{builtins::value::ValueData, exec::Executor, forward, forward_val, realm::Realm};
use std::f64;

#[test]
fn check_number_constructor_is_function() {
Expand Down Expand Up @@ -34,14 +35,14 @@ fn call_number() {
let invalid_nan = forward_val(&mut engine, "invalid_nan").unwrap();
let from_exp = forward_val(&mut engine, "from_exp").unwrap();

assert_eq!(default_zero.to_num(), f64::from(0));
assert_eq!(int_one.to_num(), f64::from(1));
assert_eq!(float_two.to_num(), f64::from(2.1));
assert_eq!(str_three.to_num(), f64::from(3.2));
assert_eq!(bool_one.to_num(), f64::from(1));
assert_eq!(default_zero.to_num(), 0_f64);
assert_eq!(int_one.to_num(), 1_f64);
assert_eq!(float_two.to_num(), 2.1);
assert_eq!(str_three.to_num(), 3.2);
assert_eq!(bool_one.to_num(), 1_f64);
assert!(invalid_nan.to_num().is_nan());
assert_eq!(bool_zero.to_num(), f64::from(0));
assert_eq!(from_exp.to_num(), f64::from(234));
assert_eq!(bool_zero.to_num(), 0_f64);
assert_eq!(from_exp.to_num(), 234_f64);
}

#[test]
Expand Down Expand Up @@ -205,9 +206,9 @@ fn value_of() {
let exp_val = forward_val(&mut engine, "exp_val").unwrap();
let neg_val = forward_val(&mut engine, "neg_val").unwrap();

assert_eq!(default_val.to_num(), f64::from(0));
assert_eq!(int_val.to_num(), f64::from(123));
assert_eq!(float_val.to_num(), f64::from(1.234));
assert_eq!(exp_val.to_num(), f64::from(12000));
assert_eq!(neg_val.to_num(), f64::from(-12000));
assert_eq!(default_val.to_num(), 0_f64);
assert_eq!(int_val.to_num(), 123_f64);
assert_eq!(float_val.to_num(), 1.234);
assert_eq!(exp_val.to_num(), 12_000_f64);
assert_eq!(neg_val.to_num(), -12_000_f64);
}
Loading

0 comments on commit bbc2269

Please sign in to comment.