1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-27 03:21:53 +03:00
samba-mirror/testprogs/ejs/sprintf.js
Andrew Tridgell 620301858a r8638: continue the trend of maknig our C functions true ejs objects by making the string functions
into an object. To keep existing code working I have added:

  string_init(global);

into base.js. That brings the functions into the global scope for our
existing scripts
(This used to be commit a978484738)
2007-10-10 13:29:48 -05:00

32 lines
744 B
JavaScript
Executable File

#!/usr/bin/env smbscript
/*
test sprintf function
*/
string_init(local);
function check_result(s, v)
{
if (s != v) {
println("expected '" + v + "' but got '" + s + "'");
}
assert(s == v);
}
function xprintf()
{
return "XX{" + vsprintf(arguments) + "}XX";
}
check_result(sprintf("%d", 7), "7");
check_result(sprintf("%04d", 42), "0042");
check_result(sprintf("my string=%7.2s", "foo%7"), "my string= fo");
check_result(sprintf("blah=0x%*x", 4, 19), "blah=0x 13");
check_result(sprintf("blah=0x%0*x", 4, 19), "blah=0x0013");
check_result(sprintf("blah=%.0f", 1032), "blah=1032");
check_result(sprintf("%4.2f%%", 72.32), "72.32%");
check_result(xprintf("%4.2f%% and %s", 72.32, "foo"),"XX{72.32% and foo}XX");
println("ALL OK");