fn test_empty_string_can_be_parsed() {
let template = "";
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
assert_eq!(template.tokens.len(), 1);
- assert_eq!(template.tokens[0], Token::Text("".to_string()));
+ assert_eq!(template.tokens[0], Token::Text(String::new()));
} else {
panic!("Expected empty template to be parsed");
}
fn fails_on_malformed_directive() {
let template = "{{ Left door open";
- let parsed_template = parse(&template);
+ let parsed_template = parse(template);
assert!(parsed_template.is_none());
}
fn fails_on_malformed_conditional() {
let template = "{{? hello }} NO TERMINATOR!!";
- let parsed_template = parse(&template);
+ let parsed_template = parse(template);
assert!(parsed_template.is_none());
}
fn fails_on_malformed_iterator() {
let template = "{{~ hello }} NO TERMINATOR!!";
- let parsed_template = parse(&template);
+ let parsed_template = parse(template);
assert!(parsed_template.is_none());
}
fn fails_on_malformed_conditional_body() {
let template = "{{? hello }} {{ someone forgot {{?}}";
- let parsed_template = parse(&template);
+ let parsed_template = parse(template);
assert!(parsed_template.is_none());
}
fn fails_on_malformed_iterator_body() {
let template = "{{~ hello }} {{ my right hand claw {{~}}";
- let parsed_template = parse(&template);
+ let parsed_template = parse(template);
assert!(parsed_template.is_none());
}
fn test_fails_on_invalid_directives() {
let template = "My name is {{ name }}";
- let context: Context =
- HashMap::from([("name".to_string(), Value::String("Scrooge".to_string()))]);
-
- let template = parse(&template);
+ let template = parse(template);
assert!(template.is_none());
}
fn test_recognizes_display_directive() {
let template = "My name is: {{= blog }}";
- if let Some(template) = parse(&template) {
+ 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!(
content: "blog".to_string()
}
);
- assert_eq!(template.tokens[2], Token::Text("".to_string()));
+ assert_eq!(template.tokens[2], Token::Text(String::new()));
} else {
panic!("Expected empty template to be parsed");
}
fn test_not_allowed_to_nest_directives_in_display() {
let template = "{{= {{ hello }} }}";
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
assert_eq!(template.tokens.len(), 2);
assert_eq!(
template.tokens[0],
fn test_recognizes_conditional_directive() {
let template = "{{? what }}OK {{= hello }}{{?}}";
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
assert_eq!(template.tokens.len(), 2);
assert_eq!(
template.tokens[0],
Token::DisplayDirective {
content: "hello".to_string()
},
- Token::Text("".to_string()),
+ Token::Text(String::new()),
]
}
);
- assert_eq!(template.tokens[1], Token::Text("".to_string()));
+ assert_eq!(template.tokens[1], Token::Text(String::new()));
} else {
panic!("Expected empty template to be parsed");
}
fn test_recognizes_iterator_directive() {
let template = "{{~ murder:crow }}Sound: {{= caw }}{{~}}";
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
assert_eq!(template.tokens.len(), 2);
assert_eq!(
template.tokens[0],
Token::DisplayDirective {
content: "caw".to_string()
},
- Token::Text("".to_string()),
+ Token::Text(String::new()),
]
}
);
- assert_eq!(template.tokens[1], Token::Text("".to_string()));
+ assert_eq!(template.tokens[1], Token::Text(String::new()));
} else {
panic!("Expected empty template to be parsed");
}
),
]);
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
match template.render(&context) {
Err(error) => panic!("{error}"),
Ok(output) => assert_eq!(
let context: Context = HashMap::new();
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
let output = template.render(&context);
assert!(output.is_err());
} else {
let context: Context = HashMap::new();
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
let output = template.render(&context);
assert!(output.is_err());
} else {
Value::String("more a comment than a question".to_string()),
)]);
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
let output = template.render(&context);
assert!(output.is_err());
} else {
let context: Context = HashMap::new();
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
let output = template.render(&context);
assert!(output.is_err());
} else {
)])]),
)]);
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
let output = template.render(&context);
assert!(output.is_err());
} else {
let context: Context =
HashMap::from([("sheeps".to_string(), Value::String("wolf".to_string()))]);
- if let Some(template) = parse(&template) {
+ if let Some(template) = parse(template) {
let output = template.render(&context);
assert!(output.is_err());
} else {
&PathBuf::from("/norealpath/ifthisfails/then/wow"),
"index.html",
);
- assert!(!template.is_none());
+ assert!(template.is_some());
}
#[test]
&PathBuf::from("/norealpath/ifthisfails/then/wow"),
"index.txt",
);
- assert!(!template.is_none());
+ assert!(template.is_some());
}
#[test]
&PathBuf::from("/norealpath/ifthisfails/then/wow"),
"index.gmi",
);
- assert!(!template.is_none());
+ assert!(template.is_some());
}
#[test]
&PathBuf::from("/norealpath/ifthisfails/then/wow"),
"index.rss",
);
- assert!(!template.is_none());
+ assert!(template.is_some());
}
}