-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Move macro implementations under internal
Signed-off-by: Akira Moroo <[email protected]>
- Loading branch information
Showing
4 changed files
with
48 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Akira Moroo <[email protected]> 2023 | ||
|
||
mod chatgpt; | ||
|
||
pub mod auto_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Akira Moroo <[email protected]> 2023 | ||
|
||
use proc_macro::TokenStream; | ||
use std::collections::HashSet; | ||
use syn::{ | ||
parse::{Parse, ParseStream, Result}, | ||
parse_macro_input, Ident, Token, | ||
}; | ||
|
||
use crate::internal::chatgpt; | ||
|
||
/// Parses a list of test function names separated by commas. | ||
/// | ||
/// test_valid, test_div_by_zero | ||
/// | ||
/// The function name is used to generate the test function name. | ||
struct Args { | ||
test_names: HashSet<Ident>, | ||
} | ||
|
||
impl Parse for Args { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let test_names = input.parse_terminated::<Ident, Token![,]>(Ident::parse)?; | ||
Ok(Args { | ||
test_names: test_names.into_iter().collect(), | ||
}) | ||
} | ||
} | ||
|
||
pub fn auto_test_impl(args: TokenStream, input: TokenStream) -> TokenStream { | ||
// Parse the list of test function names that should be generated. | ||
let args = parse_macro_input!(args as Args); | ||
|
||
match chatgpt::generate_tests(input, args.test_names) { | ||
Ok(output) => output, | ||
Err(e) => panic!("{}", e), | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Akira Moroo <[email protected]> 2023 | ||
|
||
use internal::auto_test::auto_test_impl; | ||
use proc_macro::TokenStream; | ||
use std::collections::HashSet; | ||
use syn::{ | ||
parse::{Parse, ParseStream, Result}, | ||
parse_macro_input, Ident, Token, | ||
}; | ||
|
||
mod chatgpt; | ||
|
||
/// Parses a list of test function names separated by commas. | ||
/// | ||
/// test_valid, test_div_by_zero | ||
/// | ||
/// The function name is used to generate the test function name. | ||
struct Args { | ||
test_names: HashSet<Ident>, | ||
} | ||
|
||
impl Parse for Args { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let test_names = input.parse_terminated::<Ident, Token![,]>(Ident::parse)?; | ||
Ok(Args { | ||
test_names: test_names.into_iter().collect(), | ||
}) | ||
} | ||
} | ||
mod internal; | ||
|
||
/// Attribute macro for automatically generating tests for functions. | ||
/// | ||
|
@@ -51,11 +29,5 @@ impl Parse for Args { | |
/// ``` | ||
#[proc_macro_attribute] | ||
pub fn auto_test(args: TokenStream, input: TokenStream) -> TokenStream { | ||
// Parse the list of test function names that should be generated. | ||
let args = parse_macro_input!(args as Args); | ||
|
||
match chatgpt::generate_tests(input, args.test_names) { | ||
Ok(output) => output, | ||
Err(e) => panic!("{}", e), | ||
} | ||
auto_test_impl(args, input) | ||
} |