Unverified Commit 2d01e08e authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: test if unused self arguments are filtered (#86353)

### What?

add test case for self argument filtering
parent 24033486
......@@ -9,9 +9,9 @@ use turbo_tasks_testing::{Registration, register, run_once};
static REGISTRATION: Registration = register!();
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn filtered_trait_method_args() -> Result<()> {
async fn filtered_impl_method_args() -> Result<()> {
run_once(&REGISTRATION, || async {
let uses_arg = UsesArg.cell();
let uses_arg = UsesArg(0).cell();
assert_eq!(
uses_arg.method_with_arg(0).to_resolved().await?,
uses_arg.method_with_arg(0).to_resolved().await?,
......@@ -21,7 +21,7 @@ async fn filtered_trait_method_args() -> Result<()> {
uses_arg.method_with_arg(1).to_resolved().await?,
);
let ignores_arg = IgnoresArg.cell();
let ignores_arg = IgnoresArg(0).cell();
assert_eq!(
ignores_arg.method_with_arg(0).to_resolved().await?,
ignores_arg.method_with_arg(0).to_resolved().await?,
......@@ -30,6 +30,128 @@ async fn filtered_trait_method_args() -> Result<()> {
ignores_arg.method_with_arg(0).to_resolved().await?,
ignores_arg.method_with_arg(1).to_resolved().await?,
);
Ok(())
})
.await
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn filtered_trait_method_args() -> Result<()> {
run_once(&REGISTRATION, || async {
let uses_arg = UsesArg(0).cell();
assert_eq!(
uses_arg.trait_method_with_arg(0).to_resolved().await?,
uses_arg.trait_method_with_arg(0).to_resolved().await?,
);
assert_ne!(
uses_arg.trait_method_with_arg(0).to_resolved().await?,
uses_arg.trait_method_with_arg(1).to_resolved().await?,
);
let ignores_arg = IgnoresArg(0).cell();
assert_eq!(
ignores_arg.trait_method_with_arg(0).to_resolved().await?,
ignores_arg.trait_method_with_arg(0).to_resolved().await?,
);
assert_eq!(
ignores_arg.trait_method_with_arg(0).to_resolved().await?,
ignores_arg.trait_method_with_arg(1).to_resolved().await?,
);
Ok(())
})
.await
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn filtered_impl_method_self() -> Result<()> {
run_once(&REGISTRATION, || async {
let uses_arg = UsesArg(0).cell();
let uses_arg2 = UsesArg(1).cell();
assert_eq!(
uses_arg.method_with_arg(0).to_resolved().await?,
uses_arg2.method_with_arg(0).to_resolved().await?,
);
assert_eq!(
uses_arg.method_with_arg(1).to_resolved().await?,
uses_arg2.method_with_arg(1).to_resolved().await?,
);
let ignores_arg = IgnoresArg(0).cell();
let ignores_arg2 = IgnoresArg(1).cell();
assert_eq!(
ignores_arg.method_with_arg(0).to_resolved().await?,
ignores_arg2.method_with_arg(0).to_resolved().await?,
);
assert_eq!(
ignores_arg.method_with_arg(1).to_resolved().await?,
ignores_arg2.method_with_arg(1).to_resolved().await?,
);
assert_eq!(
ignores_arg.method_with_arg(0).to_resolved().await?,
ignores_arg2.method_with_arg(1).to_resolved().await?,
);
Ok(())
})
.await
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn filtered_trait_method_self() -> Result<()> {
run_once(&REGISTRATION, || async {
let uses_arg = UsesArg(0).cell();
let uses_arg2 = UsesArg(1).cell();
assert_eq!(
uses_arg.trait_method_with_arg(0).to_resolved().await?,
uses_arg2.trait_method_with_arg(0).to_resolved().await?,
);
assert_eq!(
uses_arg.trait_method_with_arg(1).to_resolved().await?,
uses_arg2.trait_method_with_arg(1).to_resolved().await?,
);
let ignores_arg = IgnoresArg(0).cell();
let ignores_arg2 = IgnoresArg(1).cell();
assert_eq!(
ignores_arg.trait_method_with_arg(0).to_resolved().await?,
ignores_arg2.trait_method_with_arg(0).to_resolved().await?,
);
assert_eq!(
ignores_arg.trait_method_with_arg(1).to_resolved().await?,
ignores_arg2.trait_method_with_arg(1).to_resolved().await?,
);
assert_eq!(
ignores_arg.trait_method_with_arg(0).to_resolved().await?,
ignores_arg2.trait_method_with_arg(1).to_resolved().await?,
);
Ok(())
})
.await
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn filtered_plain_method_args() -> Result<()> {
run_once(&REGISTRATION, || async {
assert_eq!(
method_with_arg(0).to_resolved().await?,
method_with_arg(0).to_resolved().await?,
);
assert_ne!(
method_with_arg(0).to_resolved().await?,
method_with_arg(1).to_resolved().await?,
);
assert_eq!(
method_with_ignored_arg(0).to_resolved().await?,
method_with_ignored_arg(0).to_resolved().await?,
);
assert_eq!(
method_with_ignored_arg(0).to_resolved().await?,
method_with_ignored_arg(1).to_resolved().await?,
);
Ok(())
})
.await
......@@ -38,14 +160,14 @@ async fn filtered_trait_method_args() -> Result<()> {
#[turbo_tasks::value_trait]
trait ExampleTrait {
#[turbo_tasks::function]
fn method_with_arg(&self, number: i32) -> Vc<()>;
fn trait_method_with_arg(&self, number: i32) -> Vc<()>;
}
#[turbo_tasks::value]
struct UsesArg;
struct UsesArg(i32);
#[turbo_tasks::value_impl]
impl ExampleTrait for UsesArg {
impl UsesArg {
#[turbo_tasks::function]
fn method_with_arg(&self, number: i32) -> Vc<()> {
let _ = number;
......@@ -53,13 +175,41 @@ impl ExampleTrait for UsesArg {
}
}
#[turbo_tasks::value_impl]
impl ExampleTrait for UsesArg {
#[turbo_tasks::function]
fn trait_method_with_arg(&self, number: i32) -> Vc<()> {
let _ = number;
Vc::cell(())
}
}
#[turbo_tasks::value]
struct IgnoresArg;
struct IgnoresArg(i32);
#[turbo_tasks::value_impl]
impl ExampleTrait for IgnoresArg {
impl IgnoresArg {
#[turbo_tasks::function]
fn method_with_arg(&self, _number: i32) -> Vc<()> {
Vc::cell(())
}
}
#[turbo_tasks::value_impl]
impl ExampleTrait for IgnoresArg {
#[turbo_tasks::function]
fn trait_method_with_arg(&self, _number: i32) -> Vc<()> {
Vc::cell(())
}
}
#[turbo_tasks::function]
fn method_with_arg(number: i32) -> Vc<()> {
let _ = number;
Vc::cell(())
}
#[turbo_tasks::function]
fn method_with_ignored_arg(_number: i32) -> Vc<()> {
Vc::cell(())
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment