annotate tests/Util.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 02dbd18b7fe9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1 /**
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
2 * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved.
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
3 * Authors: Jacob Carlborg
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
4 * Version: Initial created: Aug 6, 2011
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
6 */
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
7 module tests.Util;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
8
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
9 import orange.core.string;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
10
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
11 bool containsDefaultXmlContent (string source)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
12 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
13 return source.containsXmlHeader() &&
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
14 source.containsArchive() &&
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
15 source.containsXmlTag("data");
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
16 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
17
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
18 bool containsXmlHeader (string source)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
19 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
20 return source.contains(`<?xml version="1.0" encoding="UTF-8"?>`);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
23 bool containsArchive (string source)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
24 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 return source.containsArchiveHeader() && source.contains("</archive>");
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
26 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
27
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
28 bool containsArchiveHeader (string source)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30 return source.contains(`<archive type="org.dsource.orange.xml" version="1.0.0">`) ||
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 source.contains(`<archive version="1.0.0" type="org.dsource.orange.xml">`);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
33
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
34 bool containsXmlTag (string source, string tag, bool simple = false)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36 return source.containsXmlTag(tag, null, null, simple);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39 bool containsXmlTag (string source, string tag, string attributes, bool simple = false)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 return source.containsXmlTag(tag, attributes, null, simple);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44 bool containsXmlTag (string source, string tag, string attributes, string content, bool simple = false)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 string pattern = '<' ~ tag;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48 if (attributes.length > 0)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 pattern ~= ' ' ~ attributes;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
51 if (simple)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
52 return source.contains(pattern ~ "/>");
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
53
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 if (content.length > 0)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55 return source.contains(pattern ~ '>' ~ content ~ "</" ~ tag ~ '>');
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 return source.contains(pattern ~ '>') && source.contains("</" ~ tag ~ '>');
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58 }