UNPKG

sku-pg

Version:

Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!

118 lines (104 loc) 4.23 kB
<!DOCTYPE html> <html> <!-- Copyright 2012 The Closure Library Authors. All Rights Reserved. Use of this source code is governed by the Apache License, Version 2.0. See the COPYING file for details. --> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Closure Unit Tests - goog.testing.proto2</title> <script src="../../base.js"></script> <script> goog.require('goog.testing.jsunit'); goog.require('goog.testing.proto2'); goog.require('proto2.TestAllTypes'); </script> </head> <body> <script> function testAssertEquals() { var assertProto2Equals = goog.testing.proto2.assertEquals; assertProto2Equals(new proto2.TestAllTypes, new proto2.TestAllTypes); assertProto2Equals(new proto2.TestAllTypes, new proto2.TestAllTypes, 'oops'); var ex = assertThrows(goog.partial(assertProto2Equals, new proto2.TestAllTypes, new proto2.TestAllTypes.NestedMessage)); assertEquals( 'Message type mismatch: TestAllTypes != TestAllTypes.NestedMessage', ex.message); var message = new proto2.TestAllTypes; message.setOptionalInt32(1); ex = assertThrows(goog.partial(assertProto2Equals, new proto2.TestAllTypes, message)); assertEquals('optional_int32 should not be present', ex.message); ex = assertThrows(goog.partial(assertProto2Equals, new proto2.TestAllTypes, message, 'oops')); assertEquals('oops\noptional_int32 should not be present', ex.message); } function testFindDifferences_EmptyMessages() { assertEquals('', goog.testing.proto2.findDifferences_( new proto2.TestAllTypes, new proto2.TestAllTypes, '')); } function testFindDifferences_FieldNotPresent() { var message = new proto2.TestAllTypes; message.setOptionalInt32(0); var empty = new proto2.TestAllTypes; assertEquals('optional_int32 should not be present', goog.testing.proto2.findDifferences_(empty, message, '')); assertEquals('optional_int32 should be present', goog.testing.proto2.findDifferences_(message, empty, '')); assertEquals('path/optional_int32 should be present', goog.testing.proto2.findDifferences_(message, empty, 'path')); } function testFindDifferences_IntFieldDiffers() { var message1 = new proto2.TestAllTypes; message1.setOptionalInt32(1); var message2 = new proto2.TestAllTypes; message2.setOptionalInt32(2); assertEquals('optional_int32 should be 1, but was 2', goog.testing.proto2.findDifferences_(message1, message2, '')); } function testFindDifferences_NestedIntFieldDiffers() { var message1 = new proto2.TestAllTypes; var nested1 = new proto2.TestAllTypes.NestedMessage(); nested1.setB(1); message1.setOptionalNestedMessage(nested1); var message2 = new proto2.TestAllTypes; var nested2 = new proto2.TestAllTypes.NestedMessage(); nested2.setB(2); message2.setOptionalNestedMessage(nested2); assertEquals('optional_nested_message/b should be 1, but was 2', goog.testing.proto2.findDifferences_(message1, message2, '')); } function testFindDifferences_RepeatedFieldLengthDiffers() { var message1 = new proto2.TestAllTypes; message1.addRepeatedInt32(1); var message2 = new proto2.TestAllTypes; message2.addRepeatedInt32(1); message2.addRepeatedInt32(2); assertEquals('repeated_int32 should have 1 items, but has 2', goog.testing.proto2.findDifferences_(message1, message2, '')); } function testFindDifferences_RepeatedFieldItemDiffers() { var message1 = new proto2.TestAllTypes; message1.addRepeatedInt32(1); var message2 = new proto2.TestAllTypes; message2.addRepeatedInt32(2); assertEquals('repeated_int32[0] should be 1, but was 2', goog.testing.proto2.findDifferences_(message1, message2, '')); } function testFindDifferences_RepeatedNestedMessageDiffers() { var message1 = new proto2.TestAllTypes; var nested1 = new proto2.TestAllTypes.NestedMessage(); nested1.setB(1); message1.addRepeatedNestedMessage(nested1); var message2 = new proto2.TestAllTypes; var nested2 = new proto2.TestAllTypes.NestedMessage(); nested2.setB(2); message2.addRepeatedNestedMessage(nested2); assertEquals('repeated_nested_message[0]/b should be 1, but was 2', goog.testing.proto2.findDifferences_(message1, message2, '')); } </script> </body> </html>