mirror of
https://github.com/microsoft/autogen.git
synced 2026-01-24 18:28:30 -05:00
* Update FunctionCallTemplate.tt
changed the desscription assigning to handle double quotes in comments and prevent the generated code from breaking.
* Added the necessary changes
Fixed handling of double quotes in descriptions within FunctionCallTemplate.tt.
Standardized newline characters to ensure consistency.
Updated test cases in FunctionCallTemplateEncodingTests to verify correct encoding of double quotes in descriptions.
Cleaned up unnecessary using directives in FunctionCallTemplateEncodingTests.
Aligned the template with the approved test output.
* test cases passing
Test cases passing like `Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 9, Skipped: 0, Total: 9, Duration: 66 ms - AutoGen.SourceGenerator.Tests.dll (net8.0)`
* Delete FunctionCallTemplateTests.TestFunctionCallTemplate.approved.txt
Deleted the ApprovalTests/FunctionCallTemplateTests.TestFunctionCallTemplate.approved.txt successfully!
* Revert "Delete FunctionCallTemplateTests.TestFunctionCallTemplate.approved.txt"
This reverts commit 7a6ea9cf0d.
---------
Co-authored-by: Xiaoyun Zhang <bigmiao.zhang@gmail.com>
92 lines
3.1 KiB
C#
92 lines
3.1 KiB
C#
// Using directives
|
|
using System.Text.Json; // Needed for JsonSerializer
|
|
using Xunit; // Needed for Fact and Assert
|
|
using AutoGen.SourceGenerator.Template; // Needed for FunctionCallTemplate
|
|
|
|
namespace AutoGen.SourceGenerator.Tests
|
|
{
|
|
public class FunctionCallTemplateEncodingTests
|
|
{
|
|
private readonly JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions
|
|
{
|
|
WriteIndented = true,
|
|
};
|
|
|
|
[Fact]
|
|
public void FunctionDescription_Should_Encode_DoubleQuotes()
|
|
{
|
|
// Arrange
|
|
var functionContracts = new List<SourceGeneratorFunctionContract>
|
|
{
|
|
new SourceGeneratorFunctionContract
|
|
{
|
|
Name = "TestFunction",
|
|
Description = "This is a \"test\" function",
|
|
Parameters = new SourceGeneratorParameterContract[]
|
|
{
|
|
new SourceGeneratorParameterContract
|
|
{
|
|
Name = "param1",
|
|
Description = "This is a \"parameter\" description",
|
|
Type = "string",
|
|
IsOptional = false
|
|
}
|
|
},
|
|
ReturnType = "void"
|
|
}
|
|
};
|
|
|
|
var template = new FunctionCallTemplate
|
|
{
|
|
NameSpace = "TestNamespace",
|
|
ClassName = "TestClass",
|
|
FunctionContracts = functionContracts
|
|
};
|
|
|
|
// Act
|
|
var result = template.TransformText();
|
|
|
|
// Assert
|
|
Assert.Contains("Description = @\"This is a \"\"test\"\" function\"", result);
|
|
Assert.Contains("Description = @\"This is a \"\"parameter\"\" description\"", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParameterDescription_Should_Encode_DoubleQuotes()
|
|
{
|
|
// Arrange
|
|
var functionContracts = new List<SourceGeneratorFunctionContract>
|
|
{
|
|
new SourceGeneratorFunctionContract
|
|
{
|
|
Name = "TestFunction",
|
|
Description = "This is a test function",
|
|
Parameters = new SourceGeneratorParameterContract[]
|
|
{
|
|
new SourceGeneratorParameterContract
|
|
{
|
|
Name = "param1",
|
|
Description = "This is a \"parameter\" description",
|
|
Type = "string",
|
|
IsOptional = false
|
|
}
|
|
},
|
|
ReturnType = "void"
|
|
}
|
|
};
|
|
|
|
var template = new FunctionCallTemplate
|
|
{
|
|
NameSpace = "TestNamespace",
|
|
ClassName = "TestClass",
|
|
FunctionContracts = functionContracts
|
|
};
|
|
|
|
// Act
|
|
var result = template.TransformText();
|
|
|
|
// Assert
|
|
Assert.Contains("Description = @\"This is a \"\"parameter\"\" description\"", result);
|
|
}
|
|
}
|
|
} |