Skip to content

Commit

Permalink
🐛 : remove surrounding quotes from parsed HCL
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Nov 15, 2019
1 parent 6c2b03c commit 9092e04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/main/java/io/codeka/gaia/hcl/HclVisitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ class HclVisitor : hclBaseVisitor<Unit>() {
private var currentOutput: Output = Output()

override fun visitVariableDirective(ctx: hclParser.VariableDirectiveContext) {
currentVariable = Variable(name = ctx.STRING().text)
currentVariable = Variable(name = ctx.STRING().text.removeSurrounding("\""))
variables.add(currentVariable)
visitChildren(ctx)
}

override fun visitVariableType(ctx: hclParser.VariableTypeContext) {
currentVariable.type = ctx.type().text
currentVariable.type = ctx.type().text.removeSurrounding("\"")
}

override fun visitVariableDefault(ctx: hclParser.VariableDefaultContext) {
currentVariable.defaultValue = ctx.expression().text
currentVariable.defaultValue = ctx.expression().text.removeSurrounding("\"")
}

override fun visitVariableDescription(ctx: hclParser.VariableDescriptionContext) {
currentVariable.description = ctx.STRING().text
currentVariable.description = ctx.STRING().text.removeSurrounding("\"")
}

override fun visitOutputDirective(ctx: hclParser.OutputDirectiveContext) {
currentOutput = Output(name = ctx.STRING().text)
currentOutput = Output(name = ctx.STRING().text.removeSurrounding("\""))
outputs.add(currentOutput)
visitChildren(ctx)
}

override fun visitOutputDescription(ctx: hclParser.OutputDescriptionContext) {
currentOutput.description = ctx.STRING().text
currentOutput.description = ctx.STRING().text.removeSurrounding("\"")
}

override fun visitOutputValue(ctx: hclParser.OutputValueContext) {
currentOutput.value = ctx.expression().text
currentOutput.value = ctx.expression().text.removeSurrounding("\"")
}

override fun visitOutputSensitive(ctx: hclParser.OutputSensitiveContext) {
currentOutput.sensitive = ctx.BOOLEAN().text
currentOutput.sensitive = ctx.BOOLEAN().text.removeSurrounding("\"")
}
}
18 changes: 9 additions & 9 deletions src/test/java/io/codeka/gaia/hcl/HCLParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ void parsing_variables_shouldWorkWithVisitor() throws IOException {
// then
assertThat(variables).hasSize(3);

var stringVar = new Variable("\"string_var\"");
stringVar.setType("\"string\"");
stringVar.setDescription("\"a test string var\"");
stringVar.setDefaultValue("\"foo\"");
var stringVar = new Variable("string_var");
stringVar.setType("string");
stringVar.setDescription("a test string var");
stringVar.setDefaultValue("foo");

var numberVar = new Variable("\"number_var\"");
var numberVar = new Variable("number_var");
numberVar.setType("number");
numberVar.setDescription("\"a test number var\"");
numberVar.setDescription("a test number var");
numberVar.setDefaultValue("42");

var boolVar = new Variable("\"bool_var\"");
var boolVar = new Variable("bool_var");
boolVar.setDefaultValue("false");

assertThat(variables).contains(stringVar, numberVar, boolVar);
Expand Down Expand Up @@ -65,8 +65,8 @@ void parsing_outputs_shouldWorkWithVisitor() throws IOException {
// then
assertThat(outputs).hasSize(2);

var output1 = new Output("\"instance_ip_addr\"", "\"${aws_instance.server.private_ip}\"", "\"The private IP address of the main server instance.\"", "false");
var output2 = new Output("\"db_password\"", "aws_db_instance.db[1].password", "\"The password for logging in to the database.\"", "true");
var output1 = new Output("instance_ip_addr", "${aws_instance.server.private_ip}", "The private IP address of the main server instance.", "false");
var output2 = new Output("db_password", "aws_db_instance.db[1].password", "The password for logging in to the database.", "true");

assertThat(outputs).contains(output1, output2);
}
Expand Down

0 comments on commit 9092e04

Please sign in to comment.