1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.build
18 
19 import androidx.build.docs.rewriteLinks
20 import junit.framework.TestCase.assertEquals
21 import org.junit.Test
22 
23 class MarkdownLinkRewriterTest {
24 
25     @Test
testStandardLinknull26     fun testStandardLink() {
27         val input = "[Progress Indicator doc](https://developer.android.com/progress)"
28         val expected = "[Progress Indicator doc](https://developer.android.com/progress)"
29         assertEquals(expected, rewriteLinks(input))
30     }
31 
32     @Test
testImageLinknull33     fun testImageLink() {
34         val input = "![Progress Image](https://developer.android.com/image.png)"
35         val expected = "![Progress Image](https://developer.android.com/image.png)"
36         assertEquals(expected, rewriteLinks(input))
37     }
38 
39     @Test
testMultiLineLinknull40     fun testMultiLineLink() {
41         val input = """
42             [Progress
43             Indicator doc](https://developer.android.com/progress)
44         """.trimIndent()
45         val expected = "[Progress Indicator doc](https://developer.android.com/progress)"
46         assertEquals(expected, rewriteLinks(input))
47     }
48 
49     @Test
testMultiLineImageLinknull50     fun testMultiLineImageLink() {
51         val input = """
52             ![Progress
53             *
54 
55             Image](https://developer.android.com/image.png)
56         """.trimIndent()
57         val expected = "![Progress Image](https://developer.android.com/image.png)"
58         assertEquals(expected, rewriteLinks(input))
59     }
60 
61     @Test
testNonLinkWithOnlyBracketsnull62     fun testNonLinkWithOnlyBrackets() {
63         val input = "[Progress Indicator doc]"
64         val expected = "[Progress Indicator doc]"
65         assertEquals(expected, rewriteLinks(input))
66     }
67 
68     @Test
testNonLinkWithBracketsAndParenthesesSeparatelynull69     fun testNonLinkWithBracketsAndParenthesesSeparately() {
70         val input = "[Progress Indicator doc] (https://developer.android.com/progress)"
71         val expected = "[Progress Indicator doc] (https://developer.android.com/progress)"
72         assertEquals(expected, rewriteLinks(input))
73     }
74 
75     @Test
testNonLinkWithOnlyParenthesesnull76     fun testNonLinkWithOnlyParentheses() {
77         val input = "(https://developer.android.com/progress)"
78         val expected = "(https://developer.android.com/progress)"
79         assertEquals(expected, rewriteLinks(input))
80     }
81 
82     @Test
testMultipleLinksWithMixedContentnull83     fun testMultipleLinksWithMixedContent() {
84         val input = """
85             Here is a regular link: [Progress doc](https://developer.android.com/progress).
86             And here is an image link: ![Image](https://developer.android.com/image.png).
87             But this should not change: [Android doc]
88             And neither should this: [https://developer.android.com]
89         """.trimIndent()
90 
91         val expected = """
92             Here is a regular link: [Progress doc](https://developer.android.com/progress).
93             And here is an image link: ![Image](https://developer.android.com/image.png).
94             But this should not change: [Android doc]
95             And neither should this: [https://developer.android.com]
96         """.trimIndent()
97 
98         assertEquals(expected, rewriteLinks(input))
99     }
100 }
101