r8346: added a sprintf test suite for ejs
authorAndrew Tridgell <tridge@samba.org>
Tue, 12 Jul 2005 05:58:41 +0000 (05:58 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:20:09 +0000 (13:20 -0500)
testprogs/ejs/sprintf.js [new file with mode: 0755]

diff --git a/testprogs/ejs/sprintf.js b/testprogs/ejs/sprintf.js
new file mode 100755 (executable)
index 0000000..34df4f9
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/env smbscript
+/*
+       test sprintf function
+*/
+
+function check_result(s, v)
+{
+       if (s != v) {
+               println("expected '" + v + "' but got '" + s + "'");
+       }
+       assert(s == v);
+}
+
+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%");
+
+println("ALL OK");