Skip to content

Commit

Permalink
Merge branch '6.2' of https://github.com/lucee/Lucee into 6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Dec 4, 2024
2 parents bc91cd7 + b61478e commit e41ff0b
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 36 deletions.
48 changes: 37 additions & 11 deletions test/datasource/MySQL.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="mysql" {

processingdirective pageEncoding="UTF-8";

function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

public function beforeTests(){
// stash system timezone
variables.timezone = getApplicationSettings().timezone;
Expand Down Expand Up @@ -184,31 +188,53 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="mysql" {
assertEquals(UnsignedMaxBigInt,qry.UnsignedMaxBigInt);
assertEquals(UnsignedMaxBigInt,""&qry.UnsignedMaxBigInt);

// ATM we only test the types, because there is an issue with float that need fixing first
// TODO we only test the types, because there is an issue with float that need fixing first
assertEquals("java.lang.Float",qry.MinFloat[1].getClass().getName());
//assertEquals(MinFloat,qry.MinFloat);
//assertEquals(MinFloat,""&qry.MinFloat);
/*
assertEquals(MinFloat,qry.MinFloat);
if ( variables.preciseMath )
assertEquals(MinFloat,""&qry.MinFloat);
else
assertEquals(toNumeric(MinFloat),""&qry.MinFloat);
*/

// ATM we only test the types, because there is an issue with float that need fixing first
// TODO we only test the types, because there is an issue with float that need fixing first
assertEquals("java.lang.Float",qry.MaxFloat[1].getClass().getName());
//assertEquals(MaxFloat,qry.MaxFloat);
//assertEquals(MaxFloat,""&qry.MaxFloat);
/*
assertEquals(MaxFloat,qry.MaxFloat);
if ( variables.preciseMath )
assertEquals(MaxFloat,""&qry.MaxFloat);
else
assertEquals(toNumeric(MaxFloat),""&qry.MaxFloat);
*/

assertEquals("java.lang.Double",qry.MinDouble[1].getClass().getName());
assertEquals(MinDouble,qry.MinDouble);
assertEquals(MinDouble,""&qry.MinDouble);

if ( variables.preciseMath )
assertEquals(MinDouble,""&qry.MinDouble);
else
assertEquals(toNumeric(MinDouble),""&qry.MinDouble);

assertEquals("java.lang.Double",qry.MaxDouble[1].getClass().getName());
assertEquals(MaxDouble,qry.MaxDouble);
assertEquals(MaxDouble,""&qry.MaxDouble);
if ( variables.preciseMath )
assertEquals(MaxDouble,""&qry.MaxDouble);
else
assertEquals(toNumeric(MaxDouble),""&qry.MaxDouble);

assertEquals("java.math.BigDecimal",qry.MinDecimal[1].getClass().getName());
assertEquals(MinDecimal,qry.MinDecimal);
assertEquals(MinDecimal,""&qry.MinDecimal);
if ( variables.preciseMath )
assertEquals(MinDecimal,""&qry.MinDecimal);
else
assertEquals(toNumeric(MinDecimal),""&qry.MinDecimal);

assertEquals("java.math.BigDecimal",qry.MaxDecimal[1].getClass().getName());
assertEquals(MaxDecimal,qry.MaxDecimal);
assertEquals(MaxDecimal,""&qry.MaxDecimal);
if ( variables.preciseMath )
assertEquals(MaxDecimal,""&qry.MaxDecimal);
else
assertEquals(toNumeric(MaxDecimal),""&qry.MaxDecimal);
}
finally {

Expand Down
7 changes: 5 additions & 2 deletions test/functions/ACos.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it(title="checking acos(0.7) function", body = function( currentSpec ) {
var res="0.7953988301841436";
assertEquals(res,tostring(acos(0.7)));
if ( getApplicationSettings().preciseMath )
assertEquals("0.7953988301841436", toString(acos(0.7)));
else
assertEquals("0.795398830184", toString(acos(0.7)));

});

it(title="checking acos() function invalid range", body = function( currentSpec ) {
Expand Down
6 changes: 4 additions & 2 deletions test/functions/ASin.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
function run( testResults , testBox ) {
describe( title="Test suite for ASin()", body=function() {
it(title="Checking ASin() function", body = function( currentSpec ) {
var res="0.3046926540153975";
assertEquals(res,tostring( asin(0.3) ));
if ( getApplicationSettings().preciseMath )
assertEquals("0.3046926540153975",tostring( asin(0.3) ));
else
assertEquals("0.304692654015",tostring( asin(0.3) ));
});
it(title="Checking ASin() function invaid input", body = function( currentSpec ) {
try{
Expand Down
13 changes: 10 additions & 3 deletions test/functions/Atn.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
function run( testResults , testBox ) {
describe( title="Test suite for Atn()", body=function() {
it(title="Checking Atn() function", body = function( currentSpec ) {
assertEquals("0.2914567944778671",tostring(atn(0.3)));
assertEquals("0.9151007005533605",tostring(atn(1.3)));
assertEquals("-1.5607966601082315",tostring(atn(-100)));
if ( getApplicationSettings().preciseMath ){
assertEquals( "0.2914567944778671",tostring(atn(0.3)));
assertEquals( "0.9151007005533605",tostring(atn(1.3)));
assertEquals("-1.5607966601082315",tostring(atn(-100)));
} else {
assertEquals( "0.291456794478",tostring(atn(0.3)));
assertEquals( "0.915100700553",tostring(atn(1.3)));
assertEquals("-1.560796660108",tostring(atn(-100)));
}

});
});
}
Expand Down
12 changes: 11 additions & 1 deletion test/functions/BitAnd.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
component extends="org.lucee.cfml.test.LuceeTestCase"{

function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function run( testResults , testBox ) {
describe( title="Test suite for BitAnd()", body=function() {
it(title="Checking BitAnd() function integers", body = function( currentSpec ) {
Expand All @@ -17,7 +22,12 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
it(title="Checking BitAnd() function float edge case ", body = function( currentSpec ) {
// they can be converted because they are below the threshold
assertEquals("0",BitAnd(1, 0.00000000000001));
assertEquals("1",BitAnd(1, 0.999999999999999));
if ( variables.preciseMath ) {
assertEquals("1",BitAnd(1, 0.999999999999999));
} else {
var Integer=createObject("java","java.lang.Integer");
assertEquals("1",BitAnd(1, Integer.MAX_VALUE));
}
});

it("should correctly perform bitwise AND between two positive numbers", function() {
Expand Down
20 changes: 17 additions & 3 deletions test/functions/BitOr.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
component extends="org.lucee.cfml.test.LuceeTestCase"{

function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function run( testResults , testBox ) {
describe( title="Test suite for BitOr()", body=function() {
it(title="Checking BitOr() function", body = function( currentSpec ) {
Expand All @@ -22,18 +27,27 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it("should handle bitwise OR where one number is the maximum integer value", function() {
expect( BitOr(2147483647, 1) ).toBe(2147483647);
if ( variables.preciseMath )
expect( BitOr(2147483647, 1) ).toBe(2147483647);
else
expect( BitOr(2147483647, 1) ).toBe(2147483648);
});

it("should return the non-zero value when one number is zero", function() {
expect( BitOr(0, 0) ).toBe(0);
});

it("should correctly perform bitwise OR between two large String values", function() {
expect( BitOr("9223372036854775808", "9223372036854775807") ).toBe("18446744073709551615");
if ( variables.preciseMath )
expect( BitOr("9223372036854775808", "9223372036854775807") ).toBe("18446744073709551615");
else
expect( BitOr("9223372036854775808", "9223372036854775807") ).toBe("9223372036854775807");
});
it("should correctly perform bitwise OR between two large Number values", function() {
expect( BitOr(9223372036854775808, 9223372036854775807) ).toBe(18446744073709551615);
if ( variables.preciseMath )
expect( BitOr(9223372036854775808, 9223372036854775807) ).toBe(18446744073709551615);
else
expect( BitOr(9223372036854775808, 9223372036854775807) ).toBe(9223372036854775807);
});

it("should correctly perform bitwise OR between a BigInteger and a smaller integer", function() {
Expand Down
14 changes: 12 additions & 2 deletions test/functions/BitSHLN.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
component extends="org.lucee.cfml.test.LuceeTestCase"{
function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function run( testResults , testBox ) {
describe( title="Test suite for BitSHLN()", body=function() {
it(title="Checking BitSHLN() function with small shifts", body = function(currentSpec) {
Expand All @@ -14,7 +18,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{

it(title="Checking BitSHLN() function with large number shift", body = function(currentSpec) {
// Shift a large number that's already near the boundary of 32-bit integer range
assertEquals("4294967294", toString(BitSHLN(2147483647, 1))); // 2147483647 << 1 = 0 (overflow)
if ( variables.preciseMath )
assertEquals("4294967294", toString(BitSHLN(2147483647, 1))); // 2147483647 << 1 = 0 (overflow)
else
assertEquals("4294967296", toString(BitSHLN(2147483647, 1))); // 2147483647 << 1 = 0 (overflow)
});

it(title="Checking BitSHLN() function with negative shift", body = function(currentSpec) {
Expand All @@ -39,7 +46,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});
it(title="Checking BitSHLN() function with extreme shifts 128", body = function(currentSpec) {
// Extreme shift cases where the shift count is very large
assertEquals("340282366920938463463374607431768211456",toString(BitSHLN(1, 128))); // 1 << 64 = 0 (all bits shifted out in a 64-bit context)
if ( variables.preciseMath )
assertEquals("340282366920938463463374607431768211456",toString(BitSHLN(1, 128))); // 1 << 64 = 0 (all bits shifted out in a 64-bit context)
else
assertEquals("0", BitSHLN(1, 64)); // 1 << 64 = 0 (all bits shifted out in a 64-bit context)
});
});
}
Expand Down
14 changes: 12 additions & 2 deletions test/functions/BitSHRN.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
component extends="org.lucee.cfml.test.LuceeTestCase"{
function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function run( testResults , testBox ) {
describe( title="Test suite for BitSHRN()", body=function() {
it(title="Checking BitSHRN() function", body = function( currentSpec ) {
Expand All @@ -14,7 +18,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it(title="Checking BitSHRN() function with large numbers", body = function(currentSpec) {
assertEquals("2147483647", BitSHRN(4294967295, 1)); // Large number shifted right
if ( variables.preciseMath )
assertEquals("2147483647", BitSHRN(4294967295, 1)); // Large number shifted right
else
assertEquals("2147483648", BitSHRN(4294967295, 1)); // Large number shifted right
});

it(title="Checking BitSHRN() function with negative numbers", body = function(currentSpec) {
Expand All @@ -23,7 +30,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it(title="Checking BitSHRN() function with extreme shift values", body = function(currentSpec) {
assertEquals("8", BitSHRN(147573952589676412928, 64)); // 128 >> 64 = 0 (all bits shifted out)
if ( variables.preciseMath )
assertEquals("8", BitSHRN(147573952589676412928, 64)); // 128 >> 64 = 0 (all bits shifted out)
else
assertEquals("0", BitSHRN(128, 64)); // 128 >> 64 = 0 (all bits shifted out)
});
});
}
Expand Down
10 changes: 9 additions & 1 deletion test/functions/BitXor.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
component extends="org.lucee.cfml.test.LuceeTestCase"{

function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function run( testResults , testBox ) {
describe( title="Test suite for BitXOr()", body=function() {
it(title="Checking BitXOr() function", body = function( currentSpec ) {
Expand Down Expand Up @@ -29,7 +34,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it(title="Checking BitXOr() function with different large numbers", body = function(currentSpec) {
assertEquals("18446744073709551614", BitXOr("18446744073709551615", "1")); // 111...11111111 XOR 000...00000001 = 111...11111110
if ( variables.preciseMath )
assertEquals("18446744073709551614", BitXOr("18446744073709551615", "1")); // 111...11111111 XOR 000...00000001 = 111...11111110
else
assertEquals("9223372036854775807", BitXOr("18446744073709551615", "1")); // 111...11111111 XOR 000...00000001 = 111...11111110
});

});
Expand Down
8 changes: 6 additions & 2 deletions test/functions/sin.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
it(title="Checking the sin() function", body=function( currentSpec ) {
var a = 90;
expect(sin(a)).toBe(0.8939966636005579);
});0.893996663601
});

it(title="Checking the sin() member function", body=function( currentSpec ) {
var a = 90;
Expand All @@ -18,7 +18,11 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {

it(title="Checking the sin() function to string", body=function( currentSpec ) {
var a = 90;
assertEquals("0.8939966636005579","#tostring(sin(a))#");
if ( getApplicationSettings().preciseMath )
expect("#tostring(sin(a))#").toBe("0.8939966636005579");
else
expect("#tostring(sin(a))#").toBe("0.893996663601");

});
});
}
Expand Down
39 changes: 38 additions & 1 deletion test/tickets/LDEV2793.cfc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
component extends="org.lucee.cfml.test.LuceeTestCase" labels="java" {

function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function afterAll(){
application action="update" precisemath=variables.preciseMath;
};

function run( testResults , testBox ) {
describe( title='LDEV-2793' , body=function(){
beforeEach( function(){
Expand All @@ -9,7 +17,35 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="java" {
afterEach( function(){
setTimeZone(variables.startingTZ?:"UTC");
});
it( title='test parseDateTime ' , body=function() {
it( title='test parseDateTime (preciseMath=true)' , body=function() {
application action="update" preciseMath=true;
var projects = [
{
id: 1,
name: "Really old project",
createdAt: createDate( 2015, 12, 15 ).getTime() // 1450155600000
},
{
id: 500,
name: "Recent project",
createdAt: createDate( 2019, 10, 30 ).getTime() // 1572408000000
},
{
id: 1000,
name: "Current project",
createdAt: createDate( 2020, 02, 26 ).getTime() // 1582693200000
}
];
projects.sort(
( a, b ) => {
return( b.createdAt - a.createdAt );
}
);

});

it( title='test parseDateTime (preciseMath=false)', skip=true, body=function() {
application action="update" preciseMath=false;
var projects = [
{
id: 1,
Expand All @@ -27,6 +63,7 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="java" {
createdAt: createDate( 2020, 02, 26 ).getTime() // 1582693200000
}
];
// errors, see LDEV-5178
projects.sort(
( a, b ) => {
return( b.createdAt - a.createdAt );
Expand Down
5 changes: 4 additions & 1 deletion test/tickets/LDEV3661.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{

var myJSON = '{"lat":20.12283319000001}';
var decoded = deserializeJSON( myJSON );
expect( serializeJSON( decoded ) ).toBe( '{"lat":20.12283319000001}' );
if ( getApplicationSettings().preciseMath )
expect( serializeJSON( decoded ) ).toBe( '{"lat":20.12283319000001}' );
else
expect( serializeJSON( decoded ) ).toBe( '{"lat":20.12283319}' );

});

Expand Down
Loading

0 comments on commit e41ff0b

Please sign in to comment.