Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly set @input field names when #!set --name is used #3302

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ private static string GetDibContent(Dictionary<string, object> metadata)
[Fact]
public void Input_tokens_are_parsed_from_dib_files()
{
var dib = "#!value --from-file @input:filename --name myfile";
var dib = """
#!value --from-file @input:"Enter a filename" --name myfile
""";

var document = CodeSubmission.Parse(dib);

Expand All @@ -586,7 +588,7 @@ public void Input_tokens_are_parsed_from_dib_files()
.Which
.ValueName
.Should()
.Be("filename");
.Be("myfile");
}

[Fact]
Expand Down Expand Up @@ -622,6 +624,40 @@ public void When_an_input_field_name_is_repeated_then_only_one_is_created_in_the
.BeEquivalentTo(new InputField("the-password", "password"));
}

[Fact]
public void When_using_set_magic_then_input_field_names_are_set_using_name_option()
{
var dib = """
#!set --name value_name --value @input:"This is the prompt"
""";

var document = CodeSubmission.Parse(dib);

document.GetInputFields()
.Should()
.ContainSingle()
.Which
.Should()
.BeEquivalentTo(new InputField("value_name", "text"));
}

[Fact]
public void When_using_set_magic_then_password_field_names_are_set_using_name_option()
{
var dib = """
#!set --name value_name --value @password:"This is the prompt"
""";

var document = CodeSubmission.Parse(dib);

document.GetInputFields()
.Should()
.ContainSingle()
.Which
.Should()
.BeEquivalentTo(new InputField("value_name", "password"));
}

private async Task<string> RoundTripDib(string filePath)
{
var expectedContent = await File.ReadAllTextAsync(filePath);
Expand Down
Loading
Loading