xref: /aosp_15_r20/tools/trebuchet/core/common/src/test/kotlin/trebuchet/io/StringStreamTest.kt (revision 56b170dbe6574b1f0ec9db7a63de7238ca6a09ea)
1 /*
2  * Copyright 2017 Google Inc.
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 trebuchet.io
18 
19 import org.junit.Assert
20 import org.junit.Assert.assertEquals
21 import org.junit.Test
22 import trebuchet.extras.findSampleData
23 import trebuchet.importers.DummyImportFeedback
24 import trebuchet.model.Model
25 import trebuchet.task.ImportTask
26 import trebuchet.testutils.makeReader
27 import java.io.BufferedReader
28 import java.io.File
29 import java.io.FileReader
30 import kotlin.test.assertNull
31 
32 class StringStreamTest {
testLineReadernull33     @Test fun testLineReader() {
34         expect1_20_300("1\n20\n300")
35     }
36 
testLineReaderCLRFnull37     @Test fun testLineReaderCLRF() {
38         expect1_20_300("1\r\n20\r\n300")
39     }
40 
testLineReaderEmptyLinesnull41     @Test fun testLineReaderEmptyLines() {
42         expect1_20_300("\n\n1\r\n\r\n20\n\n\n\n300\n\n\n")
43 
44     }
45 
expect1_20_300null46     private fun expect1_20_300(data: String) {
47         val lines = mutableListOf<String>()
48         data.makeReader().iterLines().forEach {
49             lines.add(it.toString())
50         }
51         assertEquals(3, lines.size)
52         assertEquals("1", lines[0])
53         assertEquals("20", lines[1])
54         assertEquals("300", lines[2])
55     }
56 }