File tree 6 files changed +40
-0
lines changed
6 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 2
2
macro_rules! equal_rule {
3
3
( ( $e: literal, $t: ty) ) => {
4
4
paste:: item! {
5
+ /// `Equal[N][TYPE]` is a type that indicates that the number is equal to `N`.
5
6
#[ allow( dead_code) ]
6
7
pub type [ <Equal $e $t>] = $crate:: Refined <[ <EqualRule $e $t>] >;
7
8
Original file line number Diff line number Diff line change 1
1
macro_rules! even_rule {
2
2
( $t: ty) => {
3
3
paste:: item! {
4
+ /// `Even[TYPE]` is a type that represents that the number is even.
4
5
#[ allow( dead_code) ]
5
6
pub type [ <Even $t: upper>] = $crate:: Refined <[ <EvenRule $t: upper>] >;
6
7
Original file line number Diff line number Diff line change 2
2
macro_rules! greater_rule {
3
3
( ( $e: literal, $t: ty) ) => {
4
4
paste:: item! {
5
+ /// `Greater[N][TYPE]` is a type that indicates that the number is greater than `N`.
5
6
#[ allow( dead_code) ]
6
7
pub type [ <Greater $e $t>] = $crate:: Refined <[ <GreaterRule $e $t>] >;
7
8
Original file line number Diff line number Diff line change 2
2
macro_rules! less_rule {
3
3
( ( $e: literal, $t: ty) ) => {
4
4
paste:: item! {
5
+ /// `Less[N][TYPE]` is a type that indicates that the number is less than `N`.
5
6
#[ allow( dead_code) ]
6
7
pub type [ <Less $e $t>] = $crate:: Refined <[ <LessRule $e $t>] >;
7
8
Original file line number Diff line number Diff line change 1
1
macro_rules! odd_rule {
2
2
( $t: ty) => {
3
3
paste:: item! {
4
+ /// `Odd[TYPE]` is a type that represents that the number is odd.
4
5
pub type [ <Odd $t: upper>] = $crate:: Refined <[ <OddRule $t: upper>] >;
5
6
pub struct [ <OddRule $t: upper>] ;
6
7
Original file line number Diff line number Diff line change @@ -3,6 +3,18 @@ use crate::rule::Rule;
3
3
use crate :: Refined ;
4
4
use regex:: Regex ;
5
5
6
+ /// The `Alphabet` type represents a type that can contain zero or more alphabetic characters.
7
+ ///
8
+ /// # Example
9
+ /// ```rust
10
+ /// # use refined_type::rule::Alphabet;
11
+ ///
12
+ /// let alphabet_result = Alphabet::new("alphabet".to_string());
13
+ /// assert!(alphabet_result.is_ok());
14
+ ///
15
+ /// let alphabet_result = Alphabet::new("I am the 1st".to_string());
16
+ /// assert!(alphabet_result.is_err());
17
+ /// ```
6
18
pub type Alphabet = Refined < AlphabetRule > ;
7
19
8
20
/// A string consisting entirely of alphabetic characters
@@ -26,3 +38,26 @@ impl Rule for AlphabetRule {
26
38
}
27
39
}
28
40
}
41
+
42
+ #[ cfg( test) ]
43
+ mod test {
44
+ use crate :: rule:: Alphabet ;
45
+
46
+ #[ test]
47
+ fn test_alphabet_ok_empty ( ) {
48
+ let alphabet_result = Alphabet :: new ( "" . to_string ( ) ) ;
49
+ assert ! ( alphabet_result. is_ok( ) ) ;
50
+ }
51
+
52
+ #[ test]
53
+ fn test_alphabet_ok_non_empty ( ) {
54
+ let alphabet_result = Alphabet :: new ( "alphabet" . to_string ( ) ) ;
55
+ assert ! ( alphabet_result. is_ok( ) ) ;
56
+ }
57
+
58
+ #[ test]
59
+ fn test_alphabet_err ( ) {
60
+ let alphabet_result = Alphabet :: new ( "I am the 1st" . to_string ( ) ) ;
61
+ assert ! ( alphabet_result. is_err( ) ) ;
62
+ }
63
+ }
You can’t perform that action at this time.
0 commit comments