Skip to content

Commit

Permalink
Add toLowerCase to accept more unfortunate errors
Browse files Browse the repository at this point in the history
[Cherry-picked a9f4008]
  • Loading branch information
Lucas Leblanc authored and Kordyjan committed Nov 29, 2023
1 parent 1bb9137 commit 4f03d10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object SocialLinks:
val errorPrefix = s"Social links arg $s is invalid: "
val splitted = s.split("::")

splitted.head match {
splitted.head.toLowerCase match {
case "github" if splitted.size == 2 => Right(Github(splitted(1)))
case "github" => Left(errorPrefix + "For 'github' arg expected one argument: url")
case "twitter" if splitted.size == 2 => Right(Twitter(splitted(1)))
Expand All @@ -25,6 +25,6 @@ object SocialLinks:
case "discord" => Left(errorPrefix + "For 'discord' arg expected one argument: url")
case LowercaseNamePattern() if splitted.size == 4 => Right(Custom(splitted(1), splitted(2), splitted(3)))
case LowercaseNamePattern() if splitted.size == 3 => Right(Custom(splitted(1), splitted(2), splitted(2)))
case LowercaseNamePattern() => Left(errorPrefix + "For 'custom' two minimum arguments are expected: url, white icon name, [dark icon name]")
case LowercaseNamePattern() => Left(errorPrefix + "For the 'custom' link, a minimum of two arguments is expected: URL, light icon file name, [dark icon file name]")
case _ => Left(errorPrefix)
}
9 changes: 7 additions & 2 deletions scaladoc/test/dotty/tools/scaladoc/SocialLinksTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ class SocialLinksTest:
val expected = SocialLinks.Custom("https://custom.com/test", "custom", "custom-dark")
assertEquals(expected, SocialLinks.parse(customLink).getOrElse(null))

@Test def customLinkUpper(): Unit =
val customLink = "Namecustom::https://custom.com/test::custom"
val expected = SocialLinks.Custom("https://custom.com/test", "custom", "custom")
assertEquals(expected, SocialLinks.parse(customLink).getOrElse(null))

@Test def parseRegexError(): Unit =
val regexErrorLink = "nameCustom::https://custom.com/test::custom::custom-dark::custom"
val regexErrorLink = "nameCustom3::https://custom.com/test::custom::custom-dark::custom"
val expected = s"Social links arg $regexErrorLink is invalid: "
assertEquals(expected, SocialLinks.parse(regexErrorLink).left.getOrElse(null))

@Test def parseLinkWithError(): Unit =
val errorLink = "namecustom::https://custom.com/test::custom::custom-dark::custom"
val expected = s"Social links arg $errorLink is invalid: For 'custom' two minimum arguments are expected: url, white icon name, [dark icon name]"
val expected = s"Social links arg $errorLink is invalid: For the 'custom' link, a minimum of two arguments is expected: URL, light icon file name, [dark icon file name]"
assertEquals(expected, SocialLinks.parse(errorLink).left.getOrElse(null))

0 comments on commit 4f03d10

Please sign in to comment.