This repository has been archived by the owner on Jan 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/deveeldb-nunit/Deveel.Data.Sql.Expressions/SqlConditionalExpressionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Deveel.Data.Sql.Expressions { | ||
[TestFixture] | ||
public static class SqlConditionalExpressionTests { | ||
[Test] | ||
public static void SimpleCase() { | ||
var first = SqlExpression.Constant(34); | ||
var second = SqlExpression.Add(SqlExpression.Constant(10), SqlExpression.Constant(24)); | ||
var condition = SqlExpression.Equal(first, second); | ||
var returnExpression = SqlExpression.Constant("It was equal"); | ||
var conditional = SqlExpression.Conditional(condition, returnExpression); | ||
|
||
var result = conditional.EvaluateToConstant(null, null); | ||
|
||
Assert.IsNotNull(result); | ||
Assert.IsFalse(Field.IsNullField(result)); | ||
Assert.AreEqual("It was equal", result.Value.ToString()); | ||
} | ||
|
||
[Test] | ||
public static void SimpleCaseWithFalse() { | ||
var first = SqlExpression.Constant(34); | ||
var second = SqlExpression.Add(SqlExpression.Constant(10), SqlExpression.Constant(34)); | ||
var condition = SqlExpression.Equal(first, second); | ||
var ifTrue = SqlExpression.Constant("It was equal"); | ||
var ifFalse = SqlExpression.Constant("It was not equal"); | ||
|
||
var conditional = SqlExpression.Conditional(condition, ifTrue, ifFalse); | ||
|
||
var result = conditional.EvaluateToConstant(null, null); | ||
|
||
Assert.IsNotNull(result); | ||
Assert.IsFalse(Field.IsNullField(result)); | ||
Assert.AreEqual("It was not equal", result.Value.ToString()); | ||
} | ||
|
||
[Test] | ||
public static void CaseNestedFalse() { | ||
var first = SqlExpression.Constant(34); | ||
var second = SqlExpression.Add(SqlExpression.Constant(10), SqlExpression.Constant(34)); | ||
var condition = SqlExpression.Equal(first, second); | ||
var ifTrue = SqlExpression.Constant("It was equal"); | ||
var ifFalseReturn = SqlExpression.Constant("It was not equal"); | ||
var ifFalse = SqlExpression.Conditional(SqlExpression.Constant(true), ifFalseReturn); | ||
|
||
var conditional = SqlExpression.Conditional(condition, ifTrue, ifFalse); | ||
|
||
var result = conditional.EvaluateToConstant(null, null); | ||
|
||
Assert.IsNotNull(result); | ||
Assert.IsFalse(Field.IsNullField(result)); | ||
Assert.AreEqual("It was not equal", result.Value.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
|
||
using Deveel.Data.Sql; | ||
using Deveel.Data.Sql.Expressions; | ||
using Deveel.Data.Sql.Statements; | ||
using Deveel.Data.Sql.Types; | ||
using Deveel.Data.Sql.Variables; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Deveel.Data { | ||
[TestFixture] | ||
public sealed class ConditionalTests : ContextBasedTest { | ||
protected override void OnAfterSetup(string testName) { | ||
Query.Access().CreateObject(new VariableInfo("a", PrimitiveTypes.Integer(), false) { | ||
DefaultExpression = SqlExpression.Constant(34) | ||
}); | ||
|
||
base.OnAfterSetup(testName); | ||
} | ||
|
||
protected override void OnBeforeTearDown(string testName) { | ||
Query.Access().DropObject(DbObjectType.Variable, new ObjectName("a")); | ||
base.OnBeforeTearDown(testName); | ||
} | ||
|
||
[Test] | ||
public void SimpleConditional() { | ||
var condition = SqlExpression.Equal(SqlExpression.VariableReference("a"), SqlExpression.Constant(34)); | ||
var ifTrue = new SqlStatement[] { | ||
new DeclareVariableStatement("b", PrimitiveTypes.String()), | ||
new AssignVariableStatement(SqlExpression.VariableReference("b"), SqlExpression.Constant(21)), | ||
}; | ||
|
||
var result = Query.If(condition, ifTrue); | ||
|
||
Assert.IsNotNull(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters