Skip to content

Commit

Permalink
Added syntax error position checks to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Lancaster committed Aug 25, 2020
1 parent 87bd988 commit fd1b36d
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions boa/src/exec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,15 +1296,16 @@ fn assignment_to_non_assignable() {
//
// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Assignment
// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
assert!(forward(&mut engine, "3 = 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 += 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 -= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 *= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 /= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 %= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 &= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 ^= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 |= 5").starts_with("Syntax Error: "));
let test_cases = [
"3 -= 5", "3 *= 5", "3 /= 5", "3 %= 5", "3 &= 5", "3 ^= 5", "3 |= 5", "3 += 5", "3 = 5",
];

for case in test_cases.iter() {
let string = forward(&mut engine, case);

assert!(string.starts_with("Syntax Error: "));
assert!(string.contains("1:3"));
}
}

#[test]
Expand All @@ -1314,9 +1315,14 @@ fn multicharacter_assignment_to_non_assignable() {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

assert!(forward(&mut engine, "3 **= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 <<= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 >>= 5").starts_with("Syntax Error: "));
let test_cases = ["3 **= 5", "3 <<= 5", "3 >>= 5"];

for case in test_cases.iter() {
let string = forward(&mut engine, case);

assert!(string.starts_with("Syntax Error: "));
assert!(string.contains("1:3"));
}
}

#[test]
Expand All @@ -1326,10 +1332,14 @@ fn multicharacter_bitwise_assignment_to_non_assignable() {
let mut engine = Interpreter::new(realm);

// Disabled - awaiting implementation.
assert!(forward(&mut engine, "3 >>>= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 &&= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 ||= 5").starts_with("Syntax Error: "));
assert!(forward(&mut engine, "3 ??= 5").starts_with("Syntax Error: "));
let test_cases = ["3 >>>= 5", "3 &&= 5", "3 ||= 5", "3 ??= 5"];

for case in test_cases.iter() {
let string = forward(&mut engine, case);

assert!(string.starts_with("Syntax Error: "));
assert!(string.contains("1:3"));
}
}

#[test]
Expand Down

0 comments on commit fd1b36d

Please sign in to comment.