From 532c00862c72d1e7a284a37ba5bb31ec20d2d8a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Juli=C3=A1n=20Espina?= Date: Thu, 11 Jul 2024 10:55:54 -0600 Subject: [PATCH] Remove `boa_macros` from `boa_string` (#3913) --- Cargo.lock | 1 - core/string/Cargo.toml | 3 --- core/string/src/tests.rs | 27 ++++++++++++++++++--------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7aa7a2cf5ba..fad72a804a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -534,7 +534,6 @@ dependencies = [ name = "boa_string" version = "0.19.0" dependencies = [ - "boa_macros", "fast-float", "paste", "rustc-hash 2.0.0", diff --git a/core/string/Cargo.toml b/core/string/Cargo.toml index 81ef5534570..0bee6f3615c 100644 --- a/core/string/Cargo.toml +++ b/core/string/Cargo.toml @@ -18,9 +18,6 @@ static_assertions.workspace = true paste.workspace = true fast-float.workspace = true -[dev-dependencies] -boa_macros.workspace = true - [lints] workspace = true diff --git a/core/string/src/tests.rs b/core/string/src/tests.rs index 2022994b483..61a23cfa35b 100644 --- a/core/string/src/tests.rs +++ b/core/string/src/tests.rs @@ -4,17 +4,26 @@ use std::hash::{BuildHasher, BuildHasherDefault, Hash}; use crate::{JsStr, JsString, StaticJsStrings}; -use boa_macros::utf16; use rustc_hash::FxHasher; fn hash_value(value: &T) -> u64 { BuildHasherDefault::::default().hash_one(value) } +const fn ascii_to_utf16(ascii: &[u8; LEN]) -> [u16; LEN] { + let mut array = [0; LEN]; + let mut i = 0; + while i < LEN { + array[i] = ascii[i] as u16; + i += 1; + } + array +} + #[test] fn empty() { let s = StaticJsStrings::EMPTY_STRING; - assert_eq!(&s, utf16!("")); + assert_eq!(&s, &[]); } #[test] @@ -85,7 +94,7 @@ fn static_ptr_eq() { #[test] fn as_str() { - const HELLO: &[u16] = utf16!("Hello"); + const HELLO: &[u16] = &ascii_to_utf16(b"Hello"); let x = JsString::from(HELLO); assert_eq!(&x, HELLO); @@ -109,22 +118,22 @@ fn hash() { #[test] fn concat() { - const Y: &[u16] = utf16!(", "); - const W: &[u16] = utf16!("!"); + const Y: &[u16] = &ascii_to_utf16(b", "); + const W: &[u16] = &ascii_to_utf16(b"!"); let x = JsString::from("hello"); let z = JsString::from("world"); let xy = JsString::concat(x.as_str(), JsString::from(Y).as_str()); - assert_eq!(&xy, utf16!("hello, ")); + assert_eq!(&xy, &ascii_to_utf16(b"hello, ")); assert_eq!(xy.refcount(), Some(1)); let xyz = JsString::concat(xy.as_str(), z.as_str()); - assert_eq!(&xyz, utf16!("hello, world")); + assert_eq!(&xyz, &ascii_to_utf16(b"hello, world")); assert_eq!(xyz.refcount(), Some(1)); let xyzw = JsString::concat(xyz.as_str(), JsString::from(W).as_str()); - assert_eq!(&xyzw, utf16!("hello, world!")); + assert_eq!(&xyzw, &ascii_to_utf16(b"hello, world!")); assert_eq!(xyzw.refcount(), Some(1)); } @@ -141,7 +150,7 @@ fn trim_start_non_ascii_to_ascii() { #[test] fn conversion_to_known_static_js_string() { const JS_STR_U8: &JsStr<'_> = &JsStr::latin1("length".as_bytes()); - const JS_STR_U16: &JsStr<'_> = &JsStr::utf16(utf16!("length")); + const JS_STR_U16: &JsStr<'_> = &JsStr::utf16(&ascii_to_utf16(b"length")); assert!(JS_STR_U8.is_latin1()); assert!(!JS_STR_U16.is_latin1());