forked from lucee/Lucee
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDEV-5189 ParseNumber should support preciseMath
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
component extends="org.lucee.cfml.test.LuceeTestCase" { | ||
function beforeAll(){ | ||
variables.preciseMath = getApplicationSettings().preciseMath; | ||
}; | ||
|
||
function afterAll(){ | ||
application action="update" precisemath=variables.preciseMath; | ||
}; | ||
|
||
function run( testResults, testBox ){ | ||
describe( "Test LSParseNumber", function(){ | ||
|
||
it( "Test with Large number", function(){ | ||
var n = "2.305.843.009,01"; | ||
var locale = "german (standard)"; | ||
application action="update" preciseMath=false; | ||
expect( LSParseNumber( n, locale ) ).toBe( 2305843009 ); | ||
application action="update" preciseMath=true; | ||
expect( LSparseNumber( n, locale ) ).toBe( 2305843009 ); // but it returns 2305843009.01 ? | ||
}); | ||
|
||
it( "Test with Large number", function(){ | ||
var n = "2.305.843.009.213.693.951,01"; | ||
var locale = "german (standard)"; | ||
application action="update" preciseMath=false; | ||
expect( LSParseNumber( n, locale ) ).toBe( 2305843009213693696 ); | ||
application action="update" preciseMath=true; | ||
expect( LSparseNumber( n, locale ) ).toBe( 2305843009213693952 ); // LSParseNumber doesn't support big numbers | ||
}); | ||
|
||
} ); | ||
} | ||
|
||
} |
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,59 @@ | ||
component extends="org.lucee.cfml.test.LuceeTestCase" { | ||
function beforeAll(){ | ||
variables.preciseMath = getApplicationSettings().preciseMath; | ||
}; | ||
|
||
function afterAll(){ | ||
application action="update" precisemath=variables.preciseMath; | ||
}; | ||
|
||
function run( testResults, testBox ){ | ||
describe( "Test ParseNumber", function(){ | ||
|
||
it( "Test with smaller number", function(){ | ||
var n = "2305843.44"; | ||
application action="update" preciseMath=false; | ||
expect( parseNumber( n ) ).toBe( 2305843.44 ); | ||
application action="update" preciseMath=true; | ||
expect( parseNumber( n ) ).toBe( 2305843.44 ); | ||
}); | ||
|
||
it( "Test with Large number", function(){ | ||
var n = "2305843009213693951.77"; | ||
application action="update" preciseMath=false; | ||
expect( parseNumber( n ) ).toBe( 2305843009213693696 ); | ||
application action="update" preciseMath=true; | ||
expect( parseNumber( n ) ).toBe( 2305843009213693951 ); // returns 2305843009213693951.77 | ||
}); | ||
|
||
it( "Test Bin", function(){ | ||
application action="update" preciseMath=false; | ||
var n = "1000"; | ||
var radix = "bin"; | ||
expect( parseNumber( n, radix ) ).toBe( 8 ); | ||
application action="update" preciseMath=true; | ||
expect( parseNumber( n, radix ) ).toBe( 8 ); | ||
}); | ||
|
||
it( "Test Oct", function(){ | ||
application action="update" preciseMath=false; | ||
var n = "1000"; | ||
var radix = "oct"; | ||
expect( parseNumber( n, radix ) ).toBe( 512 ); | ||
application action="update" preciseMath=true; | ||
expect( parseNumber( n, radix ) ).toBe( 512 ); | ||
}); | ||
|
||
it( "Test Hex", function(){ | ||
application action="update" preciseMath=false; | ||
var n = "1000"; | ||
var radix = "hex"; | ||
expect( parseNumber( n, radix ) ).toBe( 4096 ); | ||
application action="update" preciseMath=true; | ||
expect( parseNumber( n, radix ) ).toBe( 4096 ); | ||
}); | ||
|
||
} ); | ||
} | ||
|
||
} |