1 /* 2 * Copyright 2018 Google LLC 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 * https://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 org.jetbrains.dokka.tests.utilities 18 19 import org.jetbrains.dokka.Utilities.firstSentence 20 import org.junit.Assert.assertEquals 21 import org.junit.Test 22 23 class StringExtensionsTest { 24 25 @Test firstSentence_emptyStringnull26 fun firstSentence_emptyString() { 27 assertEquals("", "".firstSentence()) 28 } 29 30 @Test incompleteSentencenull31 fun incompleteSentence() { 32 assertEquals("Hello there", "Hello there".firstSentence()) 33 } 34 35 @Test incompleteSentence_withParenthesisnull36 fun incompleteSentence_withParenthesis() { 37 assertEquals("Hello there (hi)", "Hello there (hi)".firstSentence()) 38 assertEquals("Hello there (hi.)", "Hello there (hi.)".firstSentence()) 39 } 40 41 @Test incompleteSentence_apiLevelnull42 fun incompleteSentence_apiLevel() { 43 assertEquals("API level 8 (Android 2.2, Froyo)", "API level 8 (Android 2.2, Froyo)".firstSentence()) 44 } 45 46 @Test unmatchedClosingParennull47 fun unmatchedClosingParen() { 48 assertEquals( 49 "A notation either declares, by name, the format of an unparsed entity (see \n", 50 "A notation either declares, by name, the format of an unparsed entity (see \n".firstSentence() 51 ) 52 } 53 54 @Test unmatchedClosingParen_withFullFirstSentencenull55 fun unmatchedClosingParen_withFullFirstSentence() { 56 assertEquals( 57 "This interface represents a notation declared in the DTD.", 58 ("This interface represents a notation declared in the DTD. A notation either declares, by name, " + 59 "the format of an unparsed entity (see \n").firstSentence() 60 ) 61 } 62 63 @Test firstSentence_singleSentencenull64 fun firstSentence_singleSentence() { 65 assertEquals("Hello there.", "Hello there.".firstSentence()) 66 } 67 68 @Test firstSentence_multipleSentencesnull69 fun firstSentence_multipleSentences() { 70 assertEquals("Hello there.", "Hello there. How are you?".firstSentence()) 71 } 72 73 @Test firstSentence_singleSentence_withParenthesisnull74 fun firstSentence_singleSentence_withParenthesis() { 75 assertEquals("API level 28 (Android Pie).", "API level 28 (Android Pie).".firstSentence()) 76 } 77 78 @Test firstSentence_multipleSentences_withParenthesisnull79 fun firstSentence_multipleSentences_withParenthesis() { 80 assertEquals( 81 "API level 28 (Android Pie).", 82 "API level 28 (Android Pie). API level 27 (Android Oreo)".firstSentence() 83 ) 84 } 85 86 @Test firstSentence_singleSentence_withPeriodInParenthesisnull87 fun firstSentence_singleSentence_withPeriodInParenthesis() { 88 assertEquals("API level 28 (Android 9.0 Pie).", "API level 28 (Android 9.0 Pie).".firstSentence()) 89 } 90 91 @Test firstSentence_multipleSentences_withPeriodInParenthesisnull92 fun firstSentence_multipleSentences_withPeriodInParenthesis() { 93 assertEquals( 94 "API level 28 (Android 9.0 Pie).", 95 "API level 28 (Android 9.0 Pie). API level 27 (Android 8.0 Oreo).".firstSentence() 96 ) 97 } 98 99 @Test parenthesisWithperiod_notFirstSentencenull100 fun parenthesisWithperiod_notFirstSentence() { 101 assertEquals("Foo bar.", "Foo bar. Baz (Wow)".firstSentence()) 102 assertEquals("Foo bar.", "Foo bar. Baz (Wow).".firstSentence()) 103 } 104 105 @Test periodInsideParenthesisnull106 fun periodInsideParenthesis() { 107 assertEquals( 108 "A ViewGroup is a special view that can contain other views (called children.) " + 109 "The view group is the base class for layouts and views containers.", 110 ("A ViewGroup is a special view that can contain other views (called children.) " + 111 "The view group is the base class for layouts and views containers. " + 112 "This class also defines the android.view.ViewGroup.LayoutParams class " + 113 "which serves as the base class for layouts parameters.").firstSentence() 114 ) 115 assertEquals("Foo (Foo.) bar.", "Foo (Foo.) bar. Baz.".firstSentence()) 116 assertEquals("Foo (Foo.) bar (bar.) baz.", "Foo (Foo.) bar (bar.) baz. Wow".firstSentence()) 117 assertEquals("Foo (Foo.) bar (bar.) baz (baz.) Wow", "Foo (Foo.) bar (bar.) baz (baz.) Wow".firstSentence()) 118 } 119 }