~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to ext/standard/tests/general_functions/001.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--TEST--
 
2
sprintf() function
 
3
--FILE--
 
4
<?php 
 
5
 
 
6
$agent = sprintf("%.5s", "James Bond, 007");
 
7
 
 
8
echo("sprintf string truncate test:   ");
 
9
if ($agent == "James") {
 
10
        echo("passed\n");
 
11
} else {
 
12
        echo("failed!\n");
 
13
}
 
14
 
 
15
echo("sprintf padding and align test: ");
 
16
$test = sprintf("abc%04d %-20s%c", 20, "fisketur", 33);
 
17
if ($test == "abc0020 fisketur            !") {
 
18
        echo("passed\n");
 
19
} else {
 
20
        echo("failed!\n");
 
21
}
 
22
 
 
23
echo("sprintf octal and hex test:     ");
 
24
$test = sprintf("%4o %4x %4X %0"."8x", 128, 1024, 49151, 3457925);
 
25
if ($test == " 200  400 BFFF 0034c385") {
 
26
        echo("passed\n");
 
27
} else {
 
28
        echo("failed!\n");
 
29
}
 
30
 
 
31
echo("sprintf octal binary test:      ");
 
32
$test = sprintf("%b", 3457925);
 
33
if ($test == "1101001100001110000101") {
 
34
        echo("passed\n");
 
35
} else {
 
36
        echo("failed!\n");
 
37
}
 
38
 
 
39
echo("sprintf float test:             ");
 
40
$test = sprintf("%0"."06.2f", 10000/3.0);
 
41
if ($test == "003333.33") {
 
42
        echo("passed\n");
 
43
} else {
 
44
        echo("failed!\n");
 
45
}
 
46
 
 
47
echo sprintf("%.2f\n", "99.00");
 
48
echo sprintf("%.2f\n", 99.00);
 
49
 
 
50
echo sprintf("%e\n", 1.234E-18);
 
51
echo sprintf("%e\n", 1.234E+18);
 
52
echo sprintf("%e\n", 9843243.12);
 
53
echo sprintf("%e\n", -9843243.12);
 
54
 
 
55
?>
 
56
--EXPECT--
 
57
sprintf string truncate test:   passed
 
58
sprintf padding and align test: passed
 
59
sprintf octal and hex test:     passed
 
60
sprintf octal binary test:      passed
 
61
sprintf float test:             passed
 
62
99.00
 
63
99.00
 
64
1.23400e-18
 
65
1.23400e+18
 
66
9.84324e+6
 
67
-9.84324e+6