~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/tests/dump/tests/dump-tests.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('dump-tests', function(Y) {
2
 
 
3
 
    var Assert = Y.Assert,
4
 
        ObjectAssert = Y.ObjectAssert,
5
 
        deep = {
6
 
            one: {
7
 
                two: {
8
 
                    three: {
9
 
                        four: {
10
 
                            five: {
11
 
                                six: {
12
 
                                    seven: [1, 2, 3, 4, 5]
13
 
                                }
14
 
                            }
15
 
                        }
16
 
                    }
17
 
                }
18
 
            }
19
 
        };
20
 
 
21
 
    var suite = new Y.Test.Suite("Dump");
22
 
 
23
 
    suite.add(new Y.Test.Case({
24
 
        name: "Dump tests",
25
 
    
26
 
        test_dump: function() {
27
 
            Assert.areEqual("0", Y.Lang.dump(0));
28
 
            Assert.areEqual("null", Y.Lang.dump(null));
29
 
            Assert.areEqual("false", Y.Lang.dump(false));
30
 
            // Other types tested in substitute
31
 
        },
32
 
        'test: dump with a date': function() {
33
 
            var d = new Date();
34
 
            var control = '{date => ' + d.toString() + '}';
35
 
            var out = Y.Lang.dump({
36
 
                date: d
37
 
            });
38
 
            Assert.areSame(control, out, 'Failed to encode Date properly');
39
 
        },
40
 
        'test: HTMLElement': function() {
41
 
            var out = Y.Lang.dump({
42
 
                nodeType: 3,
43
 
                tagName: 'DIV',
44
 
                id: 'foo'
45
 
            });
46
 
            Assert.areEqual('DIV#foo', out, 'Failed to encode HTMLElement');
47
 
        },
48
 
        'test: HTMLDocument': function() {
49
 
            var out = Y.Lang.dump({
50
 
                location: {},
51
 
                body: {}
52
 
            });
53
 
            Assert.areEqual('document', out, 'Failed to encode HTMLDocument');
54
 
        },
55
 
        'test: HTMLWindow': function() {
56
 
            var out = Y.Lang.dump({
57
 
                document: {},
58
 
                navigator: {}
59
 
            });
60
 
            Assert.areEqual('window', out, 'Failed to encode HTMLWindow');
61
 
        },
62
 
        'test: function': function() {
63
 
            var out = Y.Lang.dump(function() {
64
 
            });
65
 
            Assert.areEqual('f(){...}', out, 'Failed to encode function');
66
 
        },
67
 
        'test: array': function() {
68
 
            var out = Y.Lang.dump([ 1, 2, 3, 4 ]);
69
 
            Assert.areEqual('[1, 2, 3, 4]', out, 'Failed to encode array');
70
 
        },
71
 
        'test: array with object': function() {
72
 
            var out = Y.Lang.dump([ 1, 2, 3, 4, {
73
 
                one: true, two: true
74
 
            }]);
75
 
            Assert.areEqual('[1, 2, 3, 4, {one => true, two => true}]', out, 'Failed to encode array with Object');
76
 
        },
77
 
        'test: array with regex': function() {
78
 
            var out = Y.Lang.dump([ 1, 2, 3, 4, /foo^bar/]);
79
 
            Assert.areEqual('[1, 2, 3, 4, /foo^bar/]', out, 'Failed to encode array with RegEx');
80
 
        },
81
 
        'test: default depth': function() {
82
 
            var out = Y.Lang.dump(deep);
83
 
            Assert.areEqual('{one => {two => {three => {four => {...}}}}}', out, 'Failed to truncate at 3');
84
 
        },
85
 
        'test: depth of 5': function() {
86
 
            var out = Y.Lang.dump(deep, 5);
87
 
            Assert.areEqual('{one => {two => {three => {four => {five => {six => {...}}}}}}}', out, 'Failed to truncate at 5');
88
 
        },
89
 
        'test: depth of 10': function() {
90
 
            var out = Y.Lang.dump(deep, 10);
91
 
            Assert.areEqual('{one => {two => {three => {four => {five => {six => {seven => [1, 2, 3, 4, 5]}}}}}}}', out, 'Failed to truncate at 5');
92
 
        }
93
 
    }));
94
 
 
95
 
    Y.Test.Runner.add(suite);
96
 
 
97
 
});