-
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.
= add VarianceSpec with a (commented out) failing test for #172
- Loading branch information
Showing
2 changed files
with
93 additions
and
1 deletion.
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
92 changes: 92 additions & 0 deletions
92
parboiled-core/src/test/scala/org/parboiled2/VarianceSpec.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,92 @@ | ||
/* | ||
* Copyright (C) 2009-2013 Mathias Doenitz, Alexander Myltsev | ||
* | ||
* 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 shapeless.test.illTyped | ||
import shapeless._ | ||
|
||
//// pure compile-time-only test | ||
class VarianceSpec { | ||
|
||
// the Parsing DSL should | ||
{ | ||
|
||
// honor contravariance on the 1st type param of the `Rule` type | ||
{ | ||
// valid example | ||
test { | ||
abstract class Par extends Parser { | ||
def A: Rule2[String, Int] = ??? | ||
def B: PopRule[Any :: HNil] = ??? | ||
def C: Rule1[String] = rule { A ~ B } | ||
} | ||
() | ||
} | ||
|
||
// TODO: fix https://github.com/sirthias/parboiled2/issues/172 and re-enable | ||
// //invalid example 1 | ||
// test { | ||
// abstract class Par extends Parser { | ||
// def A: Rule1[Any] = ??? | ||
// def B: PopRule[Int :: HNil] = ??? | ||
// } | ||
// illTyped("""class P extends Par { def C = rule { A ~ B } }""", "Illegal rule composition") | ||
// } | ||
|
||
// invalid example 2 | ||
test { | ||
abstract class Par extends Parser { | ||
def A: Rule2[String, Any] = ??? | ||
def B: PopRule[Int :: HNil] = ??? | ||
} | ||
illTyped("""class P extends Par { def C = rule { A ~ B } }""", "Illegal rule composition") | ||
} | ||
|
||
// invalid example 3 | ||
test { | ||
abstract class Par extends Parser { | ||
def A: Rule1[String] = ??? | ||
def B: PopRule[Int :: HNil] = ??? | ||
} | ||
illTyped("""class P extends Par { def C = rule { A ~ B } }""", "Illegal rule composition") | ||
} | ||
} | ||
|
||
// honor covariance on the 2nd type param of the `Rule` type | ||
{ | ||
// valid example | ||
test { | ||
abstract class Par extends Parser { | ||
def A: Rule0 = ??? | ||
def B: Rule1[Int] = ??? | ||
def C: Rule1[Any] = rule { A ~ B } | ||
} | ||
} | ||
|
||
// invalid example | ||
test { | ||
abstract class Par extends Parser { | ||
def A: Rule0 = ??? | ||
def B: Rule1[Any] = ??? | ||
} | ||
illTyped("""class P extends Par { def C: Rule1[Int] = rule { A ~ B } }""", "type mismatch;.*") | ||
} | ||
} | ||
} | ||
|
||
def test(x: Any): Unit = () // prevent "a pure expression does nothing in statement position" warnings | ||
} |