Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure tests test error type #563

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions boa/src/builtins/bigint/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{forward, forward_val, Interpreter, Realm};
use crate::{forward, Interpreter, Realm};

#[test]
fn equality() {
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down
11 changes: 7 additions & 4 deletions boa/src/builtins/object/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}

Expand All @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions boa/src/exec/operator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 changes: 6 additions & 6 deletions boa/src/exec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}