Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand_unit: Always use string literals #24

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions prse-derive/src/expand_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use syn::{GenericParam, Generics, ImplGenerics, WhereClause, WherePredicate};

use crate::derive::{Derive, Fields};
use crate::instructions::Instructions;
use crate::invocation::string_to_tokens;

impl Derive {
pub fn into_token_stream(self) -> TokenStream {
Expand Down Expand Up @@ -131,7 +130,7 @@ fn expand_tuple(
}

fn expand_unit(s: String, to_return: TokenStream, error: Option<TokenStream>) -> TokenStream {
let l_string = string_to_tokens(&s);
let l_string = s.to_token_stream();
let error = error.unwrap_or_else(|| {
if cfg!(feature = "alloc") {
quote! {
Expand Down
32 changes: 32 additions & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
mod common {
use prse::{parse, Parse};

#[test]
fn empty_literal() {
let input = "";
parse!(input, "");
let input = "Test";
parse!(input, "Test")
}

#[derive(Parse, Eq, PartialEq, Debug)]
enum SimpleAlphabet {
#[prse = "A"]
A,
#[prse = "B"]
B,
}

#[derive(Parse, Eq, PartialEq, Debug)]
#[prse = "{:-:2}"]
struct Alphabets([SimpleAlphabet; 2]);

#[test]
fn parse_single_chars() {
assert_eq!(SimpleAlphabet::A, parse!("A", "{}"));
assert_eq!(
Alphabets([SimpleAlphabet::A, SimpleAlphabet::B]),
parse!("A-B", "{}")
)
}
}
8 changes: 1 addition & 7 deletions tests/test-alloc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,5 @@ mod tests {
assert_eq!(var, "test:")
}

#[test]
fn empty_literal() {
let input = "";
parse!(input, "");
let input = "Test";
parse!(input, "Test")
}
include!("../common.rs");
}
8 changes: 1 addition & 7 deletions tests/test-no-std/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,5 @@ mod tests {
assert_eq!(num, 7)
}

#[test]
fn empty_literal() {
let input = "";
parse!(input, "");
let input = "Test";
parse!(input, "Test")
}
include!("../common.rs");
}
10 changes: 2 additions & 8 deletions tests/test-std/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ mod tests {
assert_eq!(num, 7)
}

#[test]
fn empty_literal() {
let input = "";
parse!(input, "");
let input = "Test";
parse!(input, "Test")
}

#[derive(Debug, Parse)]
struct Position {
x: i32,
Expand Down Expand Up @@ -173,4 +165,6 @@ mod tests {
}
)
}

include!("../common.rs");
}
Loading