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

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

@ -25,14 +25,14 @@ fn object_create_with_undefined() {
try { try {
const bar = Object.create(); const bar = Object.create();
} catch (err) { } catch (err) {
err.message err.toString()
} }
"#; "#;
let result = forward(&mut engine, init); let result = forward(&mut engine, init);
assert_eq!( assert_eq!(
result, 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 { try {
const bar = Object.create(5); const bar = Object.create(5);
} catch (err) { } catch (err) {
err.message err.toString()
} }
"#; "#;
let result = forward(&mut engine, init); 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] #[test]

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

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