-
Notifications
You must be signed in to change notification settings - Fork 131
issue #242 implementation of repNM for 1.2.x #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
149 changes: 149 additions & 0 deletions
149
shared/src/test/scala/scala/util/parsing/combinator/gh242.scala
This file contains hidden or 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,149 @@ | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
import scala.util.parsing.combinator.Parsers | ||
import scala.util.parsing.input.CharSequenceReader | ||
|
||
class gh242 { | ||
class TestWithSeparator extends Parsers { | ||
type Elem = Char | ||
val csv: Parser[List[Char]] = repMN(5, 10, 'a', ',') | ||
} | ||
|
||
class TestWithoutSeparator extends Parsers { | ||
type Elem = Char | ||
val csv: Parser[List[Char]] = repMN(5, 10, 'a') | ||
} | ||
|
||
@Test | ||
def testEmpty(): Unit = { | ||
val tstParsers = new TestWithSeparator | ||
val s = new CharSequenceReader("") | ||
val expectedFailure = """[1.1] failure: end of input | ||
| | ||
| | ||
|^""".stripMargin | ||
assertEquals(expectedFailure, tstParsers.csv(s).toString) | ||
} | ||
|
||
@Test | ||
def testBelowMinimum(): Unit = { | ||
val tstParsers = new TestWithSeparator | ||
val s = new CharSequenceReader("a,a,a,a") | ||
val expectedFailure = """[1.8] failure: end of input | ||
| | ||
|a,a,a,a | ||
| ^""".stripMargin | ||
assertEquals(expectedFailure, tstParsers.csv(s).toString) | ||
} | ||
|
||
@Test | ||
def testMinimum(): Unit = { | ||
val tstParsers = new TestWithSeparator | ||
val s = new CharSequenceReader("a,a,a,a,a") | ||
val expected = List.fill[Char](5)('a') | ||
val actual = tstParsers.csv(s) | ||
assertEquals(9, actual.next.offset) | ||
assert(actual.successful) | ||
assertEquals(expected, actual.get) | ||
} | ||
|
||
@Test | ||
def testInRange(): Unit = { | ||
val tstParsers = new TestWithSeparator | ||
val s = new CharSequenceReader("a,a,a,a,a,a,a,a") | ||
val expected = List.fill[Char](8)('a') | ||
val actual = tstParsers.csv(s) | ||
assertEquals(15, actual.next.offset) | ||
assert(actual.successful) | ||
assertEquals(expected, actual.get) | ||
} | ||
|
||
@Test | ||
def testMaximum(): Unit = { | ||
val tstParsers = new TestWithSeparator | ||
val s = new CharSequenceReader("a,a,a,a,a,a,a,a,a,a") | ||
val expected = List.fill[Char](10)('a') | ||
val actual = tstParsers.csv(s) | ||
assertEquals(19, actual.next.offset) | ||
assert(actual.successful) | ||
assertEquals(expected, actual.get) | ||
} | ||
|
||
@Test | ||
def testAboveMaximum(): Unit = { | ||
val tstParsers = new TestWithSeparator | ||
val s = new CharSequenceReader("a,a,a,a,a,a,a,a,a,a,a,a") | ||
val expected = List.fill[Char](10)('a') | ||
val actual = tstParsers.csv(s) | ||
assertEquals(19, actual.next.offset) | ||
assert(actual.successful) | ||
assertEquals(expected, actual.get) | ||
} | ||
|
||
@Test | ||
def testEmptyWithoutSep(): Unit = { | ||
val tstParsers = new TestWithoutSeparator | ||
val s = new CharSequenceReader("") | ||
val expectedFailure = """[1.1] failure: end of input | ||
| | ||
| | ||
|^""".stripMargin | ||
assertEquals(expectedFailure, tstParsers.csv(s).toString) | ||
} | ||
|
||
@Test | ||
def testBelowMinimumWithoutSep(): Unit = { | ||
val tstParsers = new TestWithoutSeparator | ||
val s = new CharSequenceReader("aaaa") | ||
val expectedFailure = """[1.5] failure: end of input | ||
| | ||
|aaaa | ||
| ^""".stripMargin | ||
assertEquals(expectedFailure, tstParsers.csv(s).toString) | ||
} | ||
|
||
@Test | ||
def testMinimumWithoutSep(): Unit = { | ||
val tstParsers = new TestWithoutSeparator | ||
val s = new CharSequenceReader("aaaaa") | ||
val expected = List.fill[Char](5)('a') | ||
val actual = tstParsers.csv(s) | ||
assertEquals(5, actual.next.offset) | ||
assert(actual.successful) | ||
assertEquals(expected, actual.get) | ||
} | ||
|
||
@Test | ||
def testInRangeWithoutSep(): Unit = { | ||
val tstParsers = new TestWithoutSeparator | ||
val s = new CharSequenceReader("aaaaaaaa") | ||
val expected = List.fill[Char](8)('a') | ||
val actual = tstParsers.csv(s) | ||
assertEquals(8, actual.next.offset) | ||
assert(actual.successful) | ||
assertEquals(expected, actual.get) | ||
} | ||
|
||
@Test | ||
def testMaximumWithoutSep(): Unit = { | ||
val tstParsers = new TestWithoutSeparator | ||
val s = new CharSequenceReader("aaaaaaaaaa") | ||
val expected = List.fill[Char](10)('a') | ||
val actual = tstParsers.csv(s) | ||
assertEquals(10, actual.next.offset) | ||
assert(actual.successful) | ||
assertEquals(expected, actual.get) | ||
} | ||
|
||
@Test | ||
def testAboveMaximumWithoutSep(): Unit = { | ||
val tstParsers = new TestWithoutSeparator | ||
val s = new CharSequenceReader("aaaaaaaaaaaa") | ||
val expected = List.fill[Char](10)('a') | ||
val actual = tstParsers.csv(s) | ||
assertEquals(10, actual.next.offset) | ||
assert(actual.successful) | ||
assertEquals(expected, actual.get) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.