diff options
-rw-r--r-- | crates/libsyntax2/src/lexer/ptr.rs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/crates/libsyntax2/src/lexer/ptr.rs b/crates/libsyntax2/src/lexer/ptr.rs index aa59e33cc..c9a5354ea 100644 --- a/crates/libsyntax2/src/lexer/ptr.rs +++ b/crates/libsyntax2/src/lexer/ptr.rs | |||
@@ -86,3 +86,81 @@ impl<'s> Ptr<'s> { | |||
86 | self.text[len as usize..].chars() | 86 | self.text[len as usize..].chars() |
87 | } | 87 | } |
88 | } | 88 | } |
89 | |||
90 | #[cfg(test)] | ||
91 | mod tests { | ||
92 | use super::*; | ||
93 | |||
94 | #[test] | ||
95 | fn test_current() { | ||
96 | let ptr = Ptr::new("test"); | ||
97 | assert_eq!(ptr.current(), Some('t')); | ||
98 | } | ||
99 | |||
100 | #[test] | ||
101 | fn test_nth() { | ||
102 | let ptr = Ptr::new("test"); | ||
103 | assert_eq!(ptr.nth(0), Some('t')); | ||
104 | assert_eq!(ptr.nth(1), Some('e')); | ||
105 | assert_eq!(ptr.nth(2), Some('s')); | ||
106 | assert_eq!(ptr.nth(3), Some('t')); | ||
107 | assert_eq!(ptr.nth(4), None); | ||
108 | } | ||
109 | |||
110 | #[test] | ||
111 | fn test_at() { | ||
112 | let ptr = Ptr::new("test"); | ||
113 | assert!(ptr.at('t')); | ||
114 | assert!(!ptr.at('a')); | ||
115 | } | ||
116 | |||
117 | #[test] | ||
118 | fn test_at_str() { | ||
119 | let ptr = Ptr::new("test"); | ||
120 | assert!(ptr.at_str("t")); | ||
121 | assert!(ptr.at_str("te")); | ||
122 | assert!(ptr.at_str("test")); | ||
123 | assert!(!ptr.at_str("tests")); | ||
124 | assert!(!ptr.at_str("rust")); | ||
125 | } | ||
126 | |||
127 | #[test] | ||
128 | fn test_at_p() { | ||
129 | let ptr = Ptr::new("test"); | ||
130 | assert!(ptr.at_p(|c| c == 't')); | ||
131 | assert!(!ptr.at_p(|c| c == 'e')); | ||
132 | } | ||
133 | |||
134 | #[test] | ||
135 | fn test_nth_is_p() { | ||
136 | let ptr = Ptr::new("test"); | ||
137 | assert!(ptr.nth_is_p(0,|c| c == 't')); | ||
138 | assert!(!ptr.nth_is_p(1,|c| c == 't')); | ||
139 | assert!(ptr.nth_is_p(3,|c| c == 't')); | ||
140 | assert!(!ptr.nth_is_p(150,|c| c == 't')); | ||
141 | } | ||
142 | |||
143 | #[test] | ||
144 | fn test_bump() { | ||
145 | let mut ptr = Ptr::new("test"); | ||
146 | assert_eq!(ptr.current(), Some('t')); | ||
147 | ptr.bump(); | ||
148 | assert_eq!(ptr.current(), Some('e')); | ||
149 | ptr.bump(); | ||
150 | assert_eq!(ptr.current(), Some('s')); | ||
151 | ptr.bump(); | ||
152 | assert_eq!(ptr.current(), Some('t')); | ||
153 | ptr.bump(); | ||
154 | assert_eq!(ptr.current(), None); | ||
155 | ptr.bump(); | ||
156 | assert_eq!(ptr.current(), None); | ||
157 | } | ||
158 | |||
159 | #[test] | ||
160 | fn test_bump_while() { | ||
161 | let mut ptr = Ptr::new("test"); | ||
162 | assert_eq!(ptr.current(), Some('t')); | ||
163 | ptr.bump_while(|c| c != 's'); | ||
164 | assert_eq!(ptr.current(), Some('s')); | ||
165 | } | ||
166 | } | ||