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 oxc_span::SourceType;
#[allow(clippy::wildcard_imports)]
use util::*;
pub use util::SemanticTester;
#[test]
fn test_cfg_files() {

View file

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

View file

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

View file

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

View file

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

View file

@ -10,7 +10,6 @@ pub struct ClassTester<'a> {
class_id: ClassId,
}
#[allow(dead_code)] // Only used in #[test]
impl<'a> ClassTester<'a> {
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)| {

View file

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

View file

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

View file

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