mirror of https://github.com/sbt/sbt.git
Merge pull request #3955 from dwijnand/fix-validID
Fix validID & expand tests
This commit is contained in:
commit
c9f3a73c3b
|
|
@ -317,7 +317,7 @@ object DefaultParsers extends Parsers with ParserMain {
|
|||
/** Returns `true` if `s` parses successfully according to [[ID]].*/
|
||||
def validID(s: String): Boolean = {
|
||||
// Handwritten version of `matches(ID, s)` because validID turned up in profiling.
|
||||
def isIdChar(c: Char): Boolean = Character.isLetterOrDigit(c) || (c == '_')
|
||||
def isIdChar(c: Char): Boolean = Character.isLetterOrDigit(c) || (c == '-') || (c == '_')
|
||||
@tailrec def isRestIdChar(cur: Int, s: String, length: Int): Boolean =
|
||||
if (cur < length)
|
||||
isIdChar(s.charAt(cur)) && isRestIdChar(cur + 1, s, length)
|
||||
|
|
|
|||
|
|
@ -8,10 +8,21 @@
|
|||
package sbt.internal.util
|
||||
package complete
|
||||
|
||||
import org.scalacheck._, Prop._
|
||||
import org.scalacheck._, Gen._, Prop._
|
||||
|
||||
object DefaultParsersSpec extends Properties("DefaultParsers") {
|
||||
import DefaultParsers._
|
||||
import DefaultParsers.{ ID, isIDChar, matches, validID }
|
||||
|
||||
property("validID == matches(ID, s)") = forAll((s: String) => validID(s) == matches(ID, s))
|
||||
property("∀ s ∈ String: validID(s) == matches(ID, s)") = forAll(
|
||||
(s: String) => validID(s) == matches(ID, s))
|
||||
|
||||
property("∀ s ∈ genID: matches(ID, s)") = forAll(genID)(s => matches(ID, s))
|
||||
property("∀ s ∈ genID: validID(s)") = forAll(genID)(s => validID(s))
|
||||
|
||||
private val chars: Seq[Char] = Char.MinValue to Char.MaxValue
|
||||
private val genID: Gen[String] =
|
||||
for {
|
||||
c <- oneOf(chars filter (_.isLetter))
|
||||
cs <- listOf(oneOf(chars filter isIDChar))
|
||||
} yield (c :: cs).mkString
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue