blob: d7bf3768fb837f0c6a504100a563541ee8f9198c [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
Feng Xiaoe841bac2015-12-11 17:09:20 -080044describe('debugTest', function() {
45 it('testSimple1', function() {
46 if (COMPILED) {
47 return;
48 }
49 var message = new proto.jspb.test.Simple1();
50 message.setAString('foo');
51 assertObjectEquals({
52 $name: 'proto.jspb.test.Simple1',
53 'aString': 'foo',
54 'aRepeatedStringList': []
55 }, jspb.debug.dump(message));
56
57 message.setABoolean(true);
58 message.setARepeatedStringList(['1', '2']);
59
60 assertObjectEquals({
61 $name: 'proto.jspb.test.Simple1',
62 'aString': 'foo',
63 'aRepeatedStringList': ['1', '2'],
64 'aBoolean': true
65 }, jspb.debug.dump(message));
66
67 message.setAString(undefined);
68
69 assertObjectEquals({
70 $name: 'proto.jspb.test.Simple1',
71 'aRepeatedStringList': ['1', '2'],
72 'aBoolean': true
73 }, jspb.debug.dump(message));
74 });
75
76
77 it('testExtensions', function() {
78 if (COMPILED) {
79 return;
80 }
81 var extension = new proto.jspb.test.IsExtension();
82 extension.setExt1('ext1field');
83 var extendable = new proto.jspb.test.HasExtensions();
84 extendable.setStr1('v1');
85 extendable.setStr2('v2');
86 extendable.setStr3('v3');
87 extendable.setExtension(proto.jspb.test.IsExtension.extField, extension);
88
89 assertObjectEquals({
90 '$name': 'proto.jspb.test.HasExtensions',
91 'str1': 'v1',
92 'str2': 'v2',
93 'str3': 'v3',
94 '$extensions': {
95 'extField': {
96 '$name': 'proto.jspb.test.IsExtension',
97 'ext1': 'ext1field'
98 },
99 'repeatedSimpleList': []
100 }
101 }, jspb.debug.dump(extendable));
102 });
103
104});