Skip to content

Instantly share code, notes, and snippets.

@k33g
Last active December 15, 2015 08:18
Show Gist options
  • Save k33g/5229460 to your computer and use it in GitHub Desktop.
Save k33g/5229460 to your computer and use it in GitHub Desktop.
Elmira : some tests with golo
module elmira
import java.util.HashMap
import java.util.Arrays
import java.util.LinkedList
function test = -> DynamicObject()
function Elmira = -> DynamicObject():
tests(HashMap()):
key(0):
define("it", |this, testDescription, func| {
var _test = test(): description(testDescription): func(func)
this: tests(): put(this: key(), _test)
return this
}):
define("equalsTo", |this, value| {
this: tests(): get(this: key()): condition("equalsTo"): compareTo(value)
this: key(this: key() + 1)
return this
}):
define("notEqualsTo", |this, value| {
this: tests(): get(this: key()): condition("notEqualsTo"): compareTo(value)
this: key(this: key() + 1)
return this
}):
define("isLessThan", |this, value| {
this: tests(): get(this: key()): condition("isLessThan"): compareTo(value)
this: key(this: key() + 1)
return this
}):
define("isLessThanOrEqualTo", |this, value| {
this: tests(): get(this: key()): condition("isLessThanOrEqualTo"): compareTo(value)
this: key(this: key() + 1)
return this
}):
define("isGreaterThan", |this, value| {
this: tests(): get(this: key()): condition("isGreaterThan"): compareTo(value)
this: key(this: key() + 1)
return this
}):
define("isGreaterThanOrEqualTo", |this, value| {
this: tests(): get(this: key()): condition("isGreaterThanOrEqualTo"): compareTo(value)
this: key(this: key() + 1)
return this
}):
define("so", |this, boolVal| {
if boolVal {println(":) Test is OK")} else {println(":( Test is KO")}
}):
define("run", |this| {
println("-------------------------------------------------------------------------------------------------")
println(" "+this: describe())
println("-------------------------------------------------------------------------------------------------")
foreach (test in this: tests(): entrySet()) {
println("[Test " + test: getKey() + "]" +
" -> \"" + test: getValue(): description() + "\"" +
" | Return -> " + test: getValue(): func() +
" | Condition -> " + test: getValue(): condition() +
" | CompareTo -> " + test: getValue(): compareTo()
)
case {
when test: getValue(): condition() == "equalsTo" {
this: so(test: getValue(): func() == test: getValue(): compareTo())
}
when test: getValue(): condition() == "notEqualsTo" {
this: so(test: getValue(): func() != test: getValue(): compareTo())
}
when test: getValue(): condition() == "isLessThan" {
this: so(test: getValue(): func() < test: getValue(): compareTo())
}
when test: getValue(): condition() == "isLessThanOrEqualTo" {
this: so(test: getValue(): func() <= test: getValue(): compareTo())
}
when test: getValue(): condition() == "isGreaterThan" {
this: so(test: getValue(): func() > test: getValue(): compareTo())
}
when test: getValue(): condition() == "isGreaterThanOrEqualTo" {
this: so(test: getValue(): func() >= test: getValue(): compareTo())
}
otherwise { println("... something should be here but ...") }
}
println("-------------------------------------------------------------------------------------------------")
}
})
module main

import elmira

function add = |a,b| { 
  return a+b 
}

function main = |args| {

	let toto = -> "toto"
	let tutu = -> "tutu"
	let tata = |message| -> "tata : " + message

	Elmira(): describe("Hello this is my tests"): 
		it("toto() should return toto", toto()): equalsTo("toto"):
		it("tutu() should return tutu", tutu()): equalsTo("tutu"):
		it("should return tata : hello", tata("hello")): equalsTo("tata : hello"):
		it("6+6 should return 12", add(6,6)): equalsTo(12):
		it("6+6 shouldn't return 25", add(6,6)): notEqualsTo(25):
		it("6+6 isGreaterThan 25 should be KO", add(6,6)): isGreaterThan(25):
		run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment