@@ -140,12 +140,11 @@ pub fn next(_h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Result<(), R
140
140
mod tests {
141
141
use super :: * ;
142
142
143
+ static TEMPLATE : & ' static str =
144
+ "{{#previous}}{{title}}: {{link}}{{/previous}}|{{#next}}{{title}}: {{link}}{{/next}}" ;
145
+
143
146
#[ test]
144
147
fn test_next_previous ( ) {
145
- let template = "
146
- {{#previous}}{{title}}: {{link}}{{/previous}}
147
- {{#next}}{{title}}: {{link}}{{/next}}" ;
148
-
149
148
let data = json ! ( {
150
149
"name" : "two" ,
151
150
"path" : "two.path" ,
@@ -169,8 +168,67 @@ mod tests {
169
168
h. register_helper ( "previous" , Box :: new ( previous) ) ;
170
169
h. register_helper ( "next" , Box :: new ( next) ) ;
171
170
172
- assert_eq ! ( h. template_render( template, & data) . unwrap( ) , "
173
- one: one.html
174
- three: three.html" ) ;
171
+ assert_eq ! (
172
+ h. template_render( TEMPLATE , & data) . unwrap( ) ,
173
+ "one: one.html|three: three.html" ) ;
174
+ }
175
+
176
+ #[ test]
177
+ fn test_first ( ) {
178
+ let data = json ! ( {
179
+ "name" : "one" ,
180
+ "path" : "one.path" ,
181
+ "chapters" : [
182
+ {
183
+ "name" : "one" ,
184
+ "path" : "one.path"
185
+ } ,
186
+ {
187
+ "name" : "two" ,
188
+ "path" : "two.path" ,
189
+ } ,
190
+ {
191
+ "name" : "three" ,
192
+ "path" : "three.path"
193
+ }
194
+ ]
195
+ } ) ;
196
+
197
+ let mut h = Handlebars :: new ( ) ;
198
+ h. register_helper ( "previous" , Box :: new ( previous) ) ;
199
+ h. register_helper ( "next" , Box :: new ( next) ) ;
200
+
201
+ assert_eq ! (
202
+ h. template_render( TEMPLATE , & data) . unwrap( ) ,
203
+ "|two: two.html" ) ;
204
+ }
205
+ #[ test]
206
+ fn test_last ( ) {
207
+ let data = json ! ( {
208
+ "name" : "three" ,
209
+ "path" : "three.path" ,
210
+ "chapters" : [
211
+ {
212
+ "name" : "one" ,
213
+ "path" : "one.path"
214
+ } ,
215
+ {
216
+ "name" : "two" ,
217
+ "path" : "two.path" ,
218
+ } ,
219
+ {
220
+ "name" : "three" ,
221
+ "path" : "three.path"
222
+ }
223
+ ]
224
+ } ) ;
225
+
226
+ let mut h = Handlebars :: new ( ) ;
227
+ h. register_helper ( "previous" , Box :: new ( previous) ) ;
228
+ h. register_helper ( "next" , Box :: new ( next) ) ;
229
+
230
+ assert_eq ! (
231
+ h. template_render( TEMPLATE , & data) . unwrap( ) ,
232
+ "two: two.html|" ) ;
175
233
}
176
234
}
0 commit comments