-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Parse RFC3339 dates as TOML requires - Tests for date parser - Update `fastparse` to 0.3.4 - Minor changes to compile after upgrade
- Loading branch information
Showing
10 changed files
with
141 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
name := "TOML Parser in Scala" | ||
name := "stoml" | ||
|
||
organization := "com.github.jvican" | ||
|
||
version := "1.0" | ||
version := "1.1" | ||
|
||
scalaVersion := "2.11.7" | ||
|
||
libraryDependencies ++= Vector( | ||
"com.lihaoyi" %% "fastparse" % "0.3.2", | ||
"com.lihaoyi" %% "fastparse" % "0.3.4", | ||
"org.scalacheck" %% "scalacheck" % "1.12.5" % "test", | ||
"org.scalatest" % "scalatest_2.11" % "2.2.4" % "test" | ||
) | ||
|
||
licenses := Seq("MIT License" -> url("http://www.opensource.org/licenses/MIT")) | ||
|
||
sonatypeProfileName := "com.github.jvican" | ||
|
||
pomExtra in Global := { | ||
<url>https://github.com/jvican/stoml.git</url> | ||
<scm> | ||
<developerConnection>scm:git:git@github.com:jvican</developerConnection> | ||
<url>https://github.com/jvican/stoml.git</url> | ||
<connection>scm:git:git@github.com:jvican/stoml.git</connection> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<id>jvican</id> | ||
<name>Jorge Vicente Cantero</name> | ||
<url>https://github.com/jvican</url> | ||
</developer> | ||
</developers> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package toml | ||
|
||
import org.scalacheck.Gen | ||
import org.scalatest.prop._ | ||
import org.scalatest.{Matchers, PropSpec} | ||
import fastparse.core.Parsed.Success | ||
|
||
trait DateTomlGen { | ||
import Gen.chooseNum | ||
|
||
def pad(n: Int, s: String): String = | ||
if(s.length < n) ("0" * (n - s.length)) + s else s | ||
def genNum(digits: Int, from: Int, to: Int): Gen[String] = | ||
chooseNum(from, to).map(n => pad(digits, n.toString)) | ||
|
||
/* This check is not covering all the formats */ | ||
val dateFormatGen: Gen[String] = for { | ||
day <- genNum(2, 0, 28) | ||
month <- genNum(2, 1, 12) | ||
year <- genNum(4, 0, 2200) | ||
hour <- genNum(2, 0, 23) | ||
minute <- genNum(2, 0, 59) | ||
second <- genNum(2, 0, 59) | ||
micro <- genNum(3, 0, 999) | ||
} yield (year + "-" + month + "-" + day + | ||
"T" + hour + ":" + minute + ":" + | ||
second + "." + micro + "Z") | ||
} | ||
|
||
class DateTomlSpec extends PropSpec | ||
with PropertyChecks with Matchers | ||
with DateTomlGen with TomlParser | ||
with TestParserUtil { | ||
|
||
property("parse dates following the RFC 3339 spec (`date` parser)") { | ||
forAll(dateFormatGen) { | ||
s => | ||
shouldBeSuccess(date.parse(s)) | ||
} | ||
} | ||
|
||
property("parse dates following the RFC 3339 spec") { | ||
forAll(dateFormatGen) { | ||
s => | ||
shouldBeSuccess(elem.parse(s)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package toml | ||
|
||
import fastparse.core.Result | ||
import fastparse.core.Result.{Failure, Success} | ||
import fastparse.core.Parsed | ||
import fastparse.core.Parsed.{Failure, Success} | ||
import org.scalatest.Matchers | ||
|
||
trait TestParserUtil { | ||
this: Matchers => | ||
|
||
def shouldBeSuccess[T](r: Result[T]) = r match { | ||
def shouldBeSuccess[T](r: Parsed[T]) = r match { | ||
case s: Success[T] => assert(true) | ||
case f: Failure => fail(s"$r is not a Success.") | ||
} | ||
|
||
def shouldBeFailure[T](r: Result[T]) = r match { | ||
def shouldBeFailure[T](r: Parsed[T]) = r match { | ||
case s: Success[T] => fail(s"$r is not a Failure.") | ||
case f: Failure => assert(true) | ||
} | ||
} | ||
} |