From 9370fca5dd014520b0c8970e55d33907921be518 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Jul 2005 05:58:41 +0000 Subject: r8346: added a sprintf test suite for ejs (This used to be commit 14af014410a9971d447aafe00640407698f63d7f) --- testprogs/ejs/sprintf.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 testprogs/ejs/sprintf.js (limited to 'testprogs/ejs/sprintf.js') diff --git a/testprogs/ejs/sprintf.js b/testprogs/ejs/sprintf.js new file mode 100755 index 0000000000..34df4f9a42 --- /dev/null +++ b/testprogs/ejs/sprintf.js @@ -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"); -- cgit From 26a55c330a8cd79da290b2ad0e15aaf94be6ebcf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Jul 2005 06:57:25 +0000 Subject: r8355: - added a vsprintf() function - removed the --outputdir option from provision, as its not used any more (as ejs knows the real paths) (This used to be commit abbf9c703c17c2edc2d978dade3619a96c38d0d9) --- testprogs/ejs/sprintf.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'testprogs/ejs/sprintf.js') diff --git a/testprogs/ejs/sprintf.js b/testprogs/ejs/sprintf.js index 34df4f9a42..4d3d9a7555 100755 --- a/testprogs/ejs/sprintf.js +++ b/testprogs/ejs/sprintf.js @@ -11,6 +11,11 @@ function check_result(s, v) 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"); @@ -19,4 +24,6 @@ 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"); -- cgit From 620301858a5b747002eebe2b9fcef10712ee8249 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Jul 2005 07:04:07 +0000 Subject: 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 a978484738168b82441c4dc4f5f803d349769a4b) --- testprogs/ejs/sprintf.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'testprogs/ejs/sprintf.js') diff --git a/testprogs/ejs/sprintf.js b/testprogs/ejs/sprintf.js index 4d3d9a7555..6ae8605718 100755 --- a/testprogs/ejs/sprintf.js +++ b/testprogs/ejs/sprintf.js @@ -3,6 +3,8 @@ test sprintf function */ +string_init(local); + function check_result(s, v) { if (s != v) { -- cgit