diff --git a/src/NHibernate.Test/Hql/Ast/ParsingFixture.cs b/src/NHibernate.Test/Hql/Ast/ParsingFixture.cs index 45be4789f1c..3af770191d5 100644 --- a/src/NHibernate.Test/Hql/Ast/ParsingFixture.cs +++ b/src/NHibernate.Test/Hql/Ast/ParsingFixture.cs @@ -1,176 +1,137 @@ using System; using System.Collections.Generic; -using log4net.Config; -using NHibernate.Cfg; -using NHibernate.Engine; +using System.IO; +using System.Xml.Linq; using NHibernate.Hql.Ast.ANTLR; -using NHibernate.Tool.hbm2ddl; using NUnit.Framework; namespace NHibernate.Test.Hql.Ast { - // This test need the new NUnit - //[TestFixture] - //public class ParsingFixture - //{ - // /// - // /// Key test for HQL strings -> HQL AST's - takes the query and returns a string - // /// representation of the resultant tree - // /// - // /// - // /// - // [Test] - // [TestCaseSource(typeof(QueryFactoryClass), "TestCases")] - // public string HqlParse(string query) - // { - // // This test need the new NUnit - // var p = new HqlParseEngine(query, false, null); - // p.Parse(); - - // return " " + p.Ast.ToStringTree(); - // } - - // /// - // /// Used to test individual queries "by hand", since td.net doesn't let me run a - // /// single test out of a data set - // /// - // [Test] - // public void ManualTest() - // { - // var p = new HqlParseEngine(@"select all s, s.Other from s in class Simple where s = :s", false, null); - - // p.Parse(); - - // Console.WriteLine(p.Ast.ToStringTree()); - // } - - // /// - // /// Helper "test" to display queries that are ignored - // /// - // [Test] - // public void ShowIgnoredQueries() - // { - // foreach (string query in QueryFactoryClass.GetIgnores) - // { - // Console.WriteLine(query); - // } - // } - - // /// - // /// Helper "test" to display queries that don't parse in H3 - // /// - // [Test] - // public void ShowExceptionQueries() - // { - // foreach (string query in QueryFactoryClass.GetExceptions) - // { - // Console.WriteLine(query); - // } - // } - - // /// - // /// Goes all the way to the DB and back. Just here until there's a better place to put it... - // /// - // [Test] - // public void BasicQuery() - // { - // string input = "select o.id, li.id from NHibernate.Test.CompositeId.Order o join o.LineItems li";// join o.LineItems li"; - - // ISessionFactoryImplementor sfi = SetupSFI(); - - // ISession session = sfi.OpenSession(); - // session.CreateQuery(input).List(); - // /* - // foreach (Animal o in session.CreateQuery(input).Enumerable()) - // { - // Console.WriteLine(o.Description); - // }*/ - // } - - // ISessionFactoryImplementor SetupSFI() - // { - // Configuration cfg = new Configuration(); - // cfg.AddAssembly(this.GetType().Assembly); - // new SchemaExport(cfg).Create(false, true); - // return (ISessionFactoryImplementor)cfg.BuildSessionFactory(); - // } - - // /// - // /// Class used by Nunit 2.5 to drive the data into the HqlParse test - // /// - // public class QueryFactoryClass - // { - // public static IEnumerable TestCases - // { - // get - // { - // // TODO - need to handle Ignore better (it won't show in results...) - // return EnumerateTests(td => !td.Ignore && !td.Result.StartsWith("Exception"), - // td => new TestCaseData(td.Query) - // .Returns(td.Result) - // .SetCategory(td.Category) - // .SetName(td.Name) - // .SetDescription(td.Description)); - // } - // } - - // public static IEnumerable GetIgnores - // { - // get - // { - // return EnumerateTests(td => td.Ignore, - // td => td.Query); - // } - // } - - // public static IEnumerable GetExceptions - // { - // get - // { - // return EnumerateTests(td => td.Result.StartsWith("Exception"), - // td => td.Query); - // } - // } - - // static IEnumerable EnumerateTests(Func predicate, Func projection) - // { - // XDocument doc = XDocument.Load(@"HQL Parsing\TestQueriesWithResults.xml"); - - // foreach (XElement testGroup in doc.Element("Tests").Elements("TestGroup")) - // { - // string category = testGroup.Attribute("Name").Value; - - // foreach (XElement test in testGroup.Elements("Test")) - // { - // QueryTestData testData = new QueryTestData(category, test); - - // if (predicate(testData)) - // { - // yield return projection(testData); - // } - // } - // } - // } - - // class QueryTestData - // { - // internal QueryTestData(string category, XElement xml) - // { - // Category = category; - // Query = xml.Element("Query").Value; - // Result = xml.Element("Result") != null ? xml.Element("Result").Value : "barf"; - // Name = xml.Element("Name") != null ? xml.Element("Name").Value : null; - // Description = xml.Element("Description") != null ? xml.Element("Description").Value : null; - // Ignore = xml.Attribute("Ignore") != null ? bool.Parse(xml.Attribute("Ignore").Value) : false; - // } - - // internal string Category; - // internal string Query; - // internal string Result; - // internal string Name; - // internal string Description; - // internal bool Ignore; - // } - // } - //} + [TestFixture] + public class ParsingFixture + { + /// + /// Key test for HQL strings -> HQL AST's - takes the query and returns a string + /// representation of the resultant tree + /// + /// + /// + [Test] + [TestCaseSource(typeof(QueryFactoryClass), nameof(QueryFactoryClass.TestCases))] + public string HqlParse(string query) + { + var p = new HqlParseEngine(query, false, null); + var result = p.Parse().ToStringTree(); + + return " " + result; + } + + /// + /// Used to test individual queries "by hand", since td.net doesn't let me run a + /// single test out of a data set + /// + [Test, Explicit] + public void ManualTest() + { + var p = new HqlParseEngine(@"select all s, s.Other from s in class Simple where s = :s", false, null); + + var result = p.Parse().ToStringTree(); + + Console.WriteLine(result); + } + + /// + /// Helper "test" to display queries that are ignored + /// + [Test, Explicit] + public void ShowIgnoredQueries() + { + foreach (string query in QueryFactoryClass.GetIgnores) + { + Console.WriteLine(query); + } + } + + /// + /// Helper "test" to display queries that don't parse in H3 + /// + [Test, Explicit] + public void ShowExceptionQueries() + { + foreach (string query in QueryFactoryClass.GetExceptions) + { + Console.WriteLine(query); + } + } + + /// + /// Class used by NUnit to drive the data into the HqlParse test. + /// + public class QueryFactoryClass + { + public static IEnumerable TestCases => + // TODO - need to handle Ignore better (it won't show in results...) + EnumerateTests( + td => !td.Ignore && !td.Result.StartsWith("Exception"), + td => new TestCaseData(td.Query) + .Returns(td.Result) + .SetCategory(td.Category) + .SetName(td.Name) + .SetDescription(td.Description)); + + public static IEnumerable GetIgnores => + EnumerateTests( + td => td.Ignore, + td => td.Query); + + public static IEnumerable GetExceptions => + EnumerateTests( + td => td.Result.StartsWith("Exception"), + td => td.Query); + + static IEnumerable EnumerateTests( + Func predicate, + Func projection) + { + + XDocument doc = XDocument.Load( + Path.Combine(Path.GetDirectoryName(typeof(ParsingFixture).Assembly.Location), @"Hql/Ast/TestQueriesWithResults.xml")); + + foreach (XElement testGroup in doc.Element("Tests").Elements("TestGroup")) + { + string category = testGroup.Attribute("Name").Value; + + foreach (XElement test in testGroup.Elements("Test")) + { + QueryTestData testData = new QueryTestData(category, test); + + if (predicate(testData)) + { + yield return projection(testData); + } + } + } + } + + class QueryTestData + { + internal QueryTestData(string category, XElement xml) + { + Category = category; + Query = xml.Element("Query").Value.Trim(); + Result = xml.Element("Result")?.Value; + Name = xml.Element("Name")?.Value; + Description = xml.Element("Description")?.Value.Trim() ?? string.Empty; + Ignore = bool.Parse(xml.Attribute("Ignore")?.Value ?? "false"); + } + + internal string Category; + internal string Query; + internal string Result; + internal string Name; + internal string Description; + internal bool Ignore; + } + } + } } diff --git a/src/NHibernate.Test/Hql/Ast/TestQueries.xml b/src/NHibernate.Test/Hql/Ast/TestQueries.xml deleted file mode 100644 index 5b0488ae037..00000000000 --- a/src/NHibernate.Test/Hql/Ast/TestQueries.xml +++ /dev/null @@ -1,3006 +0,0 @@ - - - - - all baz.IntArray.indices]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0]]> - - - 0]]> - - - current_date]]> - - - 100]]> - - - 10000]]> - - - - 100]]> - - - 10000]]> - - - - - - - - - - - - - all elements(p.scores)]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 100 - order by count(kitten) asc, sum(kitten.weight) desc - ]]> - - - - - - - = all ( - select cat.effectiveDate from Catalog as cat where cat.effectiveDate < sysdate) group by ord - having sum(price.amount) > :minAmount order by sum(price.amount) desc - ]]> - - - - :minAmount order by sum(price.amount) desc - ]]> - - - - PaymentStatus.AWAITING_APPROVAL or ( - statusChange.timeStamp = ( select max(change.timeStamp) - from PaymentStatusChange change where change.payment = payment - ) and statusChange.user <> :currentUser ) - group by status.name, status.sortOrder order by status.sortOrder - ]]> - - - PaymentStatus.AWAITING_APPROVAL - or payment.statusChanges[ maxIndex(payment.statusChanges) ].user <> :currentUser - group by status.name, status.sortOrder order by status.sortOrder - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ( select avg(cat.weight) from eg.DomesticCat cat)]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 3.1415e3]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - parse( - "SELECT DISTINCT bar FROM eg.mypackage.Cat qat left join com.multijoin.JoinORama as bar, com.toadstool.Foo f join net.sf.blurb.Blurb"); - - - - - - - - - - - - - 5]]> - - - 5]]> - - - - - - - - - - - - 10]]> - - - 10 and an.bodyWeight < 100) or an.bodyWeight is null - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Added quote quote is an escape - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0]]> - - - 'a' or foo2.id <'a' - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ? or bar.short = 1 or bar.string = 'ff ? bb']]> - - - - - - - - - - - - - - - - - - '0' order by s.foo]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 'a']]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TODO: "count" is reserved - - - - TODO: "count" is reserved - - - - TODO: "count" is reserved - - - - - - - - - - 0]]> - - - 0]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 10]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - :count]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0]]> - - - - - - 'a']]> - - - - - - - - - - - - - - - - - - - - - 'a']]> - - - 'a']]> - - - - - - - - - - - - - - - -1 and s.name is null]]> - - - - - - -1 and s.name is null]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - ]]> - - - 0 and m.extraProp is not null]]> - - - 0 and m.name is not null]]> - - - - - - - - - 0.0]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Added '?' as a valid expression. - - - - - - - - - Added collectionExpr as a valid 'in' clause. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cover NOT optimization in HqlParser - - - - - 1 )]]> - - - = 1 )]]> - - - - - - - - - - - - - - - double "NOT" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - from h3.2.6 I'm not sure about these... [jsd] - - - - from h3.2.6 I'm not sure about these... [jsd] - - - - from h3.2.6 I'm not sure about these... [jsd] - -1 and this.name is null]]> - - - from h3.2.6 I'm not sure about these... [jsd] - - - - from h3.2.6 I'm not sure about these... [jsd] - - - - - - - - - - - - - - - no member of - - - - - - - - - - - - - - - - The keyword 'order' used as a property name. - - - - The keyword 'order' and 'count' used as a property name. - 3]]> - - - - The keywords 'where', 'order' and 'count' used as a property name. - 3]]> - - - - - - - - - - - - - Super evil badness... a legitimate keyword! - - - - - - - - - - - - - - - - - - - - - - - - - - Okay, now this is getting silly. - - - - - - - - - - - - - - - 'where' as a package name - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TODO support .NET identifier NH-685; won't fix ? - - - - - - - TODO Some SQLs have function names with package qualifiers. - - - - - - - - - - - - - - - - - won't fix - - :dateenow ]]> - - - - - - - - - - - - - - 1]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [Test, Ignore("Not supported")] - - - TODO InnerClass but for NET - the problem with inner class is that in .NET the "separator" is '+' and - Path+Identifier is a valid MathAddExpression - because this is a special case and the use of entity-name is a valid workaroud we can wait - to support it or we can choose another character to query inner-classes (the same of JAVA '$' is a valid choice) - - - - - - - - - - - TODO Support Unicode in StringLiteral - - - - - - - - from NHibernate tests - - - - - - - - 1]]> - - - - - - 0]]> - - - - - - 0]]> - - - - - - 0]]> - - - - - - 0]]> - - - - from NHibernate tests - - - - - - - - - - - - - - - - - - - - - - - - from NHibernate tests - - - - - - - - - - from NHibernate tests - - - - - - - - - - - - - - - - - - - - - - - - - - - from NHibernate tests - - - - - - - - - from NHibernate tests - - - - - - - - - from NHibernate tests - - - - - - - - - - from NHibernate tests - - - - - - - - - from NHibernate tests - - - - - 0]]> - - - 0]]> - - - - from NHibernate tests - - - - - - - - - - - - - - from NHibernate tests - - - - - 10]]> - - - - - from NHibernate tests - - - - - - - - - - - - from NHibernate tests - - - - - - - - - - - - - - from NHibernate tests - - - - - - - - - - - - - - 0]]> - - - 0]]> - - - - - - - - - - - - - - - 0]]> - - - 0]]> - - - 0]]> - - - - - - - - - - - from NHibernate tests - - - - - - - from NHibernate tests - - - - - 0]]> - - - - - from NHibernate tests - - - - - - - - - - from NHibernate tests - - - - - - - - from NHibernate tests - - - - - - - from NHibernate tests - - - - - - - - - - from NHibernate tests - - - - - - - - - - from NHibernate tests - - 0]]> - - - 3]]> - - - 0]]> - - - - \ No newline at end of file diff --git a/src/NHibernate.Test/Hql/Ast/TestQueriesWithResults.xml b/src/NHibernate.Test/Hql/Ast/TestQueriesWithResults.xml index c7d8efb5a52..03fa3aa7a5e 100644 --- a/src/NHibernate.Test/Hql/Ast/TestQueriesWithResults.xml +++ b/src/NHibernate.Test/Hql/Ast/TestQueriesWithResults.xml @@ -269,14 +269,14 @@ select cat.color, sum(cat.weight), count(cat) from eg.Cat cat group by cat.color having cat.color in (eg.Color.TABBY, eg.Color.BLACK) ]]> - + 100 order by count(kitten) asc, sum(kitten.weight) desc ]]> - ( avg ( . kitten weight ) ) 100 ) ) ) ( order ( count kitten ) asc ( sum ( . kitten weight ) ) desc ) )]]> + ( avg ( . kitten weight ) ) 100 ) ) ( order ( count kitten ) asc ( sum ( . kitten weight ) ) desc ) )]]> @@ -290,7 +290,7 @@ select cat.effectiveDate from Catalog as cat where cat.effectiveDate < sysdate) group by ord having sum(price.amount) > :minAmount order by sum(price.amount) desc ]]> - = ( . catalog effectiveDate ) ( all ( query ( SELECT_FROM ( from ( RANGE Catalog cat ) ) ( select ( . cat effectiveDate ) ) ) ( where ( < ( . cat effectiveDate ) sysdate ) ) ) ) ) ) ) ( group ord ( having ( > ( sum ( . price amount ) ) ( : minAmount ) ) ) ) ( order ( sum ( . price amount ) ) desc ) )]]> + = ( . catalog effectiveDate ) ( all ( query ( SELECT_FROM ( from ( RANGE Catalog cat ) ) ( select ( . cat effectiveDate ) ) ) ( where ( < ( . cat effectiveDate ) sysdate ) ) ) ) ) ) ) ( group ord ) ( having ( > ( sum ( . price amount ) ) ( : minAmount ) ) ) ( order ( sum ( . price amount ) ) desc ) )]]> :minAmount order by sum(price.amount) desc ]]> - ( sum ( . price amount ) ) ( : minAmount ) ) ) ) ( order ( sum ( . price amount ) ) desc ) )]]> + ( sum ( . price amount ) ) ( : minAmount ) ) ) ( order ( sum ( . price amount ) ) desc ) )]]> 10]]> - ( sum ( . s count ) ) 10 ) ) ) )]]> + ( sum ( . s count ) ) 10 ) ) )]]> - + @@ -3510,7 +3510,7 @@ 0]]> - ( ( abs ( exprList ( * ( . a BodyWeight ) ( - 1 ) ) ) ) 0 ) ) ) )]]> + ( ( abs ( exprList ( * ( . a BodyWeight ) ( - 1 ) ) ) ) 0 ) ) )]]> @@ -3551,7 +3551,7 @@ - + @@ -3568,7 +3568,7 @@ - + @@ -3615,15 +3615,15 @@ 0]]> - ( ( cast ( exprList ( . a BodyWeight ) Double ) ) 0 ) ) ) )]]> + ( ( cast ( exprList ( . a BodyWeight ) Double ) ) 0 ) ) )]]> 0]]> - ( ( cast ( exprList ( - ( + 7 123.3 ) ( * 1 ( . a BodyWeight ) ) ) int ) ) 0 ) ) ) )]]> + ( ( cast ( exprList ( - ( + 7 123.3 ) ( * 1 ( . a BodyWeight ) ) ) int ) ) 0 ) ) )]]> 0]]> - ( ( cast ( exprList ( + ( : aParam ) ( . a BodyWeight ) ) int ) ) 0 ) ) ) )]]> + ( ( cast ( exprList ( + ( : aParam ) ( . a BodyWeight ) ) int ) ) 0 ) ) )]]> @@ -3718,7 +3718,7 @@ 0]]> - ( ( cast ( exprList ( + ( : aParam ) ( . a BodyWeight ) ) Double ) ) 0 ) ) ) )]]> + ( ( cast ( exprList ( + ( : aParam ) ( . a BodyWeight ) ) Double ) ) 0 ) ) )]]> diff --git a/src/NHibernate.Test/NHibernate.Test.csproj b/src/NHibernate.Test/NHibernate.Test.csproj index a3770c40cbf..43e244811b9 100644 --- a/src/NHibernate.Test/NHibernate.Test.csproj +++ b/src/NHibernate.Test/NHibernate.Test.csproj @@ -34,6 +34,9 @@ Always + + PreserveNewest +