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

Add tests for AliasProcessor #21

Merged
merged 2 commits into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}
}