|
| 1 | +use codebook::queries::LanguageType; |
| 2 | + |
| 3 | +use super::utils::{assert_spelling, assert_spelling_at}; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn test_hcl_attribute_identifiers() { |
| 7 | + let sample_text = r#" |
| 8 | +resource "aws_instance" "web_server" { |
| 9 | + instnace_type = "t3.micro" |
| 10 | + descriptin = "Valid text" |
| 11 | +} |
| 12 | +"#; |
| 13 | + |
| 14 | + assert_spelling( |
| 15 | + LanguageType::Hcl, |
| 16 | + sample_text, |
| 17 | + &["instnace", "descriptin"], |
| 18 | + &["resource", "aws_instance", "web_server"], |
| 19 | + ); |
| 20 | +} |
| 21 | + |
| 22 | +#[test] |
| 23 | +fn test_hcl_strings_and_comments() { |
| 24 | + let sample_text = r#" |
| 25 | +# Comment with a speling error. |
| 26 | +
|
| 27 | +/* Multi-line comment |
| 28 | +with an error on the seconnd line. */ |
| 29 | +
|
| 30 | +variable "region" { |
| 31 | + description = "Cloud regon for the deploymant." |
| 32 | + default = "eu-west-1" |
| 33 | +} |
| 34 | +
|
| 35 | +resource "aws_instance" "web_server" { |
| 36 | + user_data = <<-EOT |
| 37 | + Configure the servver for this environment. |
| 38 | + Enable applicaton logging for ${var.region}. |
| 39 | + EOT |
| 40 | +} |
| 41 | +"#; |
| 42 | + |
| 43 | + assert_spelling_at( |
| 44 | + LanguageType::Hcl, |
| 45 | + sample_text, |
| 46 | + &[ |
| 47 | + ("speling", &[0]), |
| 48 | + ("seconnd", &[0]), |
| 49 | + ("regon", &[0]), |
| 50 | + ("deploymant", &[0]), |
| 51 | + ("servver", &[0]), |
| 52 | + ("applicaton", &[0]), |
| 53 | + ], |
| 54 | + ); |
| 55 | +} |
| 56 | + |
| 57 | +#[test] |
| 58 | +fn test_hcl_only_checks_identifier_definitions() { |
| 59 | + let sample_text = r#" |
| 60 | +variable "source_value" { |
| 61 | + default = "valid" |
| 62 | +} |
| 63 | +
|
| 64 | +locals { |
| 65 | + misspeled_value = var.source_value |
| 66 | +} |
| 67 | +
|
| 68 | +output "result" { |
| 69 | + value = local.misspeled_value |
| 70 | +} |
| 71 | +"#; |
| 72 | + |
| 73 | + assert_spelling_at( |
| 74 | + LanguageType::Hcl, |
| 75 | + sample_text, |
| 76 | + &[ |
| 77 | + // The attribute name is checked at its definition, but the same |
| 78 | + // text in the traversal expression is not checked as a usage. |
| 79 | + ("misspeled", &[0]), |
| 80 | + ], |
| 81 | + ); |
| 82 | +} |
| 83 | + |
| 84 | +#[test] |
| 85 | +fn test_hcl_string_interpolation() { |
| 86 | + let sample_text = r#" |
| 87 | +variable "region" { |
| 88 | + default = "eu-west-1" |
| 89 | +} |
| 90 | +
|
| 91 | +locals { |
| 92 | + message = "Deploy to the regon ${var.misspeled_reference}" |
| 93 | +} |
| 94 | +"#; |
| 95 | + |
| 96 | + assert_spelling( |
| 97 | + LanguageType::Hcl, |
| 98 | + sample_text, |
| 99 | + &["regon"], |
| 100 | + &["misspeled_reference"], |
| 101 | + ); |
| 102 | +} |
0 commit comments