Permalink
Browse files

Removed/changed senders of addPrototype:.

  • Loading branch information...
1 parent 217708e commit 963c98553aa36ee1daa85205006a7e59d9a3d2aa @briantrice committed Mar 6, 2011
@@ -1,4 +1,4 @@
-collections addPrototype: #Collection derivedFrom: {Cloneable}.
+collections definePrototype: #Collection &basis: Cloneable.
"The abstract object type for Collections, objects which other objects can be
added and removed and tested for as elements."
View
@@ -1,10 +1,9 @@
-
-collections addPrototype: #Heap derivedFrom: {SortedArray}.
+collections definePrototype: #Heap &basis: SortedArray &doing: [
+ sortBlock := #< `er. "The block used for comparing items for sorting."
+].
"A heap is a SortedArray of items.
It is more efficient than a standard SortedArray if elements are only
removed at the beginning, and elements are added in arbitrary sort order."
-Heap sortBlock := #< `er.
-"The block used for comparing items for sorting."
h@(Heap traits) push: obj
[
View
@@ -1,12 +1,13 @@
-streams addPrototype: #RandomStream derivedFrom: {PositionableReadStream}.
+streams define: #RandomStream &basis: PositionableReadStream &doing: [
+ #state := (Array newSize: 624).
+"This array is used for the calculations and works as a kind of history buffer.
+The particular size of the array corresponds to / is determined by the
+desired range of the outputs. See the website for particulars when porting."
+].
"Answers a series of pseudo-random positive SmallIntegers across the entire
value range. It is very fast and has an extremely long period (2^19937-1).
Based off the Mersenne Twister code in C at:
http://www.math.keio.ac.jp/~matumoto/emt.html"
-RandomStream addSlot: #state valued: (Array newSize: 624).
-"This array is used for the calculations and works as a kind of history buffer.
-The particular size of the array corresponds to / is determined by the
-desired range of the outputs. See the website for particulars when porting."
rs@(RandomStream traits) collectionType
[
@@ -1,6 +1,4 @@
-prototypes addPrototype: #EventTest derivedFrom: {Cloneable}.
-
-EventTest addSlot: #fini valued: False.
+prototypes define: #EventTest &slots: {#fini -> False}.
et@(EventTest traits) showEvents
[| evt evt_type |
@@ -65,4 +63,4 @@ _@(EventTest traits) showOther: event
inform: 'Some other event going on'.
].
-EventTest showEvents.
+EventTest showEvents.
View
@@ -1,4 +1,4 @@
-UnitTests addPrototype: #File derivedFrom: {TestCase}.
+UnitTests definePrototype: #File &basis: TestCase.
"Unit test for file functionality."
UnitTests File addSlot: #inputFileName valued: ('LICENSE' as: File Locator).
View
@@ -1,4 +1,4 @@
-UnitTests addPrototype: #MapOverlay derivedFrom: { TestCase }.
+UnitTests definePrototype: #MapOverlay &basis: TestCase.
"Tests the MapOverlay class"
View
@@ -1,6 +1,6 @@
load: 'src/lib/regex.slate'.
-"UnitTests addPrototype: #Regex derivedFrom: {TestCase}.
+"UnitTests definePrototype: #Regex &basis: TestCase.
tc@(UnitTests Regex traits) shouldMatch: string against: regex withMatches: c
[| matcher |
@@ -1,4 +1,4 @@
-RegressionTests addPrototype: #CollectionHash derivedFrom: {TestCase}.
+RegressionTests definePrototype: #CollectionHash &basis: TestCase.
"Checks whether hash value for collections with same elements is equal."
t@(RegressionTests CollectionHash traits) testCollection: c1 against: c2
@@ -40,7 +40,7 @@ t@(RegressionTests CollectionHash traits) suite
#testSequence.
}].
-RegressionTests addPrototype: #ExtSeqWriter derivedFrom: {TestCase}.
+RegressionTests definePrototype: #ExtSeqWriter &basis: TestCase.
"Checks whether writer iterator of ExtensibleSequence is actually able to
extend the sequence."
@@ -1,4 +1,4 @@
-RegressionTests addPrototype: #WordCount derivedFrom: {TestCase}.
+RegressionTests definePrototype: #WordCount &basis: TestCase.
"A regression test playing with the LICENSE file"
t@(RegressionTests WordCount traits) testFileName
@@ -7,8 +7,8 @@ t@(RegressionTests WordCount traits) testFileName
].
t@(RegressionTests WordCount traits) testWordCount
-[| words |
- words: Bag new.
+[
+ words ::= Bag new.
(File newNamed: t testFileName &mode: File Read) sessionDo:
[| :file |
file reader split >> words writer.
@@ -20,11 +20,11 @@ t@(RegressionTests WordCount traits) testWordCount
t@(RegressionTests WordCount traits) testLineCount
"Note that empty lines will be ignored by #splitWith: "
[| lineCount |
- lineCount: 0.
+ lineCount := 0.
(File newNamed: t testFileName &mode: File Read) sessionDo:
[| :file |
(file reader splitWith: { $\n }) do:
- [| :line | lineCount: lineCount succ].
+ [| :line | lineCount += 1].
].
"Console ; 'Number of lines ' ; (lineCount as: String) ; '\n'."
t assert: lineCount = 16 description: 'The number of lines found in the LICENSE file is not as expected.'.
View
@@ -1,5 +1,4 @@
-
-UnitTests addPrototype: #SkipList derivedFrom: {TestCase}.
+UnitTests definePrototype: #SkipList &basis: TestCase.
tc@(UnitTests SkipList traits) isEmpty
[
View
@@ -8,57 +8,58 @@ CursesConsole traits lib: Nil.
Image save.
"
-UnitTests addPrototype: #SmartConsole derivedFrom: {Cloneable}.
+UnitTests definePrototype: #SmartConsole.
"Not a real unit test, it's an object to dispatch on for a few
methods that test SmartConsole/Terminal functionality with human
interaction."
_@(UnitTests SmartConsole traits) streamedCommandProcessor
[
- SmartConsole new sessionDo: [| :console terminal editor reader |
- terminal: (Terminal newBasedOn: console).
- editor: terminal commandEditor.
- editor prompt: 'Prompt> '.
- reader: editor reader.
-
- terminal ; 'This test should echo all lines committed by enters, and exit if a \'q\' character is encountered'.
-
- [| char |
- char: reader next.
- terminal nextPut: char.
- "char printOn: terminal &radix: 16."
- terminal flush.
- char = $q
- ] whileFalse.
+ SmartConsole new sessionDo:
+ [| :console terminal editor reader |
+ terminal := Terminal newBasedOn: console.
+ editor := terminal commandEditor.
+ editor prompt := 'Prompt> '.
+ reader := editor reader.
+
+ terminal ; 'This test should echo all lines committed by enters, and exit if a \'q\' character is encountered'.
+
+ [| char |
+ char := reader next.
+ terminal nextPut: char.
+ "char printOn: terminal &radix: 16."
+ terminal flush.
+ char = $q] whileFalse
].
].
_@(UnitTests SmartConsole traits) commandProcessor
[
- SmartConsole new sessionDo: [| :console terminal editor |
- terminal: (Terminal newBasedOn: console).
- editor: terminal commandEditor.
- editor prompt: 'Prompt> '.
-
- terminal ; 'This test should echo lines ending with a dot and committed with enters; quit with the \'quit.\' command'.
- terminal newLine.
- console writer ; 'Also demonstrates editing at any column: '.
-
- [| line |
- [ line: editor readLine.
- ["console writeCursorPositionAt: (console width // 2) , (console height // 2)."
+ SmartConsole new sessionDo:
+ [| :console terminal editor |
+ terminal := (Terminal newBasedOn: console).
+ editor := terminal commandEditor.
+ editor prompt := 'Prompt> '.
+
+ terminal ; 'This test should echo lines ending with a dot and committed with enters; quit with the \'quit.\' command'.
+ terminal newLine.
+ console writer ; 'Also demonstrates editing at any column: '.
+
+ [| line |
+ [line := editor readLine.
+ ["console writeCursorPositionAt: (console width // 2) , (console height // 2)."
line size = 0 \/ [(line at: line indexLast) ~= $. ]]
- whileTrue: [line: (editor continue)].
+ whileTrue: [line := editor continue].
- terminal newLine.
- terminal ; '\'' ; line ; '\''.
- terminal newLine.
- terminal flush]
- on: Stream Exhaustion do: [| :_ |
- terminal ; '\nStream closed\n'].
+ terminal newLine.
+ terminal ; '\'' ; line ; '\''.
+ terminal newLine.
+ terminal flush]
+ on: Stream Exhaustion do: [| :_ |
+ terminal ; '\nStream closed\n'].
- line ~= Nil /\ [line = 'quit.']
- ] whileFalse.
+ line ~= Nil /\ [line = 'quit.']
+ ] whileFalse.
].
].
@@ -105,7 +106,7 @@ _@(UnitTests SmartConsole traits) draw
_@(UnitTests SmartConsole traits) echoEvent: event@(SmartConsole ResizeEvent traits) on: terminal
[| console |
- console: terminal console.
+ console := terminal console.
terminal ; 'Console resized to: ' ; (console width as: String) ; 'x' ; (console height as: String).
console clearToEOL.
terminal newLine.
@@ -114,7 +115,7 @@ _@(UnitTests SmartConsole traits) echoEvent: event@(SmartConsole ResizeEvent tra
_@(UnitTests SmartConsole traits) echoEvent: event@(SmartConsole KeyEvent traits) on: terminal
[| console |
- console: terminal console.
+ console := terminal console.
terminal ; 'Key code: ' ; (event keyCode as: String) ; ' - 16r' ;
(event keyCode printString &radix: 16).
console clearToEOL.
@@ -146,7 +147,7 @@ _@(UnitTests SmartConsole traits) echoEvent: event@(SmartConsole KeyEvent traits
t@(UnitTests SmartConsole traits) echoEvents
[
SmartConsole new sessionDo: [| :console terminal |
- terminal: (Terminal newBasedOn: console).
+ terminal := (Terminal newBasedOn: console).
terminal ; 'Press keys and their event will be printed, quit with Esc\n'.
[
@@ -159,42 +160,39 @@ t@(UnitTests SmartConsole traits) echoEvents
_@(UnitTests SmartConsole traits) echoRawCursesEvents
[
CursesConsole new sessionDo: [| :console terminal |
- terminal: (Terminal newBasedOn: console).
+ terminal := (Terminal newBasedOn: console).
terminal ; 'Press keys and raw key codes will be printed, quit with Enter\n'.
- [| keyCode |
- keyCode: (console primitives nextEvent applyTo: {-1}).
- terminal ; (keyCode as: String) ; ' - 16r' ;
- (keyCode printString &radix: 16).
- console clearToEOL.
- terminal newLine.
- keyCode = 10 \/ [keyCode = 13]
- ] whileFalse
+ [| keyCode |
+ keyCode := console primitives nextEvent apply*, -1.
+ terminal ; (keyCode as: String) ; ' - 16r' ; (keyCode printString &radix: 16).
+ console clearToEOL.
+ terminal newLine.
+ keyCode = 10 \/ [keyCode = 13]
+ ] whileFalse
]
].
_@(UnitTests SmartConsole traits) echoRawWindowsEvents &unicode: unicode
[| available |
- available: False.
- [WindowsConsole isAvailable ifTrue: [available: True]]
- breakOn: Error.
+ available := False.
+ [WindowsConsole isAvailable ifTrue: [available := True]] breakOn: Error.
available ifFalse: [error: 'Windows console plugin not loaded or otherwise not available'. ^ Nil].
- unicode ifNil: [unicode: False].
+ unicode `defaultsTo: False.
WindowsConsole clone sessionDo: [| :c record dword |
c ; 'Printing out raw console events coming from Windows, quit with Esc\n'.
c ; 'Codepage returned by GetConsoleCP: ' ; Windows Kernel GetConsoleCP do printString ; '\n'.
- record: Windows INPUT_RECORD clone.
- dword: (ByteArray new &capacity: #[Windows DWORD byteSize]).
+ record := Windows INPUT_RECORD clone.
+ dword := ByteArray new &capacity: #[Windows DWORD byteSize].
[
[| method |
- unicode
- ifTrue: [method: Windows Kernel ReadConsoleInputW]
- ifFalse: [method: Windows Kernel ReadConsoleInputA].
- method applyTo: {c consoleIn. record. 1. dword}.
- record EventType = #[Windows KEY_EVENT]
- ] whileFalse.
+ method := unicode
+ ifTrue: [Windows Kernel ReadConsoleInputW]
+ ifFalse: [Windows Kernel ReadConsoleInputA].
+ method apply*, c consoleIn, record, 1, dword.
+ record EventType = #[Windows KEY_EVENT]] whileFalse.
"record printOn: c writer.
c newLine."

0 comments on commit 963c985

Please sign in to comment.