mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-11 21:06:31 +00:00
add test for error recovery
This commit is contained in:
parent
6dfe47b87c
commit
92ecfcb83c
3 changed files with 83 additions and 3 deletions
|
@ -736,9 +736,32 @@ mod tests {
|
||||||
let source = "<style>body { color: blue; ";
|
let source = "<style>body { color: blue; ";
|
||||||
let tokens = Lexer::new(source).tokenize().unwrap();
|
let tokens = Lexer::new(source).tokenize().unwrap();
|
||||||
let mut parser = Parser::new(tokens);
|
let mut parser = Parser::new(tokens);
|
||||||
let result = parser.parse().unwrap();
|
let ast = parser.parse().unwrap();
|
||||||
assert_eq!(result.errors().len(), 1);
|
insta::assert_yaml_snapshot!(ast);
|
||||||
assert!(matches!(&result.errors()[0], AstError::UnclosedTag(tag) if tag == "style"));
|
assert_eq!(ast.errors().len(), 1);
|
||||||
|
assert!(matches!(&ast.errors()[0], AstError::UnclosedTag(tag) if tag == "style"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_error_recovery() {
|
||||||
|
let source = r#"<div class="container">
|
||||||
|
<h1>Header</h1>
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<p>Welcome {{ user.name }}</p>
|
||||||
|
<div>
|
||||||
|
{# This div is unclosed #}
|
||||||
|
{% for item in items %}
|
||||||
|
<span>{{ item }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
<footer>Page Footer</footer>
|
||||||
|
</div>"#;
|
||||||
|
let tokens = Lexer::new(source).tokenize().unwrap();
|
||||||
|
let mut parser = Parser::new(tokens);
|
||||||
|
let ast = parser.parse().unwrap();
|
||||||
|
insta::assert_yaml_snapshot!(ast);
|
||||||
|
assert_eq!(ast.errors().len(), 1);
|
||||||
|
assert!(matches!(&ast.errors()[0], AstError::UnclosedTag(tag) if tag == "div"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
---
|
||||||
|
source: crates/djls-template-ast/src/parser.rs
|
||||||
|
expression: ast
|
||||||
|
---
|
||||||
|
nodes:
|
||||||
|
- Html:
|
||||||
|
Element:
|
||||||
|
tag_name: div
|
||||||
|
attributes:
|
||||||
|
class:
|
||||||
|
Value: container
|
||||||
|
children:
|
||||||
|
- Html:
|
||||||
|
Element:
|
||||||
|
tag_name: h1
|
||||||
|
attributes: {}
|
||||||
|
children:
|
||||||
|
- Text: Header
|
||||||
|
- Django:
|
||||||
|
Tag:
|
||||||
|
Block:
|
||||||
|
name: if
|
||||||
|
bits:
|
||||||
|
- if
|
||||||
|
- user.is_authenticated
|
||||||
|
children:
|
||||||
|
- Html:
|
||||||
|
Element:
|
||||||
|
tag_name: p
|
||||||
|
attributes: {}
|
||||||
|
children:
|
||||||
|
- Text: "Welcome "
|
||||||
|
- Django:
|
||||||
|
Variable:
|
||||||
|
bits:
|
||||||
|
- user
|
||||||
|
- name
|
||||||
|
filters: []
|
||||||
|
- Django:
|
||||||
|
Tag:
|
||||||
|
Closing:
|
||||||
|
name: endif
|
||||||
|
bits: []
|
||||||
|
- Html:
|
||||||
|
Element:
|
||||||
|
tag_name: footer
|
||||||
|
attributes: {}
|
||||||
|
children:
|
||||||
|
- Text: Page Footer
|
||||||
|
errors: []
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
source: crates/djls-template-ast/src/parser.rs
|
||||||
|
expression: ast
|
||||||
|
---
|
||||||
|
nodes: []
|
||||||
|
errors:
|
||||||
|
- UnclosedTag: style
|
Loading…
Add table
Add a link
Reference in a new issue