{value
let test-target:TestTarget = {TestTarget} || counters
let n-success:int = 0
let n-failure:int = 0
|| displays
let success-display:TextDisplay =
{TextDisplay {splice display-styling}}
let failure-display:TextDisplay =
{TextDisplay {splice display-styling}}
|| coordination
{test-target.add-event-handler
{on e:TestMessage do
{switch e.result
case "success" do
{inc n-success}
set success-display.value =
{String n-success}
case "failure" do
{inc n-failure}
set failure-display.value =
{String n-failure}
}}}
|| layout
{VBox spacing = 6px, margin = 6px, border-width = 1px,
|| driver commands
{HBox spacing = 6px,
{CommandButton label = {message Run},
{on Action do
{test-target.run-tests}}},
{CommandButton label = {message Reset},
{on Action do
set n-success = 0
set n-failure = 0
{success-display.unset-value}
{failure-display.unset-value}
}},
{Fill}},
|| progress display
{HBox spacing = 6px,
success-display,
failure-display,
{Fill}}
}
}
{value
let test-target:TestTarget = {TestTarget}
|| counters
let counters:ItemCounter = {ItemCounter}
|| coordination
{test-target.add-event-handler
{on e:TestMessage do
{counters.note-item e.result}
}}
|| layout
{VBox spacing = 6px, margin = 6px, border-width = 1px,
|| driver commands
{HBox spacing = 6px,
{CommandButton label = {message Run},
{on Action do
{test-target.run-tests}}},
{CommandButton label = {message Reset},
{on Action do
{counters.clear}
}},
{Fill}},
|| progress display
{HBox spacing = 6px,
data-binding-context = counters,
{TextDisplay {splice display-styling},
{bind value to "success"}},
{TextDisplay {splice display-styling},
{bind value to "failure"}},
{Fill}}
}
}
{define-class public ItemCounter
{inherits {HashTable-of String, int}, DataBindingContext}
{constructor public {default ...}
{construct-super.{HashTable-of String, int} {splice ...}}
}
{method {note-item item:String}:void
{if {self.key-exists? item} then
{inc self[item]}
else
set self[item] = 1
}
{self.refresh}
}
|| DataBindingContext protocol
{method public {get-data selector:any}:(any, bool)
{return
{type-switch selector
case item:String do
{self.get-if-exists item}
else
(0, false)
}}
}
|| HashTable-of protocol
{method public {clear}:void
{super.clear}
{self.refresh}
}
}
There are no comments on this document