diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-04-06 01:16:53 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-04-06 01:16:53 +0200 |
| commit | d51c665a6dbd6dd8b47c194ea391286a55efbcbd (patch) | |
| tree | 23903f0b876b47d4a6f5cacfac574ba84215f3d3 /src | |
| parent | 9b9e713ebaa9e934d291c4e220872433b5fcc9f6 (diff) | |
Use get in template
Diffstat (limited to 'src')
| -rw-r--r-- | src/template.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/template.rs b/src/template.rs index 8e61978..9bc00dd 100644 --- a/src/template.rs +++ b/src/template.rs @@ -319,7 +319,7 @@ mod tests { if let Some(template) = parse(template) { assert_eq!(template.tokens.len(), 1); - assert_eq!(template.tokens[0], Token::Text(String::new())); + assert_eq!(template.tokens.first(), Some(&Token::Text(String::new()))); } else { panic!("Expected empty template to be parsed"); } @@ -379,14 +379,14 @@ mod tests { if let Some(template) = parse(template) { assert_eq!(template.tokens.len(), 3); - assert_eq!(template.tokens[0], Token::Text("My name is: ".to_string())); + assert_eq!(template.tokens.first(), Some(&Token::Text("My name is: ".to_string()))); assert_eq!( - template.tokens[1], - Token::DisplayDirective { + template.tokens.get(1), + Some(&Token::DisplayDirective { content: "blog".to_string() - } + }) ); - assert_eq!(template.tokens[2], Token::Text(String::new())); + assert_eq!(template.tokens.get(2), Some(&Token::Text(String::new()))); } else { panic!("Expected empty template to be parsed"); } @@ -399,12 +399,12 @@ mod tests { if let Some(template) = parse(template) { assert_eq!(template.tokens.len(), 2); assert_eq!( - template.tokens[0], - Token::DisplayDirective { + template.tokens.first(), + Some(&Token::DisplayDirective { content: "{{ hello".to_string() - } + }) ); - assert_eq!(template.tokens[1], Token::Text(" }}".to_string())); + assert_eq!(template.tokens.get(1), Some(&Token::Text(" }}".to_string()))); } else { panic!("Expected empty template to be parsed"); } @@ -417,8 +417,8 @@ mod tests { if let Some(template) = parse(template) { assert_eq!(template.tokens.len(), 2); assert_eq!( - template.tokens[0], - Token::ConditionalDirective { + template.tokens.first(), + Some(&Token::ConditionalDirective { condition: "what".to_string(), children: vec![ Token::Text("OK ".to_string()), @@ -427,9 +427,9 @@ mod tests { }, Token::Text(String::new()), ] - } + }) ); - assert_eq!(template.tokens[1], Token::Text(String::new())); + assert_eq!(template.tokens.get(1), Some(&Token::Text(String::new()))); } else { panic!("Expected empty template to be parsed"); } @@ -442,8 +442,8 @@ mod tests { if let Some(template) = parse(template) { assert_eq!(template.tokens.len(), 2); assert_eq!( - template.tokens[0], - Token::IteratorDirective { + template.tokens.first(), + Some(&Token::IteratorDirective { collection: "murder".to_string(), member_label: "crow".to_string(), children: vec![ @@ -453,9 +453,9 @@ mod tests { }, Token::Text(String::new()), ] - } + }) ); - assert_eq!(template.tokens[1], Token::Text(String::new())); + assert_eq!(template.tokens.get(1), Some(&Token::Text(String::new()))); } else { panic!("Expected empty template to be parsed"); } |