refactor(semantic): remove all #[dead_code[ from tester

This commit is contained in:
Boshen 2024-01-25 20:27:46 +08:00
parent 889837704c
commit fc1592bc97
No known key found for this signature in database
GPG key ID: 234DA6A7079C6801
9 changed files with 16 additions and 28 deletions

View file

@ -3,8 +3,7 @@ mod util;
use std::fs; use std::fs;
use oxc_span::SourceType; use oxc_span::SourceType;
#[allow(clippy::wildcard_imports)] pub use util::SemanticTester;
use util::*;
#[test] #[test]
fn test_cfg_files() { fn test_cfg_files() {

View file

@ -1,6 +1,6 @@
mod util; mod util;
use util::SemanticTester; pub use util::SemanticTester;
#[test] #[test]
fn test_class_simple() { fn test_class_simple() {
@ -15,7 +15,7 @@ fn test_class_simple() {
set b(v) {} set b(v) {}
get b() {} get b() {}
} }
", ",
) )
.has_class("Foo") .has_class("Foo")
@ -33,7 +33,7 @@ fn test_class_with_ts() {
accessor #pap = 1; accessor #pap = 1;
constructor() {} // this method is skip constructor() {} // this method is skip
} }
", ",
) )
.has_class("Foo") .has_class("Foo")

View file

@ -1,7 +1,6 @@
mod util; mod util;
#[allow(clippy::wildcard_imports)] pub use util::SemanticTester;
use util::*;
#[test] #[test]
fn test_exports() { fn test_exports() {

View file

@ -1,7 +1,7 @@
mod util; mod util;
use oxc_semantic::ScopeFlags; use oxc_semantic::ScopeFlags;
use util::{Expect, SemanticTester}; pub use util::{Expect, SemanticTester};
#[test] #[test]
fn test_top_level_strict() { fn test_top_level_strict() {
@ -11,7 +11,7 @@ fn test_top_level_strict() {
"use strict"; "use strict";
function foo() { function foo() {
return 1 return 1
} }
"#, "#,
) )
.has_root_symbol("foo") .has_root_symbol("foo")
@ -24,7 +24,7 @@ fn test_top_level_strict() {
r" r"
function foo() { function foo() {
return 1 return 1
} }
", ",
) )
.has_root_symbol("foo") .has_root_symbol("foo")
@ -37,7 +37,7 @@ fn test_top_level_strict() {
"use strict"; "use strict";
function foo() { function foo() {
return 1 return 1
} }
"#, "#,
) )
.with_module(false) .with_module(false)
@ -50,7 +50,7 @@ fn test_top_level_strict() {
r" r"
function foo() { function foo() {
return 1 return 1
} }
", ",
) )
.with_module(false) .with_module(false)

View file

@ -1,7 +1,7 @@
mod util; mod util;
use oxc_semantic::SymbolFlags; use oxc_semantic::SymbolFlags;
use util::SemanticTester; pub use util::SemanticTester;
#[test] #[test]
fn test_class_simple() { fn test_class_simple() {

View file

@ -10,7 +10,6 @@ pub struct ClassTester<'a> {
class_id: ClassId, class_id: ClassId,
} }
#[allow(dead_code)] // Only used in #[test]
impl<'a> ClassTester<'a> { impl<'a> ClassTester<'a> {
pub(super) fn has_class(semantic: Semantic<'a>, name: &str) -> Self { pub(super) fn has_class(semantic: Semantic<'a>, name: &str) -> Self {
let class_id = semantic.classes().iter_enumerated().find_map(|(class_id, ast_node_id)| { let class_id = semantic.classes().iter_enumerated().find_map(|(class_id, ast_node_id)| {

View file

@ -1,4 +1,5 @@
pub trait Expect<P, R> { pub trait Expect<P, R> {
#[must_use]
fn expect<F>(self, expectation: F) -> Self fn expect<F>(self, expectation: F) -> Self
where where
F: FnOnce(P) -> R; F: FnOnce(P) -> R;

View file

@ -25,7 +25,6 @@ impl<'a> SemanticTester<'a> {
/// Create a new tester for a TypeScript test case. /// Create a new tester for a TypeScript test case.
/// ///
/// Use [`SemanticTester::js`] for JavaScript test cases. /// Use [`SemanticTester::js`] for JavaScript test cases.
#[allow(dead_code)]
pub fn ts(source_text: &'static str) -> Self { pub fn ts(source_text: &'static str) -> Self {
Self::new(source_text, SourceType::default().with_module(true).with_typescript(true)) Self::new(source_text, SourceType::default().with_module(true).with_typescript(true))
} }
@ -33,7 +32,6 @@ impl<'a> SemanticTester<'a> {
/// Create a new tester for a JavaScript test case. /// Create a new tester for a JavaScript test case.
/// ///
/// Use [`SemanticTester::ts`] for TypeScript test cases. /// Use [`SemanticTester::ts`] for TypeScript test cases.
#[allow(dead_code)]
pub fn js(source_text: &'static str) -> Self { pub fn js(source_text: &'static str) -> Self {
Self::new(source_text, SourceType::default().with_module(true)) Self::new(source_text, SourceType::default().with_module(true))
} }
@ -43,26 +41,27 @@ impl<'a> SemanticTester<'a> {
} }
/// Set the [`SourceType`] to TypeScript (or JavaScript, using `false`) /// Set the [`SourceType`] to TypeScript (or JavaScript, using `false`)
#[allow(dead_code)] #[must_use]
pub fn with_typescript(mut self, yes: bool) -> Self { pub fn with_typescript(mut self, yes: bool) -> Self {
self.source_type = SourceType::default().with_typescript(yes); self.source_type = SourceType::default().with_typescript(yes);
self self
} }
/// Mark the [`SourceType`] as JSX /// Mark the [`SourceType`] as JSX
#[allow(dead_code)] #[must_use]
pub fn with_jsx(mut self, yes: bool) -> Self { pub fn with_jsx(mut self, yes: bool) -> Self {
self.source_type = self.source_type.with_jsx(yes); self.source_type = self.source_type.with_jsx(yes);
self self
} }
#[allow(dead_code)] #[must_use]
pub fn with_module(mut self, yes: bool) -> Self { pub fn with_module(mut self, yes: bool) -> Self {
self.source_type = self.source_type.with_module(yes); self.source_type = self.source_type.with_module(yes);
self self
} }
/// Parse the source text and produce a new [`Semantic`] /// Parse the source text and produce a new [`Semantic`]
/// # Panics
#[allow(unstable_name_collisions)] #[allow(unstable_name_collisions)]
pub fn build(&self) -> Semantic<'_> { pub fn build(&self) -> Semantic<'_> {
let parse = let parse =
@ -102,13 +101,11 @@ impl<'a> SemanticTester<'a> {
semantic_ret.semantic semantic_ret.semantic
} }
#[allow(dead_code)]
pub fn basic_blocks_count(&self) -> usize { pub fn basic_blocks_count(&self) -> usize {
let built = self.build(); let built = self.build();
built.cfg().basic_blocks.len() built.cfg().basic_blocks.len()
} }
#[allow(dead_code)]
pub fn basic_blocks_printed(&self) -> String { pub fn basic_blocks_printed(&self) -> String {
let built = self.build(); let built = self.build();
built built
@ -126,7 +123,6 @@ impl<'a> SemanticTester<'a> {
.join("\n\n") .join("\n\n")
} }
#[allow(dead_code)]
pub fn cfg_dot_diagram(&self) -> String { pub fn cfg_dot_diagram(&self) -> String {
let built = self.build(); let built = self.build();
format!( format!(
@ -151,7 +147,6 @@ impl<'a> SemanticTester<'a> {
/// ///
/// ## Fails /// ## Fails
/// If no symbol with the given name exists at the top-level scope. /// If no symbol with the given name exists at the top-level scope.
#[allow(dead_code)]
pub fn has_root_symbol(&self, name: &str) -> SymbolTester { pub fn has_root_symbol(&self, name: &str) -> SymbolTester {
SymbolTester::new_at_root(self, self.build(), name) SymbolTester::new_at_root(self, self.build(), name)
} }
@ -160,7 +155,6 @@ impl<'a> SemanticTester<'a> {
/// ///
/// ## Fails /// ## Fails
/// If no class with the given name exists. /// If no class with the given name exists.
#[allow(dead_code)]
pub fn has_class(&self, name: &str) -> ClassTester { pub fn has_class(&self, name: &str) -> ClassTester {
ClassTester::has_class(self.build(), name) ClassTester::has_class(self.build(), name)
} }
@ -171,7 +165,6 @@ impl<'a> SemanticTester<'a> {
/// 1. No symbol with the given name exists, /// 1. No symbol with the given name exists,
/// 2. More than one symbol with the given name exists, so a symbol cannot /// 2. More than one symbol with the given name exists, so a symbol cannot
/// be uniquely obtained. /// be uniquely obtained.
#[allow(dead_code)]
pub fn has_some_symbol(&self, name: &str) -> SymbolTester { pub fn has_some_symbol(&self, name: &str) -> SymbolTester {
SymbolTester::new_unique(self, self.build(), name) SymbolTester::new_unique(self, self.build(), name)
} }

View file

@ -18,7 +18,6 @@ pub struct SymbolTester<'a> {
} }
impl<'a> SymbolTester<'a> { impl<'a> SymbolTester<'a> {
#[allow(dead_code)]
pub(super) fn new_at_root( pub(super) fn new_at_root(
parent: &'a SemanticTester, parent: &'a SemanticTester,
semantic: Semantic<'a>, semantic: Semantic<'a>,
@ -36,7 +35,6 @@ impl<'a> SymbolTester<'a> {
} }
} }
#[allow(dead_code)]
pub(super) fn new_unique( pub(super) fn new_unique(
parent: &'a SemanticTester, parent: &'a SemanticTester,
semantic: Semantic<'a>, semantic: Semantic<'a>,
@ -104,7 +102,6 @@ impl<'a> SymbolTester<'a> {
self.has_number_of_references_where(ref_count, Reference::is_read) self.has_number_of_references_where(ref_count, Reference::is_read)
} }
#[allow(dead_code)]
pub fn has_number_of_writes(self, ref_count: usize) -> Self { pub fn has_number_of_writes(self, ref_count: usize) -> Self {
self.has_number_of_references_where(ref_count, Reference::is_write) self.has_number_of_references_where(ref_count, Reference::is_write)
} }