-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper for Markdown inline code escaping
The helper adds escaping to a string so that it can be embedded in a Markdown inline code segment delimited by backticks. Closes #18867. PiperOrigin-RevId: 547527057 Change-Id: Ie37d076c46f82ddd04e31c33c0f695109c5d29f5
- Loading branch information
1 parent
928d924
commit 3d26048
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
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
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
24 changes: 24 additions & 0 deletions
24
src/test/java/com/google/devtools/build/skydoc/rendering/BUILD
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,24 @@ | ||
load("@rules_java//java:defs.bzl", "java_test") | ||
|
||
package( | ||
default_applicable_licenses = ["//:license"], | ||
default_visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
filegroup( | ||
name = "srcs", | ||
testonly = 0, | ||
srcs = glob(["*"]), | ||
visibility = ["//src:__subpackages__"], | ||
) | ||
|
||
java_test( | ||
name = "MarkdownUtilTest", | ||
size = "small", | ||
srcs = ["MarkdownUtilTest.java"], | ||
deps = [ | ||
"//src/main/java/com/google/devtools/build/skydoc/rendering", | ||
"//third_party:junit4", | ||
"//third_party:truth", | ||
], | ||
) |
50 changes: 50 additions & 0 deletions
50
src/test/java/com/google/devtools/build/skydoc/rendering/MarkdownUtilTest.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,50 @@ | ||
// Copyright 2023 The Bazel Authors. All rights reserved. | ||
// | ||
// 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 | ||
// | ||
// http://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.devtools.build.skydoc.rendering; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** Tests for MarkdownUtil. */ | ||
@RunWith(JUnit4.class) | ||
public class MarkdownUtilTest { | ||
|
||
MarkdownUtil util = new MarkdownUtil(); | ||
|
||
@Test | ||
public void markdownCodeSpan() { | ||
assertThat(MarkdownUtil.markdownCodeSpan("")).isEqualTo("``"); | ||
assertThat(MarkdownUtil.markdownCodeSpan("foo bar ")).isEqualTo("`foo bar `"); | ||
} | ||
|
||
@Test | ||
public void markdownCodeSpan_backticks() { | ||
assertThat(MarkdownUtil.markdownCodeSpan("foo`bar")).isEqualTo("``foo`bar``"); | ||
assertThat(MarkdownUtil.markdownCodeSpan("foo``bar")).isEqualTo("```foo``bar```"); | ||
assertThat(MarkdownUtil.markdownCodeSpan("foo`bar```baz``quz")) | ||
.isEqualTo("````foo`bar```baz``quz````"); | ||
} | ||
|
||
@Test | ||
public void markdownCodeSpan_backticksPadding() { | ||
assertThat(MarkdownUtil.markdownCodeSpan("`foo")).isEqualTo("`` `foo ``"); | ||
assertThat(MarkdownUtil.markdownCodeSpan("``foo")).isEqualTo("``` ``foo ```"); | ||
assertThat(MarkdownUtil.markdownCodeSpan("foo`")).isEqualTo("`` foo` ``"); | ||
assertThat(MarkdownUtil.markdownCodeSpan("foo``")).isEqualTo("``` foo`` ```"); | ||
} | ||
} |