chore: initial git load of code space
This commit is contained in:
@@ -0,0 +1,279 @@
|
||||
using Strata.SqlTools.SqlBreakdown.Expressions;
|
||||
using Strata.SqlTools.SqlBreakdown.Expressions.Conditional.Logical;
|
||||
using Strata.SqlTools.SqlBreakdown.Expressions.Literals;
|
||||
using Strata.SqlTools.Markdown.Expressions;
|
||||
|
||||
namespace Strata.SqlTools.Markdown.Tests.Expressions;
|
||||
|
||||
[TestFixture]
|
||||
public class ExpressionGeneratorTests
|
||||
{
|
||||
private ExpressionGenerator _generator = null!;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_generator = new ExpressionGenerator();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMarkdown_WithSimpleExpression_GeneratesMarkdown()
|
||||
{
|
||||
// Arrange
|
||||
var expression = new NumberLiteralExpression(42);
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateMarkdown(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("## Expression Structure"));
|
||||
Assert.That(result, Does.Contain("## Expression Type"));
|
||||
Assert.That(result, Does.Contain("## Mermaid Diagram"));
|
||||
Assert.That(result, Does.Contain("NumberLiteralExpression"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMarkdown_WithComparisonExpression_IncludesComparison()
|
||||
{
|
||||
// Arrange
|
||||
Expression left = new NumberLiteralExpression(100);
|
||||
Expression right = new NumberLiteralExpression(50);
|
||||
var expression = left > right;
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateMarkdown(expression, "Price Comparison");
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("# Price Comparison"));
|
||||
Assert.That(result, Does.Contain("Comparison"));
|
||||
Assert.That(result, Does.Contain("```"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMarkdown_WithArithmeticExpression_IncludesArithmetic()
|
||||
{
|
||||
// Arrange
|
||||
Expression price = new NumberLiteralExpression(100);
|
||||
Expression discount = new NumberLiteralExpression(0.1m);
|
||||
var expression = price * (1 - discount);
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateMarkdown(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("Arithmetic"));
|
||||
Assert.That(result, Does.Contain("```mermaid"));
|
||||
Assert.That(result, Does.Contain("graph TD"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMarkdown_WithLogicalExpression_IncludesLogic()
|
||||
{
|
||||
// Arrange
|
||||
var expr1 = new NumberLiteralExpression(5) > new NumberLiteralExpression(3);
|
||||
var expr2 = new NumberLiteralExpression(10) < new NumberLiteralExpression(20);
|
||||
var expression = new AndExpression(expr1, expr2);
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateMarkdown(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("AND"));
|
||||
Assert.That(result, Does.Contain("mermaid"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMarkdown_WithTitle_IncludesTitle()
|
||||
{
|
||||
// Arrange
|
||||
var expression = new StringLiteralExpression("test");
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateMarkdown(expression, "Test Expression");
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.StartWith("# Test Expression"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMarkdown_ComplexExpression_GeneratesCompleteDoc()
|
||||
{
|
||||
// Arrange
|
||||
Expression quantity = new NumberLiteralExpression(10);
|
||||
Expression price = new NumberLiteralExpression(25.50m);
|
||||
Expression discount = new NumberLiteralExpression(0.15m);
|
||||
var expression = quantity * price * (1 - discount);
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateMarkdown(expression, "Order Total");
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("# Order Total"));
|
||||
Assert.That(result, Does.Contain("## Expression Structure"));
|
||||
Assert.That(result, Does.Contain("## Expression Type"));
|
||||
Assert.That(result, Does.Contain("## Mermaid Diagram"));
|
||||
Assert.That(result, Does.Contain("## Mathematical Expression"));
|
||||
Assert.That(result, Does.Contain("Arithmetic"));
|
||||
Assert.That(result.Length, Is.GreaterThan(200));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMathematicalExpression_WithArithmetic_GeneratesLatex()
|
||||
{
|
||||
// Arrange
|
||||
Expression a = new NumberLiteralExpression(5);
|
||||
Expression b = new NumberLiteralExpression(3);
|
||||
var expression = a + b;
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("$$"));
|
||||
Assert.That(result, Does.Contain("+"));
|
||||
Assert.That(result, Does.Contain("5"));
|
||||
Assert.That(result, Does.Contain("3"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMathematicalExpression_WithMultiplication_UsesTimesSymbol()
|
||||
{
|
||||
// Arrange
|
||||
Expression x = new NumberLiteralExpression(10);
|
||||
Expression y = new NumberLiteralExpression(20);
|
||||
var expression = x * y;
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("\\times"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMathematicalExpression_WithComparison_UsesCorrectSymbol()
|
||||
{
|
||||
// Arrange
|
||||
Expression a = new NumberLiteralExpression(10);
|
||||
Expression b = new NumberLiteralExpression(20);
|
||||
var expression = a >= b;
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("\\geq"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMathematicalExpression_WithLogicalAnd_UsesLandSymbol()
|
||||
{
|
||||
// Arrange
|
||||
var expr1 = new NumberLiteralExpression(5) > new NumberLiteralExpression(3);
|
||||
var expr2 = new NumberLiteralExpression(10) < new NumberLiteralExpression(20);
|
||||
var expression = new AndExpression(expr1, expr2);
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("\\land"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMathematicalExpression_Inline_UsesSingleDollar()
|
||||
{
|
||||
// Arrange
|
||||
var expression = new NumberLiteralExpression(42);
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateMathematicalExpression(expression, inline: true);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.StartWith("$"));
|
||||
Assert.That(result, Does.EndWith("$"));
|
||||
Assert.That(result, Does.Not.Contain("$$"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMathematicalExpression_Block_UsesDoubleDollar()
|
||||
{
|
||||
// Arrange
|
||||
var expression = new NumberLiteralExpression(42);
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateMathematicalExpression(expression, inline: false);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("$$"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMathematicalExpression_ComplexArithmetic_GeneratesCorrectLatex()
|
||||
{
|
||||
// Arrange
|
||||
Expression quantity = new NumberLiteralExpression(10);
|
||||
Expression price = new NumberLiteralExpression(25);
|
||||
Expression discount = new NumberLiteralExpression(0.1m);
|
||||
var expression = quantity * price * (1 - discount);
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateMathematicalExpression(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("\\times"));
|
||||
Assert.That(result, Does.Contain("10"));
|
||||
Assert.That(result, Does.Contain("25"));
|
||||
Assert.That(result, Does.Contain("0.1"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateRawMathematicalExpression_CauchySchwarzInequality_WithDollarFormat()
|
||||
{
|
||||
// Arrange
|
||||
var latex = @"\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)";
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateRawMathematicalExpression(latex, format: "dollar", inline: false);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.StartWith("$$"));
|
||||
Assert.That(result, Does.EndWith("$$"));
|
||||
Assert.That(result, Does.Contain("\\sum_{k=1}^n"));
|
||||
Assert.That(result, Does.Contain("a_k b_k"));
|
||||
Assert.That(result, Does.Contain("\\leq"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateRawMathematicalExpression_CauchySchwarzInequality_WithMathFormat()
|
||||
{
|
||||
// Arrange
|
||||
var latex = @"\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)";
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateRawMathematicalExpression(latex, format: "math");
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.StartWith("```math"));
|
||||
Assert.That(result, Does.EndWith("```"));
|
||||
Assert.That(result, Does.Contain("\\sum_{k=1}^n"));
|
||||
Assert.That(result, Does.Contain("a_k b_k"));
|
||||
Assert.That(result, Does.Contain("\\leq"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateRawMathematicalExpression_Inline_UsesSingleDollar()
|
||||
{
|
||||
// Arrange
|
||||
var latex = "E = mc^2";
|
||||
|
||||
// Act
|
||||
var result = ExpressionGenerator.GenerateRawMathematicalExpression(latex, inline: true);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.StartWith("$"));
|
||||
Assert.That(result, Does.EndWith("$"));
|
||||
Assert.That(result, Does.Not.Contain("```"));
|
||||
Assert.That(result, Is.EqualTo("$E = mc^2$"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
using Strata.SqlTools.SqlBreakdown.Expressions;
|
||||
using Strata.SqlTools.SqlBreakdown.Expressions.Conditional.Logical;
|
||||
using Strata.SqlTools.SqlBreakdown.Expressions.Literals;
|
||||
using Strata.SqlTools.Markdown.Expressions;
|
||||
|
||||
namespace Strata.SqlTools.Markdown.Tests.Expressions;
|
||||
|
||||
[TestFixture]
|
||||
public class SimpleExpressionGeneratorTests
|
||||
{
|
||||
private SimpleExpressionGenerator _generator = null!;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_generator = new SimpleExpressionGenerator();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMarkdown_WithSimpleExpression_GeneratesSimpleDoc()
|
||||
{
|
||||
// Arrange
|
||||
var expression = new NumberLiteralExpression(42);
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateMarkdown(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("## Expression"));
|
||||
Assert.That(result, Does.Contain("## Type Information"));
|
||||
Assert.That(result, Does.Contain("## Description"));
|
||||
Assert.That(result, Does.Contain("```sql"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMarkdown_WithTitle_IncludesTitle()
|
||||
{
|
||||
// Arrange
|
||||
var expression = new StringLiteralExpression("test");
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateMarkdown(expression, "Simple Expression");
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.StartWith("# Simple Expression"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateMarkdown_IncludesDescription()
|
||||
{
|
||||
// Arrange
|
||||
Expression left = new NumberLiteralExpression(100);
|
||||
Expression right = new NumberLiteralExpression(50);
|
||||
var expression = left == right;
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateMarkdown(expression);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("EqualToExpression"));
|
||||
Assert.That(result, Does.Contain("expression"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateComparisonTable_WithMultipleExpressions_GeneratesTable()
|
||||
{
|
||||
// Arrange
|
||||
var expressions = new Dictionary<string, Expression>
|
||||
{
|
||||
["Price Filter"] = new NumberLiteralExpression(100) > new NumberLiteralExpression(50),
|
||||
["Status Filter"] = new StringLiteralExpression("Active") == new StringLiteralExpression("Active"),
|
||||
["Quantity Check"] = new NumberLiteralExpression(10) <= new NumberLiteralExpression(100)
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateComparisonTable(expressions);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("| Name | Expression | Type |"));
|
||||
Assert.That(result, Does.Contain("|------|------------|------|"));
|
||||
Assert.That(result, Does.Contain("Price Filter"));
|
||||
Assert.That(result, Does.Contain("Status Filter"));
|
||||
Assert.That(result, Does.Contain("Quantity Check"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateComparisonTable_WithTitle_IncludesTitle()
|
||||
{
|
||||
// Arrange
|
||||
var expressions = new Dictionary<string, Expression>
|
||||
{
|
||||
["Test"] = new NumberLiteralExpression(1)
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateComparisonTable(expressions, "Comparison Table");
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.StartWith("# Comparison Table"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateBulletList_WithExpressions_GeneratesList()
|
||||
{
|
||||
// Arrange
|
||||
var expressions = new List<Expression>
|
||||
{
|
||||
new NumberLiteralExpression(100),
|
||||
new StringLiteralExpression("Active"),
|
||||
new NumberLiteralExpression(5) + new NumberLiteralExpression(10)
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateBulletList(expressions);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("- `100`"));
|
||||
Assert.That(result, Does.Contain("- `'Active'`"));
|
||||
Assert.That(result, Does.Contain("- `"));
|
||||
Assert.That(result, Does.Contain("*NumberLiteralExpression*"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateBulletList_WithTitle_IncludesTitle()
|
||||
{
|
||||
// Arrange
|
||||
var expressions = new List<Expression>
|
||||
{
|
||||
new NumberLiteralExpression(1)
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateBulletList(expressions, "Expression List");
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.StartWith("## Expression List"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateComparisonTable_WithOrExpression_GeneratesTable()
|
||||
{
|
||||
// Arrange
|
||||
var expr1 = new NumberLiteralExpression(1) > new NumberLiteralExpression(0);
|
||||
var expr2 = new NumberLiteralExpression(2) > new NumberLiteralExpression(0);
|
||||
var expressions = new Dictionary<string, Expression>
|
||||
{
|
||||
["Test"] = new OrExpression(expr1, expr2)
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = _generator.GenerateComparisonTable(expressions);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Does.Contain("Test"));
|
||||
Assert.That(result, Does.Contain("OrExpression"));
|
||||
Assert.That(result, Does.Contain("OR"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user