Skip to content

Instantly share code, notes, and snippets.

@treytomes
Created April 6, 2023 19:43
Show Gist options
  • Save treytomes/f190566a928a73b426df80d48465eccf to your computer and use it in GitHub Desktop.
Save treytomes/f190566a928a73b426df80d48465eccf to your computer and use it in GitHub Desktop.
Creating a Cucumber-style test in MiniScript.
import "qa"
Scenario = {}
Scenario.init = function(name)
self.name = name
return self
end function
Scenario.Given = {}
Scenario.Given.init = function(scenario, values)
self.scenario = scenario
self.values = values
for kv in self.values
globals[kv.key] = kv.value
end for
return self
end function
Scenario.Given.assert = function(condition)
qa.assert(condition, "N/A")
return self
end function
Scenario.Given.done = function()
clr = text.color
text.color = color.green
print("Scenario ""{0}"" passed.".fill(self.scenario.name))
text.color = clr
end function
Scenario.given = function(values)
return (new Scenario.Given).init(self, values)
end function
scenario = function(name)
return (new Scenario).init(name)
end function
Tuple = {}
Tuple.init = function(x, y, z, w)
self.x = x
self.y = y
self.z = z
self.w = w
return self
end function
Tuple.isPoint = function()
return self.w == 1
end function
Tuple.isVector = function()
return self.w == 0
end function
scenario("A tuple with w=1.0 is a point").
given({"a": (new Tuple).init(4.3, -4.2, 3.1, 1.0)}).
assert(a.x == 4.3).
assert(a.y == -4.2).
assert(a.z == 3.1).
assert(a.w == 1.0).
assert(a.isPoint).
assert(not a.isVector).
done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment