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

Cleanup and added test for String.prototype.concat #538

Merged
merged 1 commit into from
Jul 2, 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
2 changes: 0 additions & 2 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ impl String {
/// [spec]: https://tc39.es/ecma262/#sec-string.prototype.concat
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat
pub(crate) fn concat(this: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue {
// First we get it the actual string a private field stored on the object only the engine has access to.
// Then we convert it into a Rust String by wrapping it in from_value
let object = ctx.require_object_coercible(this)?;
let mut string = ctx.to_string(object)?.to_string();

Expand Down
24 changes: 19 additions & 5 deletions boa/src/builtins/string/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,25 @@ fn concat() {
"#;
eprintln!("{}", forward(&mut engine, init));

// Todo: fix this
let _a = forward(&mut engine, "hello.concat(world, nice)");
let _b = forward(&mut engine, "hello + world + nice");
// assert_eq!(a, String::from("Hello, world! Have a nice day."));
// assert_eq!(b, String::from("Hello, world! Have a nice day."));
let a = forward(&mut engine, "hello.concat(world, nice)");
assert_eq!(a, "Hello, world! Have a nice day.");

let b = forward(&mut engine, "hello + world + nice");
assert_eq!(b, "Hello, world! Have a nice day.");
}

#[test]
fn generic_concat() {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);
let init = r#"
Number.prototype.concat = String.prototype.concat;
let number = new Number(100);
"#;
eprintln!("{}", forward(&mut engine, init));

let a = forward(&mut engine, "number.concat(' - 50', ' = 50')");
assert_eq!(a, "100 - 50 = 50");
}

#[allow(clippy::result_unwrap_used)]
Expand Down