Mercurial > projects > orange
annotate orange/core/io.d @ 51:70df72d2299a default tip
Added unit tests for events.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 13 Aug 2011 17:06:35 +0200 |
parents | 78e5fef4bbf2 |
children |
rev | line source |
---|---|
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
1 /** |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
2 * Copyright: Copyright (c) 2007-2008 Jacob Carlborg. All rights reserved. |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
3 * Authors: Jacob Carlborg |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
4 * Version: Initial created: 2007 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
6 * |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
7 */ |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
8 module orange.core.io; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
9 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
10 version (Tango) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
11 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
12 import tango.io.Stdout; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
13 import tango.io.Console; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
14 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
15 import orange.core.string; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
16 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
17 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
18 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
19 import std.stdio; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
20 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
21 /** |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
22 * Print to the standard output |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
23 * |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
24 * Params: |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
25 * args = what to print |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
26 */ |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
27 void print (A...)(A args) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
28 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
29 version (Tango) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
30 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
31 const string fmt = "{}{}{}{}{}{}{}{}" |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
32 "{}{}{}{}{}{}{}{}" |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
33 "{}{}{}{}{}{}{}{}"; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
34 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
35 static assert (A.length <= fmt.length / 2, "mambo.io.print :: too many arguments"); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
36 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
37 Stdout.format(fmt[0 .. args.length * 2], args).flush; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
38 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
39 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
40 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
41 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
42 write(args); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
43 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
44 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
45 /** |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
46 * Print to the standard output, adds a new line |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
47 * |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
48 * Params: |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
49 * args = what to print |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
50 */ |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
51 void println (A...)(A args) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
52 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
53 version (Tango) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
54 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
55 const string fmt = "{}{}{}{}{}{}{}{}" |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
56 "{}{}{}{}{}{}{}{}" |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
57 "{}{}{}{}{}{}{}{}"; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
58 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
59 static assert (A.length <= fmt.length / 2, "mambo.io.println :: too many arguments"); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
60 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
61 Stdout.formatln(fmt[0 .. args.length * 2], args); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
62 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
63 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
64 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
65 writeln(args); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
66 } |