pike.git
/
src
/
testsuite.in
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/testsuite.in:13177:
]],[[ ({}) ]]) test_any_equal([[ class X { mixed test(int a, mixed ... b) { if(a) return test(0); return b; } }; return X()->test(1,2); ]],[[ ({}) ]])
+
+
+
// - sprintf module
+
+
dnl This really belongs to sscanf, but...
+
test_eq([[ array_sscanf(sprintf("%1c", -1), "%1c")[0] ]], 255)
+
test_eq([[ array_sscanf(sprintf("%2c", -1), "%2c")[0] ]], 65535)
+
test_eq([[ array_sscanf(sprintf("%3c", -1), "%3c")[0] ]], 16777215)
+
+
test_eq([[ sprintf("%4c",16909060) ]],"\1\2\3\4")
+
test_eq([[ sprintf("%-4c",16909060) ]],"\4\3\2\1")
+
test_eq([[ sprintf("%2c",16909060) ]],"\3\4")
+
test_eq([[ sprintf("%-2c",16909060) ]],"\4\3")
+
test_eq([[ sprintf("%4c",2147483648) ]],"\200\0\0\0")
+
test_eq([[ sprintf("%-4c",2147483648) ]],"\0\0\0\200")
+
test_eq([[ sprintf("%2c",2147483648) ]],"\0\0")
+
test_eq([[ sprintf("%-2c",2147483648) ]],"\0\0")
+
+
cond([[ sizeof( cpp("__AUTO_BIGNUM__")/"__AUTO_BIGNUM__" ) == 1 ]])
+
+
test_eq([[ sprintf("%1c", 0x1abcd7893) ]], "\223")
+
test_eq([[ sprintf("%2c", 0x1abcd7893) ]], "x\223")
+
test_eq([[ sprintf("%3c", 0x1abcd7893) ]], "\315x\223")
+
test_eq([[ sprintf("%4c", 0x1abcd7893) ]], "\253\315x\223")
+
test_eq([[ sprintf("%5c", 0x1abcd7893) ]], "\1\253\315x\223")
+
test_eq([[ sprintf("%6c", 0x1abcd7893) ]], "\0\1\253\315x\223")
+
test_eq([[ sprintf("%7c", 0x1abcd7893) ]], "\0\0\1\253\315x\223")
+
+
test_eq([[ sprintf("%1c", -0x1abcd7893) ]], "m")
+
test_eq([[ sprintf("%2c", -0x1abcd7893) ]], "\207m")
+
test_eq([[ sprintf("%3c", -0x1abcd7893) ]], "2\207m")
+
test_eq([[ sprintf("%4c", -0x1abcd7893) ]], "T2\207m")
+
test_eq([[ sprintf("%5c", -0x1abcd7893) ]], "\376T2\207m")
+
test_eq([[ sprintf("%6c", -0x1abcd7893) ]], "\377\376T2\207m")
+
test_eq([[ sprintf("%7c", -0x1abcd7893) ]], "\377\377\376T2\207m")
+
+
test_eq([[ array_sscanf(sprintf("%4c", -1), "%4c")[0] ]], 4294967295)
+
test_eq([[ array_sscanf(sprintf("%5c", -1), "%5c")[0] ]], 1099511627775)
+
test_eq([[ array_sscanf(sprintf("%6c", -1), "%6c")[0] ]], 281474976710655)
+
test_eq([[ array_sscanf(sprintf("%7c", -1), "%7c")[0] ]], 72057594037927935)
+
test_eq([[ array_sscanf(sprintf("%8c", -1), "%8c")[0] ]], 18446744073709551615)
+
test_eq([[ array_sscanf(sprintf("%9c", -1), "%9c")[0] ]], 4722366482869645213695)
+
test_eq([[ array_sscanf(sprintf("%10c", -1), "%10c")[0] ]], 1208925819614629174706175)
+
test_eq([[ array_sscanf(sprintf("%11c", -1), "%11c")[0] ]], 309485009821345068724781055)
+
+
test_eq("\25363274223", [[ sprintf("%c", 0x1abcd7893) ]])
+
test_eq("\12414503555", [[ sprintf("%c", -0x1abcd7893) ]])
+
+
cond_end // __AUTO_BIGNUM__
+
+
test_eq([[ sprintf("%x", -1) ]], "-1")
+
test_eq([[ sprintf("%4x", -1) ]], " -1")
+
test_eq([[ sprintf("%10x", -1) ]], " -1")
+
test_eq([[ sprintf("%10x", -15) ]], " -f")
+
test_eq([[ sprintf("%010x", -15) ]], "-00000000f")
+
+
test_eq([[ sprintf("%08x", -1) ]], "-0000001")
+
test_eq([[ sprintf("%016x", -15) ]], "-00000000000000f")
+
test_eq([[ sprintf("%x", 65535) ]], "ffff")
+
test_eq([[ sprintf("%x", -0x80000000) ]], "-80000000")
+
+
test_eq("f", [[ sprintf("%.1x", -1) ]])
+
test_eq("ff", [[ sprintf("%.2x", -1) ]])
+
test_eq("fff", [[ sprintf("%.3x", -1) ]])
+
test_eq("ffffffffffffffffffff", [[ sprintf("%.20x", -1) ]])
+
test_eq("1", [[ sprintf("%.3x", 1) ]])
+
test_eq("1", [[ sprintf("%0.3x", 1) ]])
+
test_eq("fff", [[ sprintf("%0.3x", -1) ]])
+
test_eq("1", [[ sprintf("%0.16x", 1) ]])
+
test_eq("ffffffffffffffff", [[ sprintf("%0.16x", -1) ]])
+
test_eq(" ff", [[ sprintf("%4.2x", -1) ]])
+
test_eq("00ff", [[ sprintf("%04.2x", -1) ]])
+
test_eq("0001", [[ sprintf("%04.2x", 1) ]])
+
test_eq("00cc", [[ sprintf("%04.2x", -0x1234) ]])
+
+
cond_begin([[ sizeof( cpp("__AUTO_BIGNUM__")/"__AUTO_BIGNUM__" ) == 1 ]])
+
+
test_eq("-123456789123456789", [[ sprintf("%x", -0x123456789123456789) ]])
+
test_eq("ba9877", [[ sprintf("%.6x", -0x123456789123456789) ]])
+
test_eq("876edcba9877", [[ sprintf("%.12x", -0x123456789123456789) ]])
+
test_eq(" 876edcba9877", [[ sprintf("%20.12x",-0x123456789123456789)]])
+
+
cond_end // __AUTO_BIGNUM__
+
+
test_eq("77777777760000000000", [[ sprintf("%.20o", -0x80000000) ]])
+
+
test_true(stringp(sprintf("")))
+
test_true(sprintf("--real %1.20f --imaginary %1.20f --scale %1.20f\n",-0.9,-0.9,-0.9))
+
test_eq(sprintf("%%"),"%")
+
test_eq(sprintf("%d",1),"1")
+
test_eq(sprintf("%d",-1),"-1")
+
test_eq(sprintf("%o",1),"1")
+
test_eq(sprintf("%u",1<<31),"2147483648")
+
test_false(sprintf("%u",-1)=="-1")
+
test_eq(sprintf("%o",255),"377")
+
test_eq(sprintf("%o",-9),"-11")
+
test_eq(sprintf("%o",012345670),"12345670")
+
test_eq(sprintf("%x",255),"ff")
+
test_eq(sprintf("%x",-27),"-1b")
+
test_eq(sprintf("%X",255),"FF")
+
test_eq(sprintf("%X",-27),"-1B")
+
test_eq(sprintf("%c",255),"\377")
+
test_eq(sprintf("%2c",65535),"\377\377")
+
test_eq(sprintf("%3c",0xffffff),"\377\377\377")
+
test_true(stringp(sprintf("%f",255.0)))
+
test_true(stringp(sprintf("%g",255.0)))
+
test_true(stringp(sprintf("%G",255.0)))
+
test_true(stringp(sprintf("%e",255.0)))
+
test_true(stringp(sprintf("%E",255.0)))
+
+
test_eq(sprintf("%.1f",31415.9267),"31415.9")
+
test_eq(sprintf("%.0f",31415.9267),"31416")
+
test_eq(sprintf("%.-1f",31415.9267),"31420")
+
test_eq(sprintf("%.-2f",31415.9267),"31400")
+
test_eq(sprintf("%.-2f",-31415.9267),"-31400")
+
test_eq(sprintf("%.-10f",31415.9267),"0")
+
test_eq(sprintf("%20.-3f", 31415.92670)," 31000")
+
+
+
dnl test for high exponent problems
+
dnl (this might only effect --with-double-precision et al)
+
test_true(stringp(sprintf("%f",exp(700))))
+
test_true(stringp(sprintf("%g",exp(700))))
+
test_true(stringp(sprintf("%G",exp(700))))
+
test_true(stringp(sprintf("%e",exp(700))))
+
test_true(stringp(sprintf("%E",exp(700))))
+
+
dnl test for "inf" problems
+
test_eq(lower_case(sprintf("%f",Math.inf)),"inf")
+
test_eq(lower_case(sprintf("%g",Math.inf)),"inf")
+
test_eq(lower_case(sprintf("%G",Math.inf)),"inf")
+
test_eq(lower_case(sprintf("%e",Math.inf)),"inf")
+
test_eq(lower_case(sprintf("%E",Math.inf)),"inf")
+
test_eq(lower_case(sprintf("%f",-Math.inf)),"-inf")
+
test_eq(lower_case(sprintf("%g",-Math.inf)),"-inf")
+
test_eq(lower_case(sprintf("%G",-Math.inf)),"-inf")
+
test_eq(lower_case(sprintf("%e",-Math.inf)),"-inf")
+
test_eq(lower_case(sprintf("%E",-Math.inf)),"-inf")
+
+
dnl test for "nan" problems
+
dnl At least the following variants exist: "nan", "Nan", "NaN", "NaNQ".
+
test_eq(lower_case(sprintf("%f",Math.nan)[..2]),"nan")
+
test_eq(lower_case(sprintf("%g",Math.nan)[..2]),"nan")
+
test_eq(lower_case(sprintf("%G",Math.nan)[..2]),"nan")
+
test_eq(lower_case(sprintf("%e",Math.nan)[..2]),"nan")
+
test_eq(lower_case(sprintf("%E",Math.nan)[..2]),"nan")
+
+
test_eq(sprintf("%s","foobaR"),"foobaR")
+
test_eq(sprintf("%s","foo\nbar"),"foo\nbar")
+
test_eq(sprintf("%8.3s","foobar")," foo")
+
test_true(stringp(sprintf("%O",this_object())))
+
test_true(stringp(sprintf("%O",({}))))
+
test_eq(sprintf("%n"),"")
+
test_eq(sprintf("%t",1),"int")
+
test_eq(sprintf("%t",1.0),"float")
+
test_eq(sprintf("%t",""),"string")
+
test_eq(sprintf("%t",this_object()),"object")
+
test_eq(sprintf("%t", ({"a"})), "array")
+
test_any([[array(string) a = ({"a"}); return sprintf("%t", a);]], "array")
+
test_eq(sprintf("%t", 0), "int")
+
test_any([[array(string) a = 0; return sprintf("%t", a);]], "int")
+
test_eq(sprintf("%t", (<>)), "multiset")
+
test_eq(sprintf("%t", ([])), "mapping")
+
test_eq(sprintf("%t", sin), "function")
+
test_eq(sprintf("%t", class {}), "program")
+
test_eq(sprintf("%t", typeof(3)), "type")
+
+
test_eq(strlen(sprintf("%1000s","")),1000)
+
test_eq(sprintf("%2d",1)," 1")
+
test_eq(sprintf("%2d",1)," 1")
+
test_eq(sprintf("foo_%3d",1),"foo_ 1")
+
test_eq(sprintf("%2d",2222),"2222")
+
test_eq(sprintf("%!2d",2222),"22")
+
test_eq(sprintf("%!!2d",2222),"2222")
+
test_eq(sprintf("% d",2)," 2")
+
test_eq(sprintf("% d",-2),"-2")
+
test_eq(sprintf("%+d",2),"+2")
+
test_eq(sprintf("%+d",-2),"-2")
+
test_eq(sprintf("%-2d",2),"2 ")
+
test_eq(sprintf("%|3d",2)," 2 ")
+
test_eq(sprintf("%-=3s","f o bar gaz"),"f o\nbar\ngaz")
+
dnl test_eq(sprintf("%/3s","f o bargaz"),"f o\nbar\ngaz")
+
test_true(stringp(sprintf("%3#s","f\no\nbargaz\nonk")))
+
test_true(stringp(sprintf("%3$s","f\no\nbargaz\nonk")))
+
test_eq(sprintf("%-$79s","foo\nbar\ngazonk"),"foo bar gazonk ")
+
test_eq(sprintf("%-$20s","foo\nbar\ngazonk"),"foo bar \ngazonk ")
+
test_eq(sprintf("%-#79s","foo\nbar\ngazonk"),"foo bar gazonk ")
+
test_eq(sprintf("%-#20s","foo\nbar\ngazonk"),"foo gazonk \nbar ")
+
+
test_eq(sprintf("%.0f",17.23456),"17")
+
+
test_eq(sprintf("%*d",3,3)," 3")
+
test_eq(sprintf("%'FOO'10s","BAR"),"FOOFOOFBAR")
+
test_eq(sprintf("%d %<d %<d",2),"2 2 2")
+
test_true(stringp(sprintf("%O",({1,2,"foo"}))))
+
test_true(stringp(sprintf("%O",([1:2,"foo":"bar"]))))
+
test_eq(sprintf("%@4d", (array)"hi!")," 104 105 33")
+
test_eq(strlen(sprintf("%@c",allocate(1000))),1000)
+
+
test_eq(sprintf("test \0 \n"),"test \0 \n")
+
test_eq(sprintf("test \0"),"test \0")
+
test_eq(sprintf("%~*n","f",5),"fffff")
+
test_eq(sprintf("%'\000'*n",5),"\000\000\000\000\000")
+
+
test_eq(sprintf("%{%d\n%}",({1,2,3,4})),"1\n2\n3\n4\n")
+
+
test_true([[sprintf("%{%{%s%}\n%}",({({({"hej"})}),({({"hop"})})}))]])
+
test_true([[sprintf("%{%{%s%}\n%}",({({({"hej"})}),({({"hop"})})}))]])
+
test_true([[sprintf("%{%{%s%}\n%}",({({({"hej"})}),({({"hop"})})}))]])
+
test_true([[sprintf("%{%{%s%}\n%}",({({({"hej"})}),({({"hop"})})}))]])
+
+
test_eq([[sprintf("%{%d %d %d\n%}",({ ({1,2,3}), ({4,5,6}) }) )]],"1 2 3\n4 5 6\n")
+
+
test_eq([[sprintf("%4F", 0.0)]], "\000\000\000\000")
+
test_eq([[sprintf("%4F", 1.0)]], "\077\200\000\000")
+
test_eq([[sprintf("%4F", 0.5)]], "\077\000\000\000")
+
test_eq([[sprintf("%4F", 2.0)]], "\100\000\000\000")
+
test_eq([[sprintf("%4F", 1.5)]], "\077\300\000\000")
+
test_eq([[sprintf("%4F", 1048576.125)]], "\111\200\000\001")
+
test_eq([[sprintf("%4F", -17.5)]], "\301\214\000\000")
+
cond([[pow(2.0,-128.0)!=0.0]],
+
[[
+
test_eq([[sprintf("%4F", pow(2.0,-128.0))]], "\000\040\000\000")
+
]])
+
test_eq([[sprintf("%4F", 0.033)]], "\075\007\053\002")
+
test_eq([[sprintf("%4F", pow(2.0,128.0))]], "\177\200\000\000")
+
test_eq([[sprintf("%8F", 0.0)]], "\000\000\000\000\000\000\000\000")
+
test_eq([[sprintf("%8F", 1.0)]], "\077\360\000\000\000\000\000\000")
+
test_eq([[sprintf("%8F", 0.5)]], "\077\340\000\000\000\000\000\000")
+
test_eq([[sprintf("%8F", 2.0)]], "\100\000\000\000\000\000\000\000")
+
test_eq([[sprintf("%8F", 1.5)]], "\077\370\000\000\000\000\000\000")
+
test_eq([[sprintf("%8F", 1048576.125)]], "\101\060\000\000\040\000\000\000")
+
test_eq([[sprintf("%8F", -17.5)]], "\300\061\200\000\000\000\000\000")
+
cond([[pow(2.0,-128.0)!=0.0]],
+
[[
+
test_eq([[sprintf("%8F", pow(2.0,-128.0))]], "\067\360\000\000\000\000\000\000")
+
]])
+
test_eq([[sprintf("%8F", 0.032999999821186065673828125)]], "\077\240\345\140\100\000\000\000")
+
+
cond([[pow(2.0,1024.0)!=0.0]],
+
[[
+
test_eq([[sprintf("%8F", pow(2.0,1024.0))]], "\177\360\000\000\000\000\000\000")
+
]])
+
+
dnl Make sure that _sprintf is called and that the argument list isn't screwed.
+
test_eq(sprintf("%d%c%s%t%o%d%u%x%X%e%f%g%E%G%O%d", 4711,
+
@allocate(14, (class { string _sprintf(int t)
+
{ mixed x = "not a number";
+
string s;
+
catch {
+
s = sprintf("%d%d%d%d", 1, 2, x, 3);
+
};
+
return sprintf("[%c%c%c]", 'a', t, 'b'); }
+
})()), 42),
+
"4711[acb][asb][atb][aob][adb][aub][axb][aXb]"
+
"[aeb][afb][agb][aEb][aGb][aOb]42")
+
+
test_eq(sprintf("%[*]s %s",2,"a","b"),"b a")
+
test_eq(sprintf("%[1]s %s %[2]s %s","b","a","r"),"a b r a")
+
+
test_do(catch(sprintf("%d-" *101, @allocate(101))))
+
+
test_eq(sprintf("%O", "a\nb"),"\"a\\n\"\n\"b\"")
+
test_eq(sprintf("%O", "a\0b"),"\"a\\0b\"")
+
test_eq(sprintf("%O", "a\0""0"),"\"a\\0\"\"0\"")
+
+
test_eq(sprintf_76("%O", "a\nb"),"\"a\\nb\"")
+
test_eq(sprintf_76("%O", "a\0b"),"\"a\\0b\"")
+
test_eq(sprintf_76("%O", "a\0""0"),"\"a\\0\"\"0\"")
+
+
test_eq(sprintf("%q", "a\nb"),"\"a\\nb\"")
+
test_eq(sprintf("%q", "a\0b"),"\"a\\0b\"")
+
test_eq(sprintf("%q", "a\0""0"),"\"a\\u00000\"")
+
test_eq(sprintf("%q", "\177\177""0"),"\"\\177\\u007f0\"")
+
+
test_eq(sprintf("%H", ""),"\0")
+
test_eq(sprintf("%H", "hello"),"\5hello")
+
+
test_eval_error(return sprintf("%0H", ""))
+
test_eval_error(return sprintf("%0H", "hello"))
+
+
test_eq(sprintf("%1H", ""),"\0")
+
test_eq(sprintf("%1H", "hello"),"\5hello")
+
test_eq(sprintf("%-1H", ""),"\0")
+
test_eq(sprintf("%-1H", "hello"),"\5hello")
+
test_eq(sprintf("%2H", ""),"\0\0")
+
test_eq(sprintf("%2H", "hello"),"\0\5hello")
+
test_eq(sprintf("%-2H", ""),"\0\0")
+
test_eq(sprintf("%-2H", "hello"),"\5\0hello")
+
test_eq(sprintf("%4H", ""),"\0\0\0\0")
+
test_eq(sprintf("%4H", "hello"),"\0\0\0\5hello")
+
test_eq(sprintf("%-4H", ""),"\0\0\0\0")
+
test_eq(sprintf("%-4H", "hello"),"\5\0\0\0hello")
+
test_do(sprintf("%9H", "x"*300););
+
+
test_eval_error(return sprintf("%H", "\x100");)
+
test_do(return sprintf("%1H", "x"*255);)
+
test_eval_error(return sprintf("%1H", "x"*256);)
+
+
dnl / : ; ^ _ > hasn't been tested
+
test_eval_error(return sprintf("%d");)
+
+
test_eq(sprintf("%O", class { string _sprintf(int type) { return "\t"; } }()), "\t")
+
END_MARKER