Browse Source

Ensure tests test error type (#563)

pull/573/head
joshwd36 4 years ago committed by GitHub
parent
commit
df80ee005b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      boa/src/builtins/bigint/tests.rs
  2. 11
      boa/src/builtins/object/tests.rs
  3. 8
      boa/src/exec/operator/tests.rs
  4. 12
      boa/src/exec/tests.rs

29
boa/src/builtins/bigint/tests.rs

@ -1,4 +1,4 @@
use crate::{forward, forward_val, Interpreter, Realm};
use crate::{forward, Interpreter, Realm};
#[test]
fn equality() {
@ -86,15 +86,16 @@ fn bigint_function_conversion_from_rational_with_fractional_part() {
let mut engine = Interpreter::new(realm);
let scenario = r#"
var x = false;
try {
BigInt(0.1);
} catch (e) {
x = true;
e.toString();
}
"#;
forward_val(&mut engine, scenario).unwrap();
assert_eq!(forward(&mut engine, "x"), "true");
assert_eq!(
forward(&mut engine, scenario),
"TypeError: The number 0.1 cannot be converted to a BigInt because it is not an integer"
);
}
#[test]
@ -103,15 +104,16 @@ fn bigint_function_conversion_from_null() {
let mut engine = Interpreter::new(realm);
let scenario = r#"
var x = false;
try {
BigInt(null);
} catch (e) {
x = true;
e.toString();
}
"#;
forward_val(&mut engine, scenario).unwrap();
assert_eq!(forward(&mut engine, "x"), "true");
assert_eq!(
forward(&mut engine, scenario),
"TypeError: cannot convert null to a BigInt"
);
}
#[test]
@ -120,15 +122,16 @@ fn bigint_function_conversion_from_undefined() {
let mut engine = Interpreter::new(realm);
let scenario = r#"
var x = false;
try {
BigInt(undefined);
} catch (e) {
x = true;
e.toString();
}
"#;
forward_val(&mut engine, scenario).unwrap();
assert_eq!(forward(&mut engine, "x"), "true");
assert_eq!(
forward(&mut engine, scenario),
"TypeError: cannot convert undefined to a BigInt"
);
}
#[test]

11
boa/src/builtins/object/tests.rs

@ -25,14 +25,14 @@ fn object_create_with_undefined() {
try {
const bar = Object.create();
} catch (err) {
err.message
err.toString()
}
"#;
let result = forward(&mut engine, init);
assert_eq!(
result,
"Object prototype may only be an Object or null: undefined"
"TypeError: Object prototype may only be an Object or null: undefined"
);
}
@ -45,12 +45,15 @@ fn object_create_with_number() {
try {
const bar = Object.create(5);
} catch (err) {
err.message
err.toString()
}
"#;
let result = forward(&mut engine, init);
assert_eq!(result, "Object prototype may only be an Object or null: 5");
assert_eq!(
result,
"TypeError: Object prototype may only be an Object or null: 5"
);
}
#[test]

8
boa/src/exec/operator/tests.rs

@ -6,11 +6,11 @@ fn assignmentoperator_lhs_not_defined() {
try {
a += 5
} catch (err) {
err.message
err.toString()
}
"#;
assert_eq!(&exec(scenario), "a is not defined");
assert_eq!(&exec(scenario), "ReferenceError: a is not defined");
}
#[test]
@ -20,9 +20,9 @@ fn assignmentoperator_rhs_throws_error() {
let a;
a += b
} catch (err) {
err.message
err.toString()
}
"#;
assert_eq!(&exec(scenario), "b is not defined");
assert_eq!(&exec(scenario), "ReferenceError: b is not defined");
}

12
boa/src/exec/tests.rs

@ -1142,24 +1142,24 @@ fn not_a_function() {
try {
a();
} catch(e) {
e.message
e.toString()
}
"#;
assert_eq!(forward(&mut engine, scenario), "not a function");
assert_eq!(forward(&mut engine, scenario), "TypeError: not a function");
let scenario = r#"
try {
a.a();
} catch(e) {
e.message
e.toString()
}
"#;
assert_eq!(forward(&mut engine, scenario), "not a function");
assert_eq!(forward(&mut engine, scenario), "TypeError: not a function");
let scenario = r#"
try {
b();
} catch(e) {
e.message
e.toString()
}
"#;
assert_eq!(forward(&mut engine, scenario), "not a function");
assert_eq!(forward(&mut engine, scenario), "TypeError: not a function");
}

Loading…
Cancel
Save