Skip to content

Commit

Permalink
made separator in join macro optional
Browse files Browse the repository at this point in the history
  • Loading branch information
vlada-shubina committed Nov 9, 2022
1 parent ddcb41b commit aad8d76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class JoinMacroConfig : BaseMacroConfig<JoinMacro, JoinMacroConfig>
private const string SymbolsTypePropertyName = "type";
private const string SymbolsValuePropertyName = "value";

internal JoinMacroConfig(JoinMacro macro, string variableName, string? dataType, IReadOnlyList<(JoinType, string)> symbols, string separator, bool removeEmptyValues)
internal JoinMacroConfig(JoinMacro macro, string variableName, string? dataType, IReadOnlyList<(JoinType, string)> symbols, string separator = "", bool removeEmptyValues = false)
: base(macro, variableName, dataType)
{
Symbols = symbols ?? throw new ArgumentNullException(nameof(symbols));
Expand All @@ -26,7 +26,7 @@ internal JoinMacroConfig(JoinMacro macro, string variableName, string? dataType,
internal JoinMacroConfig(JoinMacro macro, IGeneratedSymbolConfig generatedSymbolConfig)
: base(macro, generatedSymbolConfig.VariableName, generatedSymbolConfig.DataType)
{
Separator = GetMandatoryParameterValue(generatedSymbolConfig, "separator");
Separator = GetOptionalParameterValue(generatedSymbolConfig, "separator") ?? string.Empty;
RemoveEmptyValues = GetOptionalParameterValue(generatedSymbolConfig, "removeEmptyValues", ConvertJTokenToBool);

List<(JoinType Type, string Value)> symbolsList = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,6 @@ public void ObsoleteEvaluateConfigTest()
Assert.Equal(convertedValue, expectedValue);
}

[Fact]
public void InvalidConfigurationTest_MissingSeparator()
{
JoinMacro macro = new();

Dictionary<string, string> jsonParameters = new(StringComparer.OrdinalIgnoreCase);
string symbols =
$"[ {{\"type\":\"const\" , \"value\":\"true\" }}, {{\"type\":\"ref\" , \"value\":\"ref\" }} ]";
jsonParameters.Add("symbols", symbols);

VariableCollection variables = new();
TemplateAuthoringException ex = Assert.Throws<TemplateAuthoringException>(() => macro.Evaluate(_engineEnvironmentSettings, variables, new GeneratedSymbol("test", "join", jsonParameters)));
Assert.Equal("Generated symbol 'test' of type 'join' should have 'separator' property defined.", ex.Message);
}

[Fact]
public void InvalidConfigurationTest_MissingSymbols()
{
Expand Down Expand Up @@ -196,15 +181,13 @@ public void DefaultConfigurationTest()
{
JoinMacro macro = new();

Dictionary<string, string> jsonParameters = new(StringComparer.OrdinalIgnoreCase)
{
{ "separator", JExtensions.ToJsonString(",") }
};
Dictionary<string, string> jsonParameters = new(StringComparer.OrdinalIgnoreCase);
string symbols = $"[ {{\"value\":\"rep\" }} ]";
jsonParameters.Add("symbols", symbols);

JoinMacroConfig config = new(macro, new GeneratedSymbol("test", "join", jsonParameters));

Assert.Equal(string.Empty, config.Separator);
Assert.False(config.RemoveEmptyValues);
Assert.Equal(JoinMacroConfig.JoinType.Const, config.Symbols.Single().Type);
}
Expand Down

0 comments on commit aad8d76

Please sign in to comment.