From f708a764c2cfe223df89f16013c9edec76615512 Mon Sep 17 00:00:00 2001 From: Iban Eguia Moraza Date: Fri, 21 Oct 2022 15:45:32 +0000 Subject: [PATCH] Fixed some documentation and clippy warnings in tests (#2362) This Pull Request fixes a small error in the documentation of `Context::register_global_function()` method, and a few clippy errors we were getting in the tests. --- boa_engine/src/builtins/intl/tests.rs | 44 +++++++++---------- boa_engine/src/context/mod.rs | 3 +- .../parser/statement/iteration/tests.rs | 42 ++++++++---------- 3 files changed, 42 insertions(+), 47 deletions(-) diff --git a/boa_engine/src/builtins/intl/tests.rs b/boa_engine/src/builtins/intl/tests.rs index b3bc6a47be..d0954e351c 100644 --- a/boa_engine/src/builtins/intl/tests.rs +++ b/boa_engine/src/builtins/intl/tests.rs @@ -17,14 +17,14 @@ fn best_avail_loc() { let no_extensions_locale = "en-US"; let available_locales = Vec::new(); assert_eq!( - best_available_locale(&available_locales, &no_extensions_locale,), + best_available_locale(&available_locales, no_extensions_locale), None ); let no_extensions_locale = "de-DE"; - let available_locales = vec![no_extensions_locale.clone()]; + let available_locales = vec![no_extensions_locale]; assert_eq!( - best_available_locale(&available_locales, &no_extensions_locale,), + best_available_locale(&available_locales, no_extensions_locale), Some(no_extensions_locale) ); @@ -32,16 +32,16 @@ fn best_avail_loc() { let no_extensions_locale = locale_part.to_string() + "-CA"; let available_locales = vec![locale_part]; assert_eq!( - best_available_locale(&available_locales, &no_extensions_locale,), + best_available_locale(&available_locales, &no_extensions_locale), Some(locale_part) ); let ja_kana_t = "ja-Kana-JP-t"; let ja_kana = "ja-Kana-JP"; let no_extensions_locale = "ja-Kana-JP-t-it-latn-it"; - let available_locales = vec![ja_kana_t, ja_kana.clone()]; + let available_locales = vec![ja_kana_t, ja_kana]; assert_eq!( - best_available_locale(&available_locales, &no_extensions_locale,), + best_available_locale(&available_locales, no_extensions_locale), Some(ja_kana) ); } @@ -98,21 +98,21 @@ fn insert_unicode_ext() { let locale = "hu-HU"; let ext = ""; assert_eq!( - insert_unicode_extension_and_canonicalize(&locale, &ext, &canonicalizer), + insert_unicode_extension_and_canonicalize(locale, ext, &canonicalizer), locale ); let locale = "hu-HU"; let ext = "-u-hc-h12"; assert_eq!( - insert_unicode_extension_and_canonicalize(&locale, &ext, &canonicalizer), + insert_unicode_extension_and_canonicalize(locale, ext, &canonicalizer), "hu-HU-u-hc-h12" ); let locale = "hu-HU-x-PRIVATE"; let ext = "-u-hc-h12"; assert_eq!( - insert_unicode_extension_and_canonicalize(&locale, &ext, &canonicalizer), + insert_unicode_extension_and_canonicalize(locale, ext, &canonicalizer), "hu-HU-u-hc-h12-x-private" ); } @@ -120,7 +120,7 @@ fn insert_unicode_ext() { #[test] fn uni_ext_comp() { let ext = "-u-ca-japanese-hc-h12"; - let components = unicode_extension_components(&ext); + let components = unicode_extension_components(ext); assert!(components.attributes.is_empty()); assert_eq!(components.keywords.len(), 2); assert_eq!(components.keywords[0].key, "ca"); @@ -129,7 +129,7 @@ fn uni_ext_comp() { assert_eq!(components.keywords[1].value, "h12"); let ext = "-u-alias-co-phonebk-ka-shifted"; - let components = unicode_extension_components(&ext); + let components = unicode_extension_components(ext); assert_eq!(components.attributes, vec![String::from("alias")]); assert_eq!(components.keywords.len(), 2); assert_eq!(components.keywords[0].key, "co"); @@ -138,7 +138,7 @@ fn uni_ext_comp() { assert_eq!(components.keywords[1].value, "shifted"); let ext = "-u-ca-buddhist-kk-nu-thai"; - let components = unicode_extension_components(&ext); + let components = unicode_extension_components(ext); assert!(components.attributes.is_empty()); assert_eq!(components.keywords.len(), 3); assert_eq!(components.keywords[0].key, "ca"); @@ -149,7 +149,7 @@ fn uni_ext_comp() { assert_eq!(components.keywords[2].value, "thai"); let ext = "-u-ca-islamic-civil"; - let components = unicode_extension_components(&ext); + let components = unicode_extension_components(ext); assert!(components.attributes.is_empty()); assert_eq!(components.keywords.len(), 1); assert_eq!(components.keywords[0].key, "ca"); @@ -478,11 +478,11 @@ fn to_date_time_opts() { let numeric_jsstring = JsValue::String("numeric".into()); assert_eq!( date_time_opts.get("year", &mut context).unwrap(), - numeric_jsstring.clone() + numeric_jsstring ); assert_eq!( date_time_opts.get("month", &mut context).unwrap(), - numeric_jsstring.clone() + numeric_jsstring ); assert_eq!( date_time_opts.get("day", &mut context).unwrap(), @@ -500,11 +500,11 @@ fn to_date_time_opts() { let numeric_jsstring = JsValue::String("numeric".into()); assert_eq!( date_time_opts.get("hour", &mut context).unwrap(), - numeric_jsstring.clone() + numeric_jsstring ); assert_eq!( date_time_opts.get("minute", &mut context).unwrap(), - numeric_jsstring.clone() + numeric_jsstring ); assert_eq!( date_time_opts.get("second", &mut context).unwrap(), @@ -522,23 +522,23 @@ fn to_date_time_opts() { let numeric_jsstring = JsValue::String("numeric".into()); assert_eq!( date_time_opts.get("year", &mut context).unwrap(), - numeric_jsstring.clone() + numeric_jsstring ); assert_eq!( date_time_opts.get("month", &mut context).unwrap(), - numeric_jsstring.clone() + numeric_jsstring ); assert_eq!( date_time_opts.get("day", &mut context).unwrap(), - numeric_jsstring.clone() + numeric_jsstring ); assert_eq!( date_time_opts.get("hour", &mut context).unwrap(), - numeric_jsstring.clone() + numeric_jsstring ); assert_eq!( date_time_opts.get("minute", &mut context).unwrap(), - numeric_jsstring.clone() + numeric_jsstring ); assert_eq!( date_time_opts.get("second", &mut context).unwrap(), diff --git a/boa_engine/src/context/mod.rs b/boa_engine/src/context/mod.rs index 4c64ed4209..0265946ab6 100644 --- a/boa_engine/src/context/mod.rs +++ b/boa_engine/src/context/mod.rs @@ -251,7 +251,8 @@ impl Context { /// This is more efficient that creating a closure function, since this does not allocate, /// it is just a function pointer. /// - /// The function will be both `constructable` (call with `new`). + /// The function will be both `constructable` (call with `new ()`) and `callable` (call + /// with `()`). /// /// The function will be bound to the global object with `writable`, `non-enumerable` /// and `configurable` attributes. The same as when you create a function in JavaScript. diff --git a/boa_engine/src/syntax/parser/statement/iteration/tests.rs b/boa_engine/src/syntax/parser/statement/iteration/tests.rs index 0ada0622dd..28d5fd8aeb 100644 --- a/boa_engine/src/syntax/parser/statement/iteration/tests.rs +++ b/boa_engine/src/syntax/parser/statement/iteration/tests.rs @@ -37,8 +37,7 @@ fn check_do_while() { )), ))] .into(), - ) - .into(), + ), Literal::from(true).into(), )) .into()], @@ -83,8 +82,7 @@ fn check_do_while_semicolon_insertion() { )), ))] .into(), - ) - .into(), + ), Binary::new( RelationalOp::LessThan.into(), Unary::new( @@ -133,29 +131,25 @@ fn check_do_while_semicolon_insertion_no_space() { .into(), Statement::DoWhileLoop(DoWhileLoop::new( Statement::Block( - vec![ - StatementListItem::Statement(Statement::Expression(Expression::from( - Call::new( - PropertyAccess::new( - Identifier::new( - interner.get_or_intern_static("console", utf16!("console")), - ) - .into(), - interner.get_or_intern_static("log", utf16!("log")), - ) - .into(), - vec![Literal::from( - interner.get_or_intern_static("hello", utf16!("hello")), + vec![StatementListItem::Statement(Statement::Expression( + Expression::from(Call::new( + PropertyAccess::new( + Identifier::new( + interner.get_or_intern_static("console", utf16!("console")), ) - .into()] .into(), - ), - ))) - .into(), - ] + interner.get_or_intern_static("log", utf16!("log")), + ) + .into(), + vec![Literal::from( + interner.get_or_intern_static("hello", utf16!("hello")), + ) + .into()] + .into(), + )), + ))] .into(), - ) - .into(), + ), Binary::new( RelationalOp::LessThan.into(), Unary::new(