#QUALITY by cg
class: RegressionTests::NumberTest
changed:
#testPrintf_Integer
#testPrintf_Misc
--- a/RegressionTests__NumberTest.st Tue Dec 03 11:53:56 2019 +0100
+++ b/RegressionTests__NumberTest.st Tue Dec 03 12:46:10 2019 +0100
@@ -310,6 +310,10 @@
!
testPrintf_Integer
+ |skipB systemIsWin32Bit|
+
+ systemIsWin32Bit := OperatingSystem isMSWINDOWSlike and:[ ExternalAddress pointerSize == 4 ].
+
"/ Integers
"/ verify that our printf generates the same string as the system-printf.
@@ -325,13 +329,32 @@
self assert:( (20 printfPrintString:'%-#5d') = '20 ' ).
self assert:( (20 printfPrintString:'%-#05d') = '20 ' ). "/ NOTICE
self assert:( (20 printfPrintString:'%-0#5d') = '20 ' ). "/ NOTICE
- self assert:( (20 printfPrintString:'%0-#5d') = '20 ' ). "/ NOTICE
- self assert:( (20 printfPrintString:'%0#-5d') = '20 ' ). "/ NOTICE
+ "/ borland printf is wrong here
+ (OperatingSystem isMSWINDOWSlike and:[ ExternalAddress pointerSize == 4]) ifTrue:[
+ "/ skip
+ ] ifFalse:[
+ self assert:( (20 printfPrintString:'%0-#5d') = '20 ' ). "/ NOTICE - some printf's dont do this correctly
+ self assert:( (20 printfPrintString:'%0#-5d') = '20 ' ). "/ NOTICE
+ ].
self assert:( (20 printfPrintString:'%#05d') = '00020' ).
- self assert:( (20 printfPrintString:'%# 5d') = ' 20' ).
self assert:( (20 printfPrintString:'%+ 5d') = ' +20' ).
self assert:( (20 printfPrintString:'%- 5d') = ' 20 ' ).
self assert:( (-20 printfPrintString:'%- 5d') = '-20 ' ).
+ self assert:( ( 20 printfPrintString:'%-+ 5d') = '+20 ' ).
+ self assert:( (-20 printfPrintString:'%-+ 5d') = '-20 ' ).
+ self assert:( ( 20 printfPrintString:'%+ 5d') = ' +20' ).
+ self assert:( (-20 printfPrintString:'%+ 5d') = ' -20' ).
+ self assert:( ( 0 printfPrintString:'%+ 5d') = ' +0' ).
+ self assert:( ( 0 printfPrintString:'%-+ 5d') = '+0 ' ).
+
+ self assert:( (20 printfPrintString:'%# 5d') = ' 20' ).
+
+ "/ skip with borland (that printf is wrong):
+ skipB := #(
+ ('%D' nil) "/ not supported at all
+ ('%#x' 0 ) "/ printf is wrong: always prepending 0x - even for 0 value
+ ('%#o' 0 ) "/ printf is wrong: always prepending 0 - even for 0 value
+ ).
#(
'%d' 20 '20'
@@ -373,7 +396,7 @@
'%#x' 255 '0xff'
'%#X' 255 '0XFF' "/ printf also uppercases the 'x'
'%x' 0 '0'
- '%#x' 0 '0'
+ '%#x' 0 '0' "/ with zero, no 0x should be prepended
'%#x' 20 '0x14'
'%5x' 20 ' 14'
'%-5x' 20 '14 '
@@ -385,7 +408,7 @@
'%o' 20 '24'
'%o' 0 '0'
'%#o' 20 '024'
- '%#o' 0 '0'
+ '%#o' 0 '0' "/ with zero, no 0 should be prepended
'%5o' 20 ' 24'
'%-5o' 20 '24 '
'%#5o' 20 ' 024'
@@ -414,12 +437,20 @@
'%.3x' 0xAFFE 'affe' "/ max length ignored for numbers
) inGroupsOf:3 do:[:fmt :val :expected|
- |printfGenerated stxGenerated|
+ |skip printfGenerated stxGenerated|
- printfGenerated := val printfPrintString:fmt.
- stxGenerated := PrintfScanf printf:fmt argument:val.
- self assert:(stxGenerated = printfGenerated).
- self assert:(printfGenerated = expected).
+ skip := false.
+ systemIsWin32Bit ifTrue:[
+ skip := skipB contains:[:pair | (pair first = fmt) and:[(pair second ? val) = val]].
+ ].
+ skip ifTrue:[
+ Transcript showCR:'skipped check for %1 (borland printf does not handle it correctly)' with:fmt
+ ] ifFalse:[
+ printfGenerated := val printfPrintString:fmt.
+ stxGenerated := PrintfScanf printf:fmt argument:val.
+ self assert:(stxGenerated = printfGenerated).
+ self assert:(printfGenerated = expected).
+ ]
].
"/ hex
@@ -576,8 +607,15 @@
"/ Checks of printfPrintString: are here to make sure, that the system's printf is doing it right...)
self assert:( (20 printfPrintString:'%%%d') = '%20' ).
self assert:( (20 printfPrintString:'%d%%') = '20%' ).
- self assert:( (20 printfPrintString:'%d%') = '20' ).
+ "/ borland is wrong here
+ (OperatingSystem isMSWINDOWSlike and:[ExternalAddress pointerSize == 4]) ifFalse:[
+ self assert:( (20 printfPrintString:'%d%') = '20' ).
+ ].
+ self assert:( PrintfScanf printf:'%d%' argument:20 ) = '20' .
+ self assert:( (20 printfPrintString:'%%') = '%' ).
+ self assert:( (20 printfPrintString:c'\%') = '%' ).
+
{
'%f' . Float NaN . 'nan' .
'%F' . Float NaN . 'NAN' .
@@ -586,8 +624,10 @@
'%f' . Float negativeInfinity . '-inf' .
'%F' . Float negativeInfinity . '-INF' .
- '%+f' . Float NaN . 'nan' .
- '%+F' . Float NaN . 'NAN' .
+ '%+f' . Float NaN . '-nan' .
+ '%+F' . Float NaN . '-NAN' .
+ '%+f' . Float NaN negated . '+nan' .
+ '%+F' . Float NaN negated . '+NAN' .
'%+f' . Float infinity . '+inf' .
'%+F' . Float infinity . '+INF' .
'%+f' . Float negativeInfinity . '-inf' .
@@ -627,6 +667,12 @@
self assert:(stxGenerated = printfGenerated).
self assert:(printfGenerated = expected).
].
+
+ "/ more examples from "Secretes of printf"
+ self assert:( (0 printfPrintString:'%d') = '0' ).
+ self assert:( (-7 printfPrintString:'%d') = '-7' ).
+ self assert:( (1560133635 printfPrintString:'%d') = '1560133635' ).
+ self assert:( (-2035065302 printfPrintString:'%d') = '-2035065302' ).
!
testPrintf_QDouble