mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-10 20:36:21 +00:00
fixes
This commit is contained in:
parent
cd128c3315
commit
50f6f33773
2 changed files with 16 additions and 36 deletions
|
@ -193,7 +193,6 @@ mod tests {
|
||||||
fn test_builtin_django_tags() -> Result<(), anyhow::Error> {
|
fn test_builtin_django_tags() -> Result<(), anyhow::Error> {
|
||||||
let specs = TagSpecs::load_builtin_specs()?;
|
let specs = TagSpecs::load_builtin_specs()?;
|
||||||
|
|
||||||
// Just verify that common Django tags exist
|
|
||||||
let expected_tags = ["if", "for", "block"];
|
let expected_tags = ["if", "for", "block"];
|
||||||
let missing_tags = [
|
let missing_tags = [
|
||||||
"extends",
|
"extends",
|
||||||
|
@ -211,7 +210,11 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
for tag in missing_tags {
|
for tag in missing_tags {
|
||||||
assert!(specs.get(tag).is_none(), "{} tag should not be present yet", tag);
|
assert!(
|
||||||
|
specs.get(tag).is_none(),
|
||||||
|
"{} tag should not be present yet",
|
||||||
|
tag
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -219,11 +222,9 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_user_defined_tags() -> Result<(), anyhow::Error> {
|
fn test_user_defined_tags() -> Result<(), anyhow::Error> {
|
||||||
// Create a temporary directory for our test project
|
|
||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
let root = dir.path();
|
let root = dir.path();
|
||||||
|
|
||||||
// Create a pyproject.toml with custom tags
|
|
||||||
let pyproject_content = r#"
|
let pyproject_content = r#"
|
||||||
[tool.djls.template.tags.mytag]
|
[tool.djls.template.tags.mytag]
|
||||||
type = "block"
|
type = "block"
|
||||||
|
@ -233,14 +234,11 @@ args = [{ name = "myarg", required = true }]
|
||||||
"#;
|
"#;
|
||||||
fs::write(root.join("pyproject.toml"), pyproject_content)?;
|
fs::write(root.join("pyproject.toml"), pyproject_content)?;
|
||||||
|
|
||||||
// Load both builtin and user specs
|
|
||||||
let specs = TagSpecs::load_all(root)?;
|
let specs = TagSpecs::load_all(root)?;
|
||||||
|
|
||||||
// Check that builtin tags are still there
|
|
||||||
let if_tag = specs.get("if").expect("if tag should be present");
|
let if_tag = specs.get("if").expect("if tag should be present");
|
||||||
assert_eq!(if_tag.tag_type, TagType::Block);
|
assert_eq!(if_tag.tag_type, TagType::Block);
|
||||||
|
|
||||||
// Check our custom tag
|
|
||||||
let my_tag = specs.get("mytag").expect("mytag should be present");
|
let my_tag = specs.get("mytag").expect("mytag should be present");
|
||||||
assert_eq!(my_tag.tag_type, TagType::Block);
|
assert_eq!(my_tag.tag_type, TagType::Block);
|
||||||
assert_eq!(my_tag.closing, Some("endmytag".to_string()));
|
assert_eq!(my_tag.closing, Some("endmytag".to_string()));
|
||||||
|
@ -256,18 +254,15 @@ args = [{ name = "myarg", required = true }]
|
||||||
assert_eq!(arg.name, "myarg");
|
assert_eq!(arg.name, "myarg");
|
||||||
assert!(arg.required);
|
assert!(arg.required);
|
||||||
|
|
||||||
// Clean up temp dir
|
|
||||||
dir.close()?;
|
dir.close()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_config_file_priority() -> Result<(), anyhow::Error> {
|
fn test_config_file_priority() -> Result<(), anyhow::Error> {
|
||||||
// Create a temporary directory for our test project
|
|
||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
let root = dir.path();
|
let root = dir.path();
|
||||||
|
|
||||||
// Create all config files with different tags
|
|
||||||
let djls_content = r#"
|
let djls_content = r#"
|
||||||
[mytag1]
|
[mytag1]
|
||||||
type = "block"
|
type = "block"
|
||||||
|
@ -282,21 +277,17 @@ mytag2.closing = "endmytag2"
|
||||||
"#;
|
"#;
|
||||||
fs::write(root.join("pyproject.toml"), pyproject_content)?;
|
fs::write(root.join("pyproject.toml"), pyproject_content)?;
|
||||||
|
|
||||||
// Load user specs
|
|
||||||
let specs = TagSpecs::load_user_specs(root)?;
|
let specs = TagSpecs::load_user_specs(root)?;
|
||||||
|
|
||||||
// Should only have mytag1 since djls.toml has highest priority
|
|
||||||
assert!(specs.get("mytag1").is_some(), "mytag1 should be present");
|
assert!(specs.get("mytag1").is_some(), "mytag1 should be present");
|
||||||
assert!(
|
assert!(
|
||||||
specs.get("mytag2").is_none(),
|
specs.get("mytag2").is_none(),
|
||||||
"mytag2 should not be present"
|
"mytag2 should not be present"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove djls.toml and try again
|
|
||||||
fs::remove_file(root.join("djls.toml"))?;
|
fs::remove_file(root.join("djls.toml"))?;
|
||||||
let specs = TagSpecs::load_user_specs(root)?;
|
let specs = TagSpecs::load_user_specs(root)?;
|
||||||
|
|
||||||
// Should now have mytag2 since pyproject.toml has second priority
|
|
||||||
assert!(
|
assert!(
|
||||||
specs.get("mytag1").is_none(),
|
specs.get("mytag1").is_none(),
|
||||||
"mytag1 should not be present"
|
"mytag1 should not be present"
|
||||||
|
|
|
@ -1,30 +1,19 @@
|
||||||
# Django built-in template tags
|
[django.template.defaulttags.block]
|
||||||
[django.template.defaulttags.if]
|
closing = "endblock"
|
||||||
branches = ["elif", "else"]
|
|
||||||
closing = "endif"
|
|
||||||
type = "block"
|
type = "block"
|
||||||
|
|
||||||
[[django.template.defaulttags.if.args]]
|
|
||||||
name = "condition"
|
|
||||||
required = true
|
|
||||||
|
|
||||||
[django.template.defaulttags.for]
|
[django.template.defaulttags.for]
|
||||||
branches = ["empty"]
|
branches = ["empty"]
|
||||||
closing = "endfor"
|
closing = "endfor"
|
||||||
type = "block"
|
type = "block"
|
||||||
|
args = [
|
||||||
|
{ name = "{item}", required = true },
|
||||||
|
{ name = "in", required = true },
|
||||||
|
{ name = "{iterable}", required = true },
|
||||||
|
]
|
||||||
|
|
||||||
[[django.template.defaulttags.for.args]]
|
[django.template.defaulttags.if]
|
||||||
name = "{item}"
|
branches = ["elif", "else"]
|
||||||
required = true
|
closing = "endif"
|
||||||
|
|
||||||
[[django.template.defaulttags.for.args]]
|
|
||||||
name = "in"
|
|
||||||
required = true
|
|
||||||
|
|
||||||
[[django.template.defaulttags.for.args]]
|
|
||||||
name = "{iterable}"
|
|
||||||
required = true
|
|
||||||
|
|
||||||
[django.template.defaulttags.block]
|
|
||||||
closing = "endblock"
|
|
||||||
type = "block"
|
type = "block"
|
||||||
|
args = [{ name = "condition", required = true }]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue