Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!-- | |
| 2 Copyright 2016 The Chromium Authors. All rights reserved. | |
| 3 Use of this source code is governed by a BSD-style license that can be | |
| 4 found in the LICENSE file. | |
| 5 --> | |
| 6 | |
| 7 <!doctype html> | |
| 8 <title>rpc-descriptor-util</title> | |
|
Bons
2016/02/23 15:52:29
title doesn't match test
nodir
2016/02/23 18:32:26
Done.
| |
| 9 | |
| 10 <script src="../../bower_components/web-component-tester/browser.js"></script> | |
| 11 <link rel="import" href="../rpc-completer.html"> | |
| 12 <link rel="import" href="descriptor.html"> | |
| 13 | |
| 14 <test-fixture id="completer"> | |
| 15 <template> | |
| 16 <rpc-completer></rpc-completer> | |
| 17 </template> | |
| 18 </test-fixture> | |
| 19 <script> | |
| 20 'use strict'; | |
| 21 | |
| 22 suite('<rpc-completer>', function() { | |
| 23 var completer; | |
| 24 | |
| 25 setup(function() { | |
| 26 completer = fixture('completer'); | |
| 27 completer.description = JSON.parse(JSON.stringify(discoveryDescriptor)); | |
| 28 rpcExplorer.descUtil.annotateSet(completer.description); | |
| 29 }); | |
| 30 | |
| 31 suite('findMatching', function() { | |
| 32 function testFindMatching(text, i, expected) { | |
| 33 test(text + ' @ ' + i + ' = ' + expected, function() { | |
| 34 var result = completer.findMatching(text, i); | |
| 35 expect(result).to.equal(expected); | |
| 36 }); | |
| 37 } | |
| 38 testFindMatching('{}', 0, 1); | |
| 39 testFindMatching('{{}}', 0, 3); | |
| 40 testFindMatching('{{}}', 1, 2); | |
| 41 testFindMatching('{[]}', 0, 3); | |
| 42 testFindMatching('{[]}', 1, 2); | |
| 43 testFindMatching('{aa[bb]ccc}', 0, 10); | |
| 44 testFindMatching('{aa[bb]ccc}', 3, 6); | |
| 45 }); | |
| 46 | |
| 47 suite('getCurrentPath', function() { | |
| 48 function testCurrentPath(text, expected) { | |
| 49 test('`' + text + '`', function() { | |
| 50 var path = completer.getCurrentPath(text); | |
| 51 expect(path.join('')).to.deep.equal(expected); | |
| 52 }); | |
| 53 } | |
| 54 | |
| 55 testCurrentPath('', ''); | |
| 56 | |
| 57 testCurrentPath( | |
| 58 '{ "a": ', | |
| 59 'a'); | |
| 60 testCurrentPath( | |
| 61 '{ "a": "', | |
| 62 'a'); | |
| 63 testCurrentPath( | |
| 64 '{ "a": {', | |
| 65 'a'); | |
| 66 | |
| 67 testCurrentPath( | |
| 68 '{ "a": { "b": [', | |
| 69 'ab'); | |
| 70 testCurrentPath( | |
| 71 '{ "a": {}, "b": {', | |
| 72 'b'); | |
| 73 testCurrentPath( | |
| 74 '{ "a": [], "b": {', | |
| 75 'b'); | |
| 76 testCurrentPath( | |
| 77 '{ "a": { "b": ', | |
| 78 'ab'); | |
| 79 testCurrentPath( | |
| 80 '{ "a": { "b": "', | |
| 81 'ab'); | |
| 82 }); | |
| 83 | |
| 84 suite('getCompletionsForText', function() { | |
| 85 var fileSet = rpcExplorer.descUtil.resolve( | |
| 86 discoveryDescriptor, 'google.protobuf.FileDescriptorSet'); | |
| 87 | |
| 88 test('FileDescriptorSet', function() { | |
| 89 var completions = completer.getCompletionsForText(fileSet, '') | |
| 90 expect(completions).to.deep.equal([{ | |
| 91 caption: 'file', | |
| 92 snippet: '"file": [{${0}}]', | |
| 93 meta: 'repeated google.protobuf.FileDescriptorProto', | |
| 94 docTooltip: '' | |
| 95 }]); | |
| 96 }); | |
| 97 | |
| 98 test('FileDescriptorSet with quote', function() { | |
| 99 var completions = completer.getCompletionsForText(fileSet, '"') | |
| 100 expect(completions).to.deep.equal([{ | |
| 101 caption: 'file', | |
| 102 snippet: 'file', | |
| 103 meta: 'repeated google.protobuf.FileDescriptorProto', | |
| 104 docTooltip: '' | |
| 105 }]); | |
| 106 }); | |
| 107 | |
| 108 test('submessage', function() { | |
| 109 var completions = completer.getCompletionsForText(fileSet, '"file":[{'); | |
| 110 expect(completions).to.have.length(12); | |
| 111 expect(completions).to.contain({ | |
| 112 caption: 'name', | |
| 113 snippet: '"name": "${0}"', | |
| 114 meta: 'string', | |
| 115 docTooltip: '' | |
| 116 }); | |
| 117 expect(completions).to.contain({ | |
| 118 caption: 'dependency', | |
| 119 snippet: '"dependency": ["${0}"]', | |
| 120 meta: 'repeated string', | |
| 121 docTooltip: ' Names of files imported by this file.\n' | |
| 122 }); | |
| 123 expect(completions).to.contain({ | |
| 124 caption: 'weak_dependency', | |
| 125 snippet: '"weak_dependency": [${0}]', | |
| 126 meta: 'repeated int32', | |
| 127 docTooltip: ( | |
| 128 ' Indexes of the weak imported files in the dependency list.\n' + | |
| 129 ' For Google-internal migration only. Do not use.\n') | |
| 130 }); | |
| 131 }); | |
| 132 | |
| 133 test('enum values', function() { | |
| 134 // Completions for FieldOptions.CType. | |
| 135 var completions = completer.getCompletionsForText( | |
| 136 fileSet, | |
| 137 '"file":[{"message_type":{"field":{"options": {"ctype": '); | |
| 138 expect(completions).to.deep.equal([ | |
| 139 { | |
| 140 caption: 'STRING', | |
| 141 snippet: '"STRING"', | |
| 142 meta: '0', | |
| 143 docTooltip: ' Default mode.\n' | |
| 144 }, | |
| 145 { | |
| 146 caption: 'CORD', | |
| 147 snippet: '"CORD"', | |
| 148 meta: '1', | |
| 149 docTooltip: '' | |
| 150 }, | |
| 151 { | |
| 152 caption: 'STRING_PIECE', | |
| 153 snippet: '"STRING_PIECE"', | |
| 154 meta: '2', | |
| 155 docTooltip: '' | |
| 156 }, | |
| 157 ]); | |
| 158 }); | |
| 159 }); | |
| 160 }); | |
| 161 </script> | |
| OLD | NEW |