DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
DeclareVariableTests.cs
Go to the documentation of this file.
1 using System;
2 using System.Linq;
3 
5 using Deveel.Data.Types;
6 
7 using NUnit.Framework;
8 
9 namespace Deveel.Data.Sql.Compile {
10  [TestFixture]
12  [Test]
13  public void DeclareSimpleVariable() {
14  const string sql = "DECLARE a NUMERIC(2, 3)";
15 
16  var result = Compile(sql);
17  Assert.IsNotNull(result);
18  Assert.IsFalse(result.HasErrors);
19 
20  Assert.AreEqual(1, result.Statements.Count);
21  Assert.IsInstanceOf<DeclareVariableStatement>(result.Statements.First());
22 
23  var statement = (DeclareVariableStatement) result.Statements.First();
24  Assert.AreEqual("a", statement.VariableName);
25  Assert.AreEqual(false, statement.IsNotNull);
26  Assert.AreEqual(false, statement.IsConstant);
27  Assert.IsInstanceOf<NumericType>(statement.VariableType);
28  }
29 
30  [Test]
31  public void DeclareConstantVariable() {
32  const string sql = "DECLARE a CONSTANT NUMERIC(2, 3)";
33 
34  var result = Compile(sql);
35  Assert.IsNotNull(result);
36  Assert.IsFalse(result.HasErrors);
37 
38  Assert.AreEqual(1, result.Statements.Count);
39  Assert.IsInstanceOf<DeclareVariableStatement>(result.Statements.First());
40 
41  var statement = (DeclareVariableStatement)result.Statements.First();
42  Assert.AreEqual("a", statement.VariableName);
43  Assert.AreEqual(true, statement.IsNotNull);
44  Assert.AreEqual(true, statement.IsConstant);
45  Assert.IsInstanceOf<NumericType>(statement.VariableType);
46  }
47 
48  [Test]
49  public void ImplicitDeclaration() {
50  const string sql = "a NUMERIC(2, 3)";
51 
52  var result = Compile(sql);
53  Assert.IsNotNull(result);
54  Assert.IsFalse(result.HasErrors);
55 
56  Assert.AreEqual(1, result.Statements.Count);
57  Assert.IsInstanceOf<DeclareVariableStatement>(result.Statements.First());
58 
59  var statement = (DeclareVariableStatement)result.Statements.First();
60  Assert.AreEqual("a", statement.VariableName);
61  Assert.IsInstanceOf<NumericType>(statement.VariableType);
62  }
63  }
64 }