| 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 "strings" | 8 "strings" |
| 9 "testing" | 9 "testing" |
| 10 ) | 10 ) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 import "afoo2.mojom"; | 27 import "afoo2.mojom"; |
| 28 | 28 |
| 29 [Attr1=1, | 29 [Attr1=1, |
| 30 Attr2=2] | 30 Attr2=2] |
| 31 struct FooStruct { // FooStruct comment. | 31 struct FooStruct { // FooStruct comment. |
| 32 // Field 1 comment. | 32 // Field 1 comment. |
| 33 int8 field1; // Field 1 comment. | 33 int8 field1; // Field 1 comment. |
| 34 int16 field2 = 10; | 34 int16 field2 = 10; |
| 35 // Field3 comment. | 35 // Field3 comment. |
| 36 // Field3 other comment. | 36 // Field3 other comment. |
| 37 int32 field3@10 = 10; | 37 int32 field3@2 = 10; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 struct FooUnion { | 40 struct FooUnion { |
| 41 [Attr1=1] int8 field1; | 41 [Attr1=1] int8 field1; |
| 42 » int16 field2@5; | 42 » int16 field2@1; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 enum FooEnum { | 45 enum FooEnum { |
| 46 VALUE1, // VALUE1 comment. | 46 VALUE1, // VALUE1 comment. |
| 47 VALUE2 = 10, // VALUE2 comment. | 47 VALUE2 = 10, // VALUE2 comment. |
| 48 | 48 |
| 49 // FooEnum Final Comment. | 49 // FooEnum Final Comment. |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // no-format | 52 // no-format |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 const int8 foo_constant2 = -10; // constant comment. | 63 const int8 foo_constant2 = -10; // constant comment. |
| 64 const float foo_constant3 = -10e10; // constant comment. | 64 const float foo_constant3 = -10e10; // constant comment. |
| 65 const int64 foo_constant4 = 0xAD10; // constant comment. | 65 const int64 foo_constant4 = 0xAD10; // constant comment. |
| 66 const int64 foo_constant5 = -0xAD10; // constant comment. | 66 const int64 foo_constant5 = -0xAD10; // constant comment. |
| 67 | 67 |
| 68 // Interface Comment. | 68 // Interface Comment. |
| 69 interface InterfaceFoo { // Interface comment. | 69 interface InterfaceFoo { // Interface comment. |
| 70 const int8 const_in_interface = 20; | 70 const int8 const_in_interface = 20; |
| 71 | 71 |
| 72 // Method 1 comment. | 72 // Method 1 comment. |
| 73 method1@5(int8 hello@10); | 73 method1@5(int8 hello@0); |
| 74 // Method 2 comment. | 74 // Method 2 comment. |
| 75 » method2([MinVersion=5] int8 hello) => (Foo bar@20); | 75 » method2([MinVersion=5] int8 hello) => (Foo bar@0); |
| 76 method3(); | 76 method3(); |
| 77 method4() => (Foo bar); | 77 method4() => (Foo bar); |
| 78 method5(int8 p1 /* p1 comment */, int16 p2); // method comment | 78 method5(int8 p1 /* p1 comment */, int16 p2); // method comment |
| 79 method6(WayTooLongAndReallyLongFactoryVisitoryFactory field1, | 79 method6(WayTooLongAndReallyLongFactoryVisitoryFactory field1, |
| 80 WayTooLongAndReallyLongFactoryVisitoryFactory field2) | 80 WayTooLongAndReallyLongFactoryVisitoryFactory field2) |
| 81 => (int8 alpha); | 81 => (int8 alpha); |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 // Final Comments. | 84 // Final Comments. |
| 85 ` | 85 ` |
| 86 | 86 |
| 87 // TODO(azani): Remove this and just fix the tabs. | 87 // TODO(azani): Remove this and just fix the tabs. |
| 88 original = strings.Replace(original, "\t", " ", -1) | 88 original = strings.Replace(original, "\t", " ", -1) |
| 89 original = strings.Replace(original, "\t//", " //", -1) | 89 original = strings.Replace(original, "\t//", " //", -1) |
| 90 | 90 |
| 91 actual, err := FormatMojom("test.mojom", original) | 91 actual, err := FormatMojom("test.mojom", original) |
| 92 if err != nil { | 92 if err != nil { |
| 93 t.Fatalf("Parser was not supposed to fail: %s", err.Error()) | 93 t.Fatalf("Parser was not supposed to fail: %s", err.Error()) |
| 94 } | 94 } |
| 95 | 95 |
| 96 if original != actual { | 96 if original != actual { |
| 97 t.Fatalf("\nExpected:\n%v\n\n*****\n\nActual:\n%v eof", original
, actual) | 97 t.Fatalf("\nExpected:\n%v\n\n*****\n\nActual:\n%v eof", original
, actual) |
| 98 } | 98 } |
| 99 } | 99 } |
| OLD | NEW |