-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
parboiled-core/src/test/scala/org/parboiled2/ReductionResetSpec.scala
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,75 @@ | ||
/* | ||
* Copyright 2009-2019 Mathias Doenitz | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.parboiled2 | ||
|
||
import utest._ | ||
import shapeless._ | ||
|
||
object ReductionResetSpec extends TestParserSpec { | ||
|
||
abstract class ReductionResetParser extends TestParser1[Int] { | ||
|
||
def Alternative: Rule1[Int] = rule { | ||
Digits ~ (String2Int ~ "." | String2Int) | ||
} | ||
|
||
def ZeroOrMore: Rule1[Int] = rule { | ||
Digits ~ zeroOrMore(String2Int ~ "." ~ Int2String) ~ String2Int | ||
} | ||
|
||
def OneOrMore: Rule1[Int] = rule { | ||
Digits ~ oneOrMore(String2Int ~ "." ~ Int2String) ~ String2Int | ||
} | ||
|
||
def String2Int: Rule[String :: HNil, Int :: HNil] = rule { | ||
run((_: String).toInt) | ||
} | ||
|
||
def Int2String: Rule[Int :: HNil, String :: HNil] = rule { | ||
run((_: Int).toString) | ||
} | ||
|
||
def Digits: Rule1[String] = rule { | ||
capture(oneOrMore(CharPredicate.Digit)) | ||
} | ||
} | ||
|
||
val tests = Tests { | ||
|
||
"ReductionResetSpec" - { | ||
|
||
"reduction reset in `|`" - new ReductionResetParser { | ||
def targetRule = Alternative | ||
|
||
// re-enable after fixing | ||
//"123" must beMatchedWith(123) | ||
} | ||
|
||
"reduction reset in `zeroOrMore`" - new ReductionResetParser { | ||
def targetRule = ZeroOrMore | ||
|
||
//"123" must beMatchedWith(123) | ||
} | ||
|
||
"reduction reset in `oneOrMore`" - new ReductionResetParser { | ||
def targetRule = OneOrMore | ||
|
||
//"123." must beMatchedWith(123) | ||
} | ||
} | ||
} | ||
} |