Skip to content
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

Load file overload #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/main/scala/ai/newmap/interpreter/EnvironmentInterpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ai.newmap.model._
import ai.newmap.util.{Outcome, Success, Failure}

import java.io.File

import scala.io.Source

class EnvironmentInterpreter(
Expand Down Expand Up @@ -137,13 +138,28 @@ class EnvironmentInterpreter(
}
}

def checkFilePath(fileInput: String): String = {
val filePath1 = "src/main/newmap/TestScripts"
val filePath2 = "src/test/newTests/"

val file1 = new File(filePath1, fileInput)
if (file1.exists) {
return file1.getAbsolutePath
}

val file2 = new File(filePath2, fileInput)
if (file2.exists) {
return file2.getAbsolutePath
}

return fileInput
}

def loadFile(filename: String): String = {
val baseDir = "src/main/newmap/"

val fileName = baseDir + filename
val fileName = checkFilePath(filename)

val linesIt = Source.fromFile(fileName).getLines

loadFileFromIterator(linesIt, env) match {
case Success(_) => ""
case Failure(reason) => s"Failure: $reason"
Expand Down