Skip to content

Commit

Permalink
Merge pull request #21 from NthPortal/tests
Browse files Browse the repository at this point in the history
Add tests for AliasProcessor
  • Loading branch information
NthPortal committed Jan 24, 2017
2 parents 477ac10 + 7c6c0dc commit d770357
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/scala/com/nthportal/shell/extensions/alias/Alias.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ package extensions.alias
* used in an input line
*/
case class Alias(name: String, expansion: String)

object Alias {
/**
* Creates an alias for a command (with no added arguments).
*
* @param name the name of the alias
* @param command the command for which it should be an alias
* @return an alias for the specified command
*/
def forCommand(name: String, command: Command): Alias = apply(name, command.name)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.nthportal.shell.extensions.alias

import com.nthportal.shell.{Shell, SimpleSpec}
import com.nthportal.shell.impl.{NoOpOutputProvider, TestCommand}
import com.nthportal.shell.parsers.WhitespaceDelineatingParser

class AliasProcessorTest extends SimpleSpec {

behavior of "AliasProcessor"

it should "process aliases properly" in {
val command = TestCommand()
val name = "alias"
val alias = Alias.forCommand(name, command)
val processor = AliasProcessor(alias)
val shell = Shell(WhitespaceDelineatingParser, NoOpOutputProvider, List(processor), command)

shell.executeLine(name)
command.executed should be (true)
}

it should "not loop infinitely" in {
val command = TestCommand()
val name = "alias"
val a1 = Alias(command.name, name)
val a2 = Alias.forCommand(name, command)
val processor = AliasProcessor(a1, a2)
val shell = Shell(WhitespaceDelineatingParser, NoOpOutputProvider, List(processor), List(command))

shell.executeLine(command.name)
command.executed should be (true)
}
}

0 comments on commit d770357

Please sign in to comment.