OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package formatter | 5 package formatter |
6 | 6 |
7 import ( | 7 import ( |
8 "mojom/mojom_parser/lexer" | 8 "mojom/mojom_parser/lexer" |
9 "mojom/mojom_parser/mojom" | 9 "mojom/mojom_parser/mojom" |
10 "testing" | 10 "testing" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 expected := `import "foo3.mojom"; | 134 expected := `import "foo3.mojom"; |
135 import "foo4.mojom"; | 135 import "foo4.mojom"; |
136 | 136 |
137 import "foo1.mojom"; | 137 import "foo1.mojom"; |
138 import "foo2.mojom"; | 138 import "foo2.mojom"; |
139 ` | 139 ` |
140 checkEq(t, expected, p.result()) | 140 checkEq(t, expected, p.result()) |
141 } | 141 } |
142 | 142 |
| 143 func TestWriteSingleLineComment(t *testing.T) { |
| 144 commentText := "// Hello world." |
| 145 token := lexer.Token{Kind: lexer.SingleLineComment, Text: commentText} |
| 146 p := getNewPrinter() |
| 147 p.writeSingleLineComment(token) |
| 148 checkEq(t, commentText, p.result()) |
| 149 } |
| 150 |
| 151 func TestWriteSingleLineCommentAddSpace(t *testing.T) { |
| 152 commentText := "//Hello world." |
| 153 token := lexer.Token{Kind: lexer.SingleLineComment, Text: commentText} |
| 154 p := getNewPrinter() |
| 155 p.writeSingleLineComment(token) |
| 156 checkEq(t, "// Hello world.", p.result()) |
| 157 } |
| 158 |
143 func TestWriteMultilineComments(t *testing.T) { | 159 func TestWriteMultilineComments(t *testing.T) { |
144 commentText := `/* | 160 commentText := `/* |
145 * Some comment. | 161 * Some comment. |
146 * More comments. | 162 * More comments. |
147 * Even more comments. | 163 * Even more comments. |
148 | 164 |
149 * And after a space. | 165 * And after a space. |
150 */` | 166 */` |
151 token := lexer.Token{Kind: lexer.MultiLineComment, Text: commentText} | 167 token := lexer.Token{Kind: lexer.MultiLineComment, Text: commentText} |
152 p := getNewPrinter() | 168 p := getNewPrinter() |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 responseParams.InitAsScope(mojom.NewTestFileScope("test.scope")) | 430 responseParams.InitAsScope(mojom.NewTestFileScope("test.scope")) |
415 responseParams.AddField(mojom.NewStructField(mojom.DeclTestData("rparam1
"), mojom.SimpleTypeInt32, nil)) | 431 responseParams.AddField(mojom.NewStructField(mojom.DeclTestData("rparam1
"), mojom.SimpleTypeInt32, nil)) |
416 responseParams.AddField(mojom.NewStructField(mojom.DeclTestData("rparam2
"), mojom.SimpleTypeInt64, nil)) | 432 responseParams.AddField(mojom.NewStructField(mojom.DeclTestData("rparam2
"), mojom.SimpleTypeInt64, nil)) |
417 | 433 |
418 mojomMethod := mojom.NewMojomMethod(mojom.DeclTestData("method_foo"), pa
rams, responseParams) | 434 mojomMethod := mojom.NewMojomMethod(mojom.DeclTestData("method_foo"), pa
rams, responseParams) |
419 | 435 |
420 p := getNewPrinter() | 436 p := getNewPrinter() |
421 p.writeDeclaredObject(mojomMethod) | 437 p.writeDeclaredObject(mojomMethod) |
422 checkEq(t, "method_foo(int8 param1, int16 param2) => (int32 rparam1, int
64 rparam2);", p.result()) | 438 checkEq(t, "method_foo(int8 param1, int16 param2) => (int32 rparam1, int
64 rparam2);", p.result()) |
423 } | 439 } |
OLD | NEW |