Skip to content

Commit f9ec54b

Browse files
committed
1. Correction of licenses.
2. Adding small tests
1 parent 2c04036 commit f9ec54b

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "include_tt"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
edition = "2021"
55
authors = ["Denis Kotlyarov (Денис Котляров) <denis2005991@gmail.com>"]
66
repository = "https://github.com/clucompany/include_tt.git"

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# include_tt
22
[![CI](https://github.com/clucompany/include_tt/actions/workflows/CI.yml/badge.svg?event=push)](https://github.com/clucompany/include_tt/actions/workflows/CI.yml)
3-
[![Apache licensed](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](./LICENSE)
3+
[![Mit/Apache licensed](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue)](./LICENSE)
44
[![crates.io](https://img.shields.io/crates/v/include_tt)](https://crates.io/crates/include_tt)
55
[![Documentation](https://docs.rs/include_tt/badge.svg)](https://docs.rs/include_tt)
66

@@ -44,3 +44,11 @@ use std::fmt::Write;
4444
assert_eq!(array, b"a, b");
4545
}
4646
```
47+
48+
### License
49+
50+
Copyright 2023 #UlinProject (Denis Kotlyarov) Денис Котляров
51+
52+
Licensed under the MIT License
53+
54+
Licensed under the Apache License, Version 2.0

src/exprs/literal.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,23 @@ pub struct ExprLit {
99
data: str
1010
}
1111

12+
impl PartialEq<ExprLit> for ExprLit {
13+
#[inline(always)]
14+
fn eq(&self, other: &ExprLit) -> bool {
15+
PartialEq::eq(self.as_str(), other.as_str())
16+
}
17+
}
18+
19+
impl PartialEq<str> for ExprLit {
20+
#[inline(always)]
21+
fn eq(&self, other: &str) -> bool {
22+
PartialEq::eq(self.as_str(), other)
23+
}
24+
}
25+
1226
/// Errors received in case of a
1327
/// literal expression parsing error.
14-
#[derive(Clone, Copy)]
28+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
1529
pub enum ExprLitTryNewErr {
1630
/// More characters were expected to be parsed.
1731
ExpLen {
@@ -106,3 +120,20 @@ impl ExprLit {
106120
&self.data
107121
}
108122
}
123+
124+
#[cfg(test)]
125+
#[test]
126+
fn test_literal() {
127+
assert_eq!(
128+
ExprLit::try_new(""),
129+
Err(ExprLitTryNewErr::ExpLen { current: 0, exp: 2 })
130+
);
131+
assert_eq!(
132+
ExprLit::try_new("\""),
133+
Err(ExprLitTryNewErr::ExpLen { current: 1, exp: 2 })
134+
);
135+
assert_eq!(
136+
ExprLit::try_new("\"\""),
137+
Ok(ExprLit::__new("")),
138+
);
139+
}

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use std::fmt::Write;
7474
*/
7575

7676
use std::slice::IterMut;
77-
use proc_macro2::TokenTree;
77+
use proc_macro2::TokenTree as TokenTree2;
7878
use proc_macro::TokenStream;
7979
use proc_macro2::TokenStream as TokenStream2;
8080
use trees::sg_err;
@@ -113,18 +113,18 @@ pub (crate) mod macros {
113113
///
114114
/// The design of this feature has been adapted to search for attachments.
115115
fn search_include_and_replacegroup(
116-
iter: &mut IterMut<'_, TokenTree>,
116+
iter: &mut IterMut<'_, TokenTree2>,
117117
_is_zero_glevel: bool
118118
) -> SearchGroup {
119119
while let Some(m_punct) = iter.next() {
120120
match m_punct {
121-
TokenTree::Punct(punct) => {
121+
TokenTree2::Punct(punct) => {
122122
if punct.as_char() == '#' {
123123
if let Some(m_ident) = iter.next() {
124-
if let TokenTree::Ident(ident) = m_ident {
124+
if let TokenTree2::Ident(ident) = m_ident {
125125
let macro_fn = {
126126
match ident.to_string().as_str() {
127-
"include" => macro_rule_include::<IncludeTt>,
127+
"include" | "include_tt" => macro_rule_include::<IncludeTt>,
128128
"include_str" => macro_rule_include::<IncludeStr>,
129129
"include_arr" => macro_rule_include::<IncludeArr>,
130130

@@ -133,10 +133,10 @@ fn search_include_and_replacegroup(
133133
};
134134

135135
if let Some(m_punct2) = iter.next() {
136-
if let TokenTree::Punct(punct2) = m_punct2 {
136+
if let TokenTree2::Punct(punct2) = m_punct2 {
137137
if punct2.as_char() == '!' {
138138
if let Some(m_group) = iter.next() {
139-
if let TokenTree::Group(group) = m_group {
139+
if let TokenTree2::Group(group) = m_group {
140140
let result = ttry!(macro_fn(
141141
group,
142142
));
@@ -165,7 +165,7 @@ fn search_include_and_replacegroup(
165165
}
166166
// If this is a group, then you need to go down inside the
167167
// group and look for the necessary macros there.
168-
TokenTree::Group(group) => match support_replace_tree_in_group(
168+
TokenTree2::Group(group) => match support_replace_tree_in_group(
169169
group,
170170
|mut iter| search_include_and_replacegroup(&mut iter, false),
171171
) {

0 commit comments

Comments
 (0)