Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from MoeOrganization/prakashk/misc-fixes
Misc fixes
- Loading branch information
Showing
5 changed files
with
102 additions
and
23 deletions.
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
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
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
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
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,60 @@ | ||
package org.moe.parser | ||
|
||
import org.scalatest.FunSuite | ||
import org.scalatest.BeforeAndAfter | ||
import org.scalatest.matchers.ShouldMatchers | ||
|
||
import org.moe.runtime._ | ||
import org.moe.interpreter._ | ||
import org.moe.ast._ | ||
import org.moe.parser._ | ||
|
||
class IOClassTestSuite extends FunSuite with BeforeAndAfter with ParserTestUtils with ShouldMatchers { | ||
|
||
// NOTE: These tests depend on the file t/000-load.t to exist. | ||
// Should the contents of this file change, the tests must also be | ||
// updated appropriately. | ||
|
||
private val goodPath = """my $path = "t/000-load.t";""" | ||
private val badPath = """my $path = "t/000-load.x";""" | ||
|
||
test("... basic IO test -- .new") { | ||
val result = interpretCode(goodPath + """my $io = ^IO.new($path); $io.isa("IO")""") | ||
result.unboxToBoolean.get should equal (true) | ||
} | ||
|
||
test("... basic IO test -- existence") { | ||
val result = interpretCode(goodPath + """my $io = ^IO.new($path); -e $io""") | ||
result.unboxToBoolean.get should equal (true) | ||
} | ||
|
||
test("... basic IO test -- existence with invalid file") { | ||
val result = interpretCode(badPath + """my $io = ^IO.new($path); -e $io""") | ||
result.unboxToBoolean.get should equal (false) | ||
} | ||
|
||
test("... basic IO test -- readable") { | ||
val result = interpretCode(goodPath + """my $io = ^IO.new($path); -r $io""") | ||
result.unboxToBoolean.get should equal (true) | ||
} | ||
|
||
test("... basic IO test -- readable with invalid file") { | ||
val result = interpretCode(badPath + """my $io = ^IO.new($path); -r $io""") | ||
result.unboxToBoolean.get should equal (false) | ||
} | ||
|
||
test("... basic IO test -- readline") { | ||
val result = interpretCode(goodPath + """my $io = ^IO.new($path); $io.readline""") | ||
result.unboxToString.get should equal ("use Test::More;") | ||
} | ||
|
||
test("... basic IO test -- readlines") { | ||
val result = interpretCode(goodPath + """my $io = ^IO.new($path); $io.readlines""") | ||
val lines = result.unboxToArrayBuffer.get | ||
lines(0).unboxToString.get should equal ("use Test::More;") | ||
lines(1).unboxToString.get should equal ("") | ||
lines(2).unboxToString.get should equal ("plan(1);") | ||
lines(3).unboxToString.get should equal ("") | ||
lines(4).unboxToString.get should equal ("""ok(true, "... this worked!");""") | ||
} | ||
} |