Skip to content
Open
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
32 changes: 32 additions & 0 deletions prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@ public void RqToSql_ThrowsArgumentNullException_WhenOptionsNull()
Assert.Throws<ArgumentNullException>(() => PrqlCompiler.RqToSql("{}", null!));
}

[Fact]
public void Compile_ThrowsArgumentException_WhenQueryIsEmpty()
{
// Regression: previously `new ArgumentException(nameof(prqlQuery))`
// passed the parameter name into the message slot, leaving ParamName
// unset and the exception message as just "prqlQuery".
var ex = Assert.Throws<ArgumentException>(() => PrqlCompiler.Compile(""));
Assert.Equal("prqlQuery", ex.ParamName);
}

[Fact]
public void PrqlToPl_ThrowsArgumentException_WhenQueryIsEmpty()
{
var ex = Assert.Throws<ArgumentException>(() => PrqlCompiler.PrqlToPl(""));
Assert.Equal("prqlQuery", ex.ParamName);
}

[Fact]
public void PlToRq_ThrowsArgumentException_WhenJsonIsEmpty()
{
var ex = Assert.Throws<ArgumentException>(() => PrqlCompiler.PlToRq(""));
Assert.Equal("plJson", ex.ParamName);
}

[Fact]
public void RqToSql_ThrowsArgumentException_WhenJsonIsEmpty()
{
var ex = Assert.Throws<ArgumentException>(
() => PrqlCompiler.RqToSql("", new PrqlCompilerOptions()));
Assert.Equal("rqJson", ex.ParamName);
}

[Fact]
public void Compile_HandlesNonAsciiInput()
{
Expand Down
27 changes: 5 additions & 22 deletions prqlc/bindings/dotnet/PrqlCompiler/PrqlCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public static partial class PrqlCompiler
/// <exception cref="FormatException"><paramref name="prqlQuery"/> cannot be compiled.</exception>
public static Result Compile(string prqlQuery)
{
if (string.IsNullOrEmpty(prqlQuery))
{
throw new ArgumentException(nameof(prqlQuery));
}
ArgumentException.ThrowIfNullOrEmpty(prqlQuery);

return Compile(prqlQuery, new PrqlCompilerOptions());
}
Expand All @@ -37,11 +34,7 @@ public static Result Compile(string prqlQuery)
/// <exception cref="FormatException"><paramref name="prqlQuery"/> cannot be compiled.</exception>
public static Result Compile(string prqlQuery, PrqlCompilerOptions options)
{
if (string.IsNullOrEmpty(prqlQuery))
{
throw new ArgumentException(nameof(prqlQuery));
}

ArgumentException.ThrowIfNullOrEmpty(prqlQuery);
ArgumentNullException.ThrowIfNull(options);

var targetPtr = options.Target is null
Expand Down Expand Up @@ -72,10 +65,7 @@ public static Result Compile(string prqlQuery, PrqlCompilerOptions options)
/// <remarks>https://docs.rs/prqlc/latest/</remarks>
public static Result PrqlToPl(string prqlQuery)
{
if (string.IsNullOrEmpty(prqlQuery))
{
throw new ArgumentException(nameof(prqlQuery));
}
ArgumentException.ThrowIfNullOrEmpty(prqlQuery);

var nativeResult = PrqlToPlExtern(prqlQuery);
return new Result(nativeResult);
Expand All @@ -91,10 +81,7 @@ public static Result PrqlToPl(string prqlQuery)
/// <remarks>https://docs.rs/prqlc/latest/</remarks>
public static Result PlToRq(string plJson)
{
if (string.IsNullOrEmpty(plJson))
{
throw new ArgumentException(nameof(plJson));
}
ArgumentException.ThrowIfNullOrEmpty(plJson);

var nativeResult = PlToRqExtern(plJson);
return new Result(nativeResult);
Expand All @@ -112,11 +99,7 @@ public static Result PlToRq(string plJson)
/// <remarks>https://docs.rs/prqlc/latest/</remarks>
public static Result RqToSql(string rqJson, PrqlCompilerOptions options)
{
if (string.IsNullOrEmpty(rqJson))
{
throw new ArgumentException(nameof(rqJson));
}

ArgumentException.ThrowIfNullOrEmpty(rqJson);
ArgumentNullException.ThrowIfNull(options);

var targetPtr = options.Target is null
Expand Down
Loading