Skip to content

Commit

Permalink
chore(turbo-tasks): Add test for argument filtering (#75585)
Browse files Browse the repository at this point in the history
This is a follow-up to: #75261

Tracking issue for these follow-ups: https://linear.app/vercel/issue/PACK-3828/argument-filtering-follow-ups
  • Loading branch information
bgw authored Feb 3, 2025
1 parent 98d4bba commit 73ab21a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
64 changes: 64 additions & 0 deletions turbopack/crates/turbo-tasks-testing/tests/filter_unused_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![feature(arbitrary_self_types)]
#![feature(arbitrary_self_types_pointers)]
#![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this

use anyhow::Result;
use turbo_tasks::Vc;
use turbo_tasks_testing::{register, run, Registration};

static REGISTRATION: Registration = register!();

#[tokio::test]
async fn filtered_trait_method_args() -> Result<()> {
run(&REGISTRATION, || async {
let uses_arg = UsesArg.cell();
assert_eq!(
uses_arg.method_with_arg(0).to_resolved().await?,
uses_arg.method_with_arg(0).to_resolved().await?,
);
assert_ne!(
uses_arg.method_with_arg(0).to_resolved().await?,
uses_arg.method_with_arg(1).to_resolved().await?,
);

let ignores_arg = IgnoresArg.cell();
assert_eq!(
ignores_arg.method_with_arg(0).to_resolved().await?,
ignores_arg.method_with_arg(0).to_resolved().await?,
);
assert_eq!(
ignores_arg.method_with_arg(0).to_resolved().await?,
ignores_arg.method_with_arg(1).to_resolved().await?,
);
Ok(())
})
.await
}

#[turbo_tasks::value_trait]
trait ExampleTrait {
fn method_with_arg(&self, number: i32) -> Vc<()>;
}

#[turbo_tasks::value]
struct UsesArg;

#[turbo_tasks::value_impl]
impl ExampleTrait for UsesArg {
#[turbo_tasks::function]
fn method_with_arg(&self, number: i32) -> Vc<()> {
let _ = number;
Vc::cell(())
}
}

#[turbo_tasks::value]
struct IgnoresArg;

#[turbo_tasks::value_impl]
impl ExampleTrait for IgnoresArg {
#[turbo_tasks::function]
fn method_with_arg(&self, _number: i32) -> Vc<()> {
Vc::cell(())
}
}

0 comments on commit 73ab21a

Please # to comment.