This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for GoCommentReformatter (#2559)
Add test for GoCommentReformatter. Updates #722
- Loading branch information
Showing
1 changed file
with
163 additions
and
0 deletions.
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
src/test/java/com/google/api/codegen/util/go/GoCommentReformatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.api.codegen.util.go; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
public class GoCommentReformatterTest { | ||
|
||
@Test | ||
public void testBulletList() throws Exception { | ||
String comment = | ||
new StringBuilder() | ||
.append("A list of items:") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append("* List item 1") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append("* List item 2") | ||
.append(System.lineSeparator()) | ||
.append(" * which has a nested item") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append("* List item 3") | ||
.append(System.lineSeparator()) | ||
.append(" which continues on a second line") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append("End list.") | ||
.toString(); | ||
|
||
String formatted = new GoCommentReformatter().reformat(comment); | ||
|
||
String expectedComment = | ||
new StringBuilder() | ||
.append("A list of items: ") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append(" List item 1") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append(" List item 2 ") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append(" which has a nested item") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append(" List item 3") | ||
.append(System.lineSeparator()) | ||
.append(" which continues on a second line") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append("End list.") | ||
.toString(); | ||
assertThat(formatted).isEqualTo(expectedComment); | ||
} | ||
|
||
@Test | ||
public void testCode() throws Exception { | ||
String comment = "Some `inline code` here."; | ||
|
||
String formatted = new GoCommentReformatter().reformat(comment); | ||
|
||
String expectedComment = "Some inline code here."; | ||
assertThat(formatted).isEqualTo(expectedComment); | ||
} | ||
|
||
@Test | ||
public void testEmphasis() throws Exception { | ||
String comment = "An *emphasized* statement."; | ||
|
||
String formatted = new GoCommentReformatter().reformat(comment); | ||
|
||
String expectedComment = "An emphasized statement."; | ||
assertThat(formatted).isEqualTo(expectedComment); | ||
} | ||
|
||
@Test | ||
public void testHtmlInline() throws Exception { | ||
String comment = "Some <span>inline html</span> here."; | ||
|
||
String formatted = new GoCommentReformatter().reformat(comment); | ||
|
||
String expectedComment = "Some <span>inline html</span> here."; | ||
assertThat(formatted).isEqualTo(expectedComment); | ||
} | ||
|
||
@Test | ||
public void testHtmlBlock() throws Exception { | ||
String comment = | ||
new StringBuilder() | ||
.append("A block of html: ") | ||
.append(System.lineSeparator()) | ||
.append("<p>") | ||
.append(System.lineSeparator()) | ||
.append("A paragraph here.") | ||
.append(System.lineSeparator()) | ||
.append("</p>") | ||
.append(System.lineSeparator()) | ||
.append("End html block.") | ||
.toString(); | ||
|
||
String formatted = new GoCommentReformatter().reformat(comment); | ||
|
||
String expectedComment = | ||
new StringBuilder() | ||
.append("A block of html:<p>") | ||
.append(System.lineSeparator()) | ||
.append("A paragraph here.") | ||
.append(System.lineSeparator()) | ||
.append("</p>") | ||
.append(System.lineSeparator()) | ||
.append("End html block.") | ||
.toString(); | ||
assertThat(formatted).isEqualTo(expectedComment); | ||
} | ||
|
||
@Test | ||
public void testParagraph() throws Exception { | ||
String comment = | ||
new StringBuilder() | ||
.append("A paragraph.") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append("A second paragraph.") | ||
.toString(); | ||
|
||
String formatted = new GoCommentReformatter().reformat(comment); | ||
|
||
String expectedComment = | ||
new StringBuilder() | ||
.append("A paragraph.") | ||
.append(System.lineSeparator()) | ||
.append(System.lineSeparator()) | ||
.append("A second paragraph.") | ||
.toString(); | ||
assertThat(formatted).isEqualTo(expectedComment); | ||
} | ||
|
||
@Test | ||
public void testLink() throws Exception { | ||
String comment = "Some [linked text](https://cloud.google.com) here."; | ||
|
||
String formatted = new GoCommentReformatter().reformat(comment); | ||
|
||
String expectedComment = "Some linked text (at https://cloud.google.com) here."; | ||
assertThat(formatted).isEqualTo(expectedComment); | ||
} | ||
} |