Skip to content

Commit 86b4e72

Browse files
committed
Adição de testes e melhorias na classe IfCommand
* Testes - Adicionados testes `If_Ident` e `If_Ident_False` para verificar a saída do IfCommand. * Refatoração - Modificado o método `Write` para usar `localIdent` em vez de `idented` para clareza. * Versionamento - Atualizada a versão do projeto de `0.1.2` para `0.1.3` para nova liberação.
1 parent 7201041 commit 86b4e72

3 files changed

Lines changed: 55 additions & 12 deletions

File tree

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator.Tests/Commands/IfTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,46 @@ public void If_Else_WithCommands()
178178
// Assert
179179
Assert.Equal(expected, generated);
180180
}
181+
182+
[Fact]
183+
public void If_Ident()
184+
{
185+
// Arrange
186+
var sb = new StringBuilder();
187+
var expected =
188+
"""
189+
if (1 == 1) { }
190+
191+
192+
""";
193+
194+
// Act
195+
var command = new IfCommand("1 == 1");
196+
command.Write(sb, 1);
197+
var generated = sb.ToString();
198+
199+
// Assert
200+
Assert.Equal(expected, generated);
201+
}
202+
203+
[Fact]
204+
public void If_Ident_False()
205+
{
206+
// Arrange
207+
var sb = new StringBuilder();
208+
var expected =
209+
"""
210+
if (1 == 1) { }
211+
212+
213+
""";
214+
215+
// Act
216+
var command = new IfCommand("1 == 1") { Idented = false };
217+
command.Write(sb, 1);
218+
var generated = sb.ToString();
219+
220+
// Assert
221+
Assert.Equal(expected, generated);
222+
}
181223
}

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/Generators/Commands/IfCommand.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ public void AddElseCommand(GeneratorNode command)
3131

3232
public override void Write(StringBuilder sb, int ident = 0)
3333
{
34-
int idented = Idented ? ident : 0;
34+
int localIdent = Idented ? ident : 0;
3535

36-
sb.Append("if (").Append(condition.GetValue(idented)).Append(")");
36+
sb.Ident(localIdent);
37+
sb.Append("if (").Append(condition.GetValue(localIdent)).Append(")");
3738

3839
if (commands is null || commands.Count is 0)
3940
{
@@ -42,30 +43,30 @@ public override void Write(StringBuilder sb, int ident = 0)
4243
else if (commands.Count is 1)
4344
{
4445
sb.AppendLine();
45-
commands.Write(sb, idented + 1);
46+
commands.Write(sb, localIdent + 1);
4647
}
4748
else
4849
{
49-
sb.AppendLine().Ident(idented).AppendLine("{");
50-
commands.Write(sb, idented + 1);
51-
sb.Ident(idented).AppendLine("}");
50+
sb.AppendLine().Ident(localIdent).AppendLine("{");
51+
commands.Write(sb, localIdent + 1);
52+
sb.Ident(localIdent).AppendLine("}");
5253
}
5354

5455
if (elseCommands is not null && elseCommands.Count > 0)
5556
{
56-
sb.Ident(idented);
57+
sb.Ident(localIdent);
5758

5859
sb.AppendLine("else");
5960

6061
if (elseCommands.Count is 1)
6162
{
62-
elseCommands.Write(sb, idented + 1);
63+
elseCommands.Write(sb, localIdent + 1);
6364
}
6465
else
6566
{
66-
sb.Ident(idented).AppendLine("{");
67-
elseCommands.Write(sb, idented + 1);
68-
sb.Ident(idented).AppendLine("}");
67+
sb.Ident(localIdent).AppendLine("{");
68+
elseCommands.Write(sb, localIdent + 1);
69+
sb.Ident(localIdent).AppendLine("}");
6970
}
7071
}
7172

RoyalCode.Utils/RoyalCode.Extensions.SourceGenerator/RoyalCode.Extensions.SourceGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<TargetFramework>netstandard2.0</TargetFramework>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88

9-
<Ver>0.1.2</Ver>
9+
<Ver>0.1.3</Ver>
1010
<Prev></Prev>
1111

1212
<Version>$(Ver)$(Prev)</Version>

0 commit comments

Comments
 (0)