'--------------------------------------------------------------------
' Test case of SPrintF Function and etc...
'--------------------------------------------------------------------

#require <Classes/ActiveBasic/Strings/SPrintF.ab>

Imports ActiveBasic.Strings
Imports ActiveBasic.Strings.Detail

Namespace SPrintFTest

Sub TestMain()
	Dim s = Nothing As String, e As Long, sign As Boolean

	s = FloatToChars(1., e, sign)
	UnitTest("FloatToChars(1)", s = "10000000000000000" And e = 0 And sign = False)

	s = FloatToChars(-93.75e-3, e, sign)
	UnitTest("FloatToChars(-93.75e-3)", s = "93750000000000000" And e = 1 - 3 And sign = True)

	s = FloatToChars(.0, e, sign)
	UnitTest("FloatToChars(0)", s = "00000000000000000" And e = 0 And sign = False)

	s = FormatFloatE(9.876543e021, 6, 0, None)
	UnitTest("FormatFloatE(9876543e+21)", s = "9.876543e+21")

	s = FormatFloatE(7.81250000E-03, 8, 0, Cap)
	UnitTest("FormatFloatE(7.81250000E-03)", s = "7.81250000E-03")

	s = FormatFloatE(1.2345e67, 4, 15, 0)
	UnitTest("FormatFloatE(1.2345e+67, field width = 15)", s = "     1.2345e+67")
	s = FormatFloatE(1.2345e67, 4, 15, Zero)
	UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero)", s = "000001.2345e+67")
	s = FormatFloatE(-1.2345e67, 4, 15, 0)
	UnitTest("FormatFloatE(-1.2345e+67, field width = 15)", s = "    -1.2345e+67")
	s = FormatFloatE(-1.2345e67, 4, 15, Zero)
	UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero)", s = "-00001.2345e+67")
	s = FormatFloatE(1.2345e67, 4, 15, Sign)
	UnitTest("FormatFloatE(1.2345e+67, field width = 15, Sign)", s = "    +1.2345e+67")
	s = FormatFloatE(1.2345e67, 4, 15, Zero Or Sign)
	UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero Or Sign)", s = "+00001.2345e+67")
	s = FormatFloatE(1.2345e67, 4, 15, Zero Or Blank)
	UnitTest("FormatFloatE(1.2345e+67, field width = 15, Zero Or Blank)", s = " 00001.2345e+67")
	s = FormatFloatE(-1.2345e67, 4, 15, Zero Or Sign)
	UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero Or Sign)", s = "-00001.2345e+67")
	s = FormatFloatE(-1.2345e67, 4, 15, Zero Or Blank)
	UnitTest("FormatFloatE(-1.2345e+67, field width = 15, Zero Or Blank)", s = "-00001.2345e+67")

	s = FormatFloatE(1.2345e+67, 4, 0, Cap)
	UnitTest("FormatFloatE(1.2345E+67, Cap)", s = "1.2345E+67")

	s = FormatFloatE(1.2345e67, 3, 0, None)
	UnitTest("FormatFloatE(1.2345e+67, precision = 3)", s = "1.234e+67")


	s = FormatIntegerU(777, 0, 0, None)
	UnitTest("FormatIntegerU(777)", s = "777")

	s = FormatIntegerU(513, 0, 5, None)
	UnitTest("FormatIntegerU(513, field width = 5)", s = "  513")

	s = FormatIntegerD(-3, 2, 0, Sign)
	UnitTest("FormatIntegerD(-3, precision = 2)", s = "-03")

	s = FormatIntegerD(3, 0, 5, Sign)
	UnitTest("FormatIntegerD(+3, field width = 5)", s = "   +3")

	s = FormatIntegerO(&o1234567, DWORD_MAX, 0, None)
	UnitTest("FormatIntegerO(&o1234567)", s = "1234567")

	s = FormatIntegerO(&o1234567, DWORD_MAX, 0, Alt)
	UnitTest("FormatIntegerO(&o1234567, Alt)", s = "01234567")

	s = FormatIntegerO(0, DWORD_MAX, 0, Alt)
	UnitTest("FormatIntegerO(0, Alt)", s = "0")

	s = FormatIntegerX(&hffff, DWORD_MAX, 0, None)
	UnitTest("FormatIntegerX(&hffff)", s = "ffff")

	s = FormatIntegerX(&hffff, DWORD_MAX, 0, Cap)
	UnitTest("FormatIntegerX(&hffff, Cap)", s = "FFFF")

	s = FormatIntegerX(&h12345678, DWORD_MAX, 0, Alt)
	UnitTest("FormatIntegerX(&h12345678, Alt)", s = "0x12345678")

	s = FormatIntegerX(1, 2, 0, Alt Or Cap)
	UnitTest("FormatIntegerX(1, precision = 2, Alt, Cap)", s = "0X01")

	s = FormatIntegerX(0, 4, 0, Alt)
	UnitTest("FormatIntegerX(0, precision = 4, Alt)", s = "0000")

'	s = FormatIntegerLU(8589934590, DWORD_MAX, 0, None)
'	UnitTest("FormatIntegerLU(8589934590)", s = "8589934590")
End Sub

End Namespace 'SPrintFTest

SPrintFTest.TestMain()
