Skip to content

Instantly share code, notes, and snippets.

@jacobappleton
Created August 9, 2015 21:18
Show Gist options
  • Save jacobappleton/324b3b9405a8c21165a4 to your computer and use it in GitHub Desktop.
Save jacobappleton/324b3b9405a8c21165a4 to your computer and use it in GitHub Desktop.
Tests for the Shunting Yard algorithm with parentheses
package io.jacobappleton.compilers.regex
import org.scalatest.FlatSpec
import scala.language.postfixOps
class ShuntingYardTests extends FlatSpec {
it should "when given the Regex a.b|c.d the output should be ab.cd.|" in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.b|c.d") == "ab.cd.|")
}
it should "when given the Regex a.(b|c).d the output should be abc|.d." in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.(b|c).d") == "abc|.d.")
}
it should "when given the regex a.b*.c the output should be ab.*c." in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.b*.c") == "ab*.c.")
}
it should "when given the regex a.b**|c the output should be ab**.c|" in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.b**|c") == "ab**.c|")
}
it should "when given the regex a.b.c.d|e the output should be ab.c.d.e|" in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("a.b.c.d|e") == "ab.c.d.e|")
}
it should "when given the regex j.a(c|o).b the output should be ja.co|.b." in {
val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2))
assert(parser.toPostfix("j.a.(c|o).b") == "ja.co|.b.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment