Example

An “example” (or example method ) is a unary method that produces an example object .

In Glamorous Toolkit, examples serve as test methods and can contain assertions.

An example is always tagged with a <gtExample> pragma. For example, this example method produces a text editor, moves a cursor, simulates a selection, and eventually asserts that it answers the selection:

select_moveOneRight_at_6
	<gtExample>
	| anEditor |
	anEditor := self editorOnMultilineText.
	anEditor editor moveCursorTo: 6.
	anEditor selecter
		moveOneToRight;
		select.
	self 
		assert: anEditor selection 
		equals: (BlCompositeSelection new select: 6 to: 7).
	self 
		assert: anEditor editor selectedText asString 
		equals: 'e'.
	self assert: anEditor cursors equals: (BrTextEditorCursor atAll: #(7)).
	^ anEditor
    

Examples can always be evaluated and inspected, by clicking on the “play and inspect” button: