Fixed: workout names #8

master
mgifos 8 years ago
parent a88c8f8983
commit 3aa27efadb
  1. 4
      README.md
  2. 2
      src/main/scala/com.github.mgifos.workouts/model/Workout.scala
  3. 12
      src/test/scala/com/github/mgifos/workouts/model/WorkoutSpec.scala

@ -32,7 +32,7 @@ Checkout a [complete training plan for 80K ultra](https://docs.google.com/spread
- Java 8 is a prerequisite, make sure you have it installed - Java 8 is a prerequisite, make sure you have it installed
- Go to the [releases page](https://github.com/mgifos/quick-plan/releases) of this project - Go to the [releases page](https://github.com/mgifos/quick-plan/releases) of this project
- Download latest release zip file and unzip it somewhere on your computer - Download latest release zip file and unzip it somewhere on your computer
- Enter bin folder and run `quick-plan` command (use `quick-plan.bat` if you are a Windows user) - Enter bin folder and run `quick-plan` command (use `quick-plan.bat` if you are a Windows user or mark quick-plan script as executable on Linux or Mac systems)
## Command line options ## Command line options
@ -73,6 +73,8 @@ The reserved keywords of the notation are: workout, warmup, cooldown, run, repea
**`<header>`** := `workout: <name>` **`<header>`** := `workout: <name>`
**`<name>`** := `[\u0020-\u007F]+` (printable ascii characters)
**`<step>`** := `<newline>- <step-def>` **`<step>`** := `<newline>- <step-def>`
**`<step-def>`** := `<simple-step> | <repetition-step>` **`<step-def>`** := `<simple-step> | <repetition-step>`

@ -33,7 +33,7 @@ case class WorkoutNote(note: String) extends Workout {
object Workout { object Workout {
private val WorkoutName = """^workout:\s([\w \-,;:\.@]+)((\n\s*\-\s[a-z]+:.*)*)$""".r private val WorkoutName = """^workout:\s([\u0020-\u007F]+)((\n\s*\-\s[a-z]+:.*)*)$""".r
private val NextStepRx = """^((-\s\w*:\s.*)((\n\s{1,}-\s.*)*))(([\s].*)*)$""".r private val NextStepRx = """^((-\s\w*:\s.*)((\n\s{1,}-\s.*)*))(([\s].*)*)$""".r
def parseDef(x: String): Either[String, WorkoutDef] = { def parseDef(x: String): Either[String, WorkoutDef] = {

@ -34,6 +34,18 @@ class WorkoutSpec extends FlatSpec with Matchers {
CooldownStep(LapButtonPressed))))) CooldownStep(LapButtonPressed)))))
} }
"Workout" should "parse various printable workout-names correctly" in {
val testNames = Seq("abcz", "123 xyw", """abc!/+-@,?*;:_!\"#$%&/()=?*""")
testNames.foreach { testName =>
val x = Workout.parseDef(testWO.replace("run-fast", testName))
println(x)
x.right.get.name should be(testName)
}
}
"Workout" should "dump json correctly" in { "Workout" should "dump json correctly" in {
val is = getClass.getClassLoader.getResourceAsStream("run-fast.json") val is = getClass.getClassLoader.getResourceAsStream("run-fast.json")
val expectJson = Json.parse(is) val expectJson = Json.parse(is)

Loading…
Cancel
Save