blob: 01cbf891ab50971e36e8908841b9e451f8a8d4be [file] [log] [blame]
Feng Xiaoe841bac2015-12-11 17:09:20 -08001// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc. All rights reserved.
3// https://developers.google.com/protocol-buffers/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following disclaimer
13// in the documentation and/or other materials provided with the
14// distribution.
15// * Neither the name of Google Inc. nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31goog.setTestOnly();
32
33goog.require('goog.testing.asserts');
Josh Habermane9f31ee2016-02-04 10:29:27 -080034
35// CommonJS-LoadFromFile: google-protobuf
Feng Xiaoe841bac2015-12-11 17:09:20 -080036goog.require('jspb.debug');
Josh Habermane9f31ee2016-02-04 10:29:27 -080037
38// CommonJS-LoadFromFile: test_pb
Feng Xiaoe841bac2015-12-11 17:09:20 -080039goog.require('proto.jspb.test.HasExtensions');
40goog.require('proto.jspb.test.IsExtension');
41goog.require('proto.jspb.test.Simple1');
42
43
Jisi Liu3b3c8ab2016-03-30 11:39:59 -070044
Feng Xiaoe841bac2015-12-11 17:09:20 -080045describe('debugTest', function() {
46 it('testSimple1', function() {
47 if (COMPILED) {
48 return;
49 }
50 var message = new proto.jspb.test.Simple1();
51 message.setAString('foo');
52 assertObjectEquals({
53 $name: 'proto.jspb.test.Simple1',
54 'aString': 'foo',
55 'aRepeatedStringList': []
56 }, jspb.debug.dump(message));
57
58 message.setABoolean(true);
59 message.setARepeatedStringList(['1', '2']);
60
61 assertObjectEquals({
62 $name: 'proto.jspb.test.Simple1',
63 'aString': 'foo',
64 'aRepeatedStringList': ['1', '2'],
65 'aBoolean': true
66 }, jspb.debug.dump(message));
67
68 message.setAString(undefined);
69
70 assertObjectEquals({
71 $name: 'proto.jspb.test.Simple1',
72 'aRepeatedStringList': ['1', '2'],
73 'aBoolean': true
74 }, jspb.debug.dump(message));
75 });
76
77
78 it('testExtensions', function() {
79 if (COMPILED) {
80 return;
81 }
82 var extension = new proto.jspb.test.IsExtension();
83 extension.setExt1('ext1field');
84 var extendable = new proto.jspb.test.HasExtensions();
85 extendable.setStr1('v1');
86 extendable.setStr2('v2');
87 extendable.setStr3('v3');
88 extendable.setExtension(proto.jspb.test.IsExtension.extField, extension);
89
90 assertObjectEquals({
91 '$name': 'proto.jspb.test.HasExtensions',
92 'str1': 'v1',
93 'str2': 'v2',
94 'str3': 'v3',
95 '$extensions': {
96 'extField': {
97 '$name': 'proto.jspb.test.IsExtension',
98 'ext1': 'ext1field'
99 },
100 'repeatedSimpleList': []
101 }
102 }, jspb.debug.dump(extendable));
103 });
104
105});