|
| 1 | +/* |
| 2 | + * Scala (https://www.scala-lang.org) |
| 3 | + * |
| 4 | + * Copyright EPFL and Lightbend, Inc. |
| 5 | + * |
| 6 | + * Licensed under Apache License 2.0 |
| 7 | + * (http://www.apache.org/licenses/LICENSE-2.0). |
| 8 | + * |
| 9 | + * See the NOTICE file distributed with this work for |
| 10 | + * additional information regarding copyright ownership. |
| 11 | + */ |
| 12 | + |
| 13 | +package scala.next |
| 14 | + |
| 15 | +import org.junit.Assert._ |
| 16 | +import org.junit.Test |
| 17 | + |
| 18 | +final class TestStringOpsExtensions { |
| 19 | + @Test |
| 20 | + def splitAsListEmpty(): Unit = { |
| 21 | + val str = "" |
| 22 | + |
| 23 | + assertTrue(str.splitAsList(',').isEmpty) |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + def splitAsListBlankString(): Unit = { |
| 28 | + val strings = List( |
| 29 | + " ", |
| 30 | + " ", |
| 31 | + "\t", |
| 32 | + "\t\t\t", |
| 33 | + "\n", |
| 34 | + "\n\n\n", |
| 35 | + " \t \t \n" |
| 36 | + ) |
| 37 | + |
| 38 | + strings.foreach { str => |
| 39 | + assertTrue(str.splitAsList(',').isEmpty) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + def splitAsListDelimiterNotFound(): Unit = { |
| 45 | + val str = "Hello World" |
| 46 | + val expected = List(str) |
| 47 | + |
| 48 | + assertEquals(expected, str.splitAsList(',')) |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + def splitAsListSingleDelimiter(): Unit = { |
| 53 | + val str = "Hello,World" |
| 54 | + val expected = List("Hello", "World") |
| 55 | + |
| 56 | + assertEquals(expected, str.splitAsList(',')) |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + def splitAsListMultipleDelimiters(): Unit = { |
| 61 | + val str = "Hello,World,Good,Bye,World" |
| 62 | + val expected = List("Hello", "World", "Good", "Bye", "World") |
| 63 | + |
| 64 | + assertEquals(expected, str.splitAsList(',')) |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + def splitAsListEmptySubStrings(): Unit = { |
| 69 | + val str = "Hello,,World," |
| 70 | + val expected = List("Hello", "World") |
| 71 | + |
| 72 | + assertEquals(expected, str.splitAsList(',')) |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + def splitAsListDelimiterAtTheEnd(): Unit = { |
| 77 | + val str = "Hello,World," |
| 78 | + val expected = List("Hello", "World") |
| 79 | + |
| 80 | + assertEquals(expected, str.splitAsList(',')) |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + def splitAsListDelimiterAtTheBeginning(): Unit = { |
| 85 | + val str = ",Hello,World" |
| 86 | + val expected = List("Hello", "World") |
| 87 | + |
| 88 | + assertEquals(expected, str.splitAsList(',')) |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + def splitAsListPreserveEmptySubStrings(): Unit = { |
| 93 | + val str = ",Hello,,World," |
| 94 | + val expected = List("", "Hello", "", "World", "") |
| 95 | + |
| 96 | + assertEquals(expected, str.splitAsList(separator = ',', preserveEmptySubStrings = true)) |
| 97 | + } |
| 98 | +} |
0 commit comments