@@ -4,17 +4,26 @@ use std::hash::{BuildHasher, BuildHasherDefault, Hash};
44
55use crate :: { JsStr , JsString , StaticJsStrings } ;
66
7- use boa_macros:: utf16;
87use rustc_hash:: FxHasher ;
98
109fn hash_value < T : Hash > ( value : & T ) -> u64 {
1110 BuildHasherDefault :: < FxHasher > :: default ( ) . hash_one ( value)
1211}
1312
13+ const fn ascii_to_utf16 < const LEN : usize > ( ascii : & [ u8 ; LEN ] ) -> [ u16 ; LEN ] {
14+ let mut array = [ 0 ; LEN ] ;
15+ let mut i = 0 ;
16+ while i < LEN {
17+ array[ i] = ascii[ i] as u16 ;
18+ i += 1 ;
19+ }
20+ array
21+ }
22+
1423#[ test]
1524fn empty ( ) {
1625 let s = StaticJsStrings :: EMPTY_STRING ;
17- assert_eq ! ( & s, utf16! ( "" ) ) ;
26+ assert_eq ! ( & s, & [ ] ) ;
1827}
1928
2029#[ test]
@@ -85,7 +94,7 @@ fn static_ptr_eq() {
8594
8695#[ test]
8796fn as_str ( ) {
88- const HELLO : & [ u16 ] = utf16 ! ( "Hello" ) ;
97+ const HELLO : & [ u16 ] = & ascii_to_utf16 ( b "Hello") ;
8998 let x = JsString :: from ( HELLO ) ;
9099
91100 assert_eq ! ( & x, HELLO ) ;
@@ -109,22 +118,22 @@ fn hash() {
109118
110119#[ test]
111120fn concat ( ) {
112- const Y : & [ u16 ] = utf16 ! ( ", " ) ;
113- const W : & [ u16 ] = utf16 ! ( "!" ) ;
121+ const Y : & [ u16 ] = & ascii_to_utf16 ( b ", ") ;
122+ const W : & [ u16 ] = & ascii_to_utf16 ( b "!") ;
114123
115124 let x = JsString :: from ( "hello" ) ;
116125 let z = JsString :: from ( "world" ) ;
117126
118127 let xy = JsString :: concat ( x. as_str ( ) , JsString :: from ( Y ) . as_str ( ) ) ;
119- assert_eq ! ( & xy, utf16! ( "hello, " ) ) ;
128+ assert_eq ! ( & xy, & ascii_to_utf16 ( b "hello, ") ) ;
120129 assert_eq ! ( xy. refcount( ) , Some ( 1 ) ) ;
121130
122131 let xyz = JsString :: concat ( xy. as_str ( ) , z. as_str ( ) ) ;
123- assert_eq ! ( & xyz, utf16! ( "hello, world" ) ) ;
132+ assert_eq ! ( & xyz, & ascii_to_utf16 ( b "hello, world") ) ;
124133 assert_eq ! ( xyz. refcount( ) , Some ( 1 ) ) ;
125134
126135 let xyzw = JsString :: concat ( xyz. as_str ( ) , JsString :: from ( W ) . as_str ( ) ) ;
127- assert_eq ! ( & xyzw, utf16! ( "hello, world!" ) ) ;
136+ assert_eq ! ( & xyzw, & ascii_to_utf16 ( b "hello, world!") ) ;
128137 assert_eq ! ( xyzw. refcount( ) , Some ( 1 ) ) ;
129138}
130139
@@ -141,7 +150,7 @@ fn trim_start_non_ascii_to_ascii() {
141150#[ test]
142151fn conversion_to_known_static_js_string ( ) {
143152 const JS_STR_U8 : & JsStr < ' _ > = & JsStr :: latin1 ( "length" . as_bytes ( ) ) ;
144- const JS_STR_U16 : & JsStr < ' _ > = & JsStr :: utf16 ( utf16 ! ( "length" ) ) ;
153+ const JS_STR_U16 : & JsStr < ' _ > = & JsStr :: utf16 ( & ascii_to_utf16 ( b "length") ) ;
145154
146155 assert ! ( JS_STR_U8 . is_latin1( ) ) ;
147156 assert ! ( !JS_STR_U16 . is_latin1( ) ) ;
0 commit comments