|
| 1 | +package com.baeldung.scala.strings.capitalize |
| 2 | + |
| 3 | +import org.scalatest.flatspec.AnyFlatSpec |
| 4 | +import org.scalatest.matchers.should.Matchers |
| 5 | +import org.scalatest.prop.TableDrivenPropertyChecks |
| 6 | + |
| 7 | +class CapitalizeWordsUnitTest |
| 8 | + extends AnyFlatSpec |
| 9 | + with Matchers |
| 10 | + with TableDrivenPropertyChecks { |
| 11 | + |
| 12 | + val table = Table( |
| 13 | + ("Input", "Expected"), |
| 14 | + ("This is scala 3", "This Is Scala 3"), |
| 15 | + ("hello world", "Hello World"), |
| 16 | + ("baeldung articles", "Baeldung Articles"), |
| 17 | + (" ", ""), |
| 18 | + ("1000", "1000") |
| 19 | + ) |
| 20 | + it should "capitalize every words of a sentence" in { |
| 21 | + forAll(table) { (input, expected) => |
| 22 | + CapitalizeWords.capitalizeWords(input) shouldBe expected |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + val tableWithExclusions = Table( |
| 27 | + ("Input", "Expected"), |
| 28 | + ("This is scala 3", "This is Scala 3"), |
| 29 | + ("baeldung articles", "Baeldung Articles"), |
| 30 | + (" ", ""), |
| 31 | + ( |
| 32 | + "the quick brown fox jumps over the lazy Dog", |
| 33 | + "The Quick Brown Fox Jumps Over the Lazy Dog" |
| 34 | + ) |
| 35 | + ) |
| 36 | + it should "capitalize every word of a sentence with exclusion" in { |
| 37 | + forAll(tableWithExclusions) { (input, expected) => |
| 38 | + CapitalizeWords.capitalizeTitleCase(input) shouldBe expected |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + val tablePreservingSpace = Table( |
| 43 | + ("Input", "Expected"), |
| 44 | + ("This is scala 3", "This Is Scala 3"), |
| 45 | + ("hello world", "Hello World"), |
| 46 | + ("baeldung articles", "Baeldung Articles"), |
| 47 | + (" ", " "), |
| 48 | + ("1000", "1000") |
| 49 | + ) |
| 50 | + it should "capitalize every words of a sentence preserving the spaces" in { |
| 51 | + forAll(tablePreservingSpace) { (input, expected) => |
| 52 | + CapitalizeWords.capitalizeWordsPreserveSpaces(input) shouldBe expected |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments