Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,155 +1,160 @@
Class {
#name : #AlbTextEditorSegmentCollectorExamples,
#superclass : #Object,
#name : #AlbTextEditorSegmentCollectorTest2,
#superclass : #TestCase,
#instVars : [
'largeFile'
],
#category : #'Album-Examples-Editor'
}

{ #category : #private }
AlbTextEditorSegmentCollectorExamples >> deleteLargeFile [
AlbTextEditorSegmentCollectorTest2 >> deleteLargeFile [

largeFile ifNotNil:
[ largeFile ensureDelete.
largeFile := nil ].
]

{ #category : #accessing }
AlbTextEditorSegmentCollectorExamples >> largeFile [
<gtExample>

^largeFile ifNil:
[ largeFile := FileReference newTempFilePrefix: 'BlRopeableCollectionFileExamples-' suffix: '-largeFile'.
largeFile writeStreamDo: [ :stream |
1 to: 10000 do: [ :l |
1 to: 9 do: [ :i |
stream << (((l-1)*10 + i-1) printPaddedWith: $0 to: 10) ].
stream << 'abcdefghi'; lf. ] ].
largeFile ].
AlbTextEditorSegmentCollectorTest2 >> largeFile [

^ largeFile ifNil: [
largeFile := FileSystem memory / 'largeFile.txt'.
largeFile writeStreamDo: [ :stream |
1 to: 10000 do: [ :l |
1 to: 9 do: [ :i | stream << (l - 1 * 10 + i - 1 printPaddedWith: $0 to: 10) ].
stream
<< 'abcdefghi';
lf ] ].
largeFile ]
]

{ #category : #accessing }
AlbTextEditorSegmentCollectorExamples >> largeFileRope [
AlbTextEditorSegmentCollectorTest2 >> largeFileRope [

^ BlRopedText file: self largeFile
"self largeFile contents asRopedText"

]

{ #category : #accessing }
AlbTextEditorSegmentCollectorTest2 >> segmentCollector [
"Answer a segment collector whose cache limit is small enough that the large file (10000 lines) holds more than 2.62 times the cache limit, as required by the tests"

^ self textEditor segmentCollector
cacheLimit: 1000;
yourself
]

{ #category : #private }
AlbTextEditorSegmentCollectorTest2 >> tearDown [

self deleteLargeFile.
super tearDown
]

{ #category : #examples }
AlbTextEditorSegmentCollectorExamples >> segmentAt142 [
AlbTextEditorSegmentCollectorTest2 >> testSegmentAt142 [
"Retrieve the segment at 1.42 times the cache limit.
This tests accessing the cache outside its initial contents.
Assumptions:
- The test file size has at least twice the number of lines in the cache"
<gtExample>
<after: #deleteLargeFile>

| segmentCollector limit expected actual |

segmentCollector := self segmentCollector.
limit := (segmentCollector cacheLimit * 1.42) rounded.
expected := ((limit - 1) * 10) printPaddedWith: $0 to: 10.
actual := (segmentCollector segmentAt: limit) asString copyFrom: 1 to: 10.
actual := (segmentCollector segmentAt: limit) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.
]

{ #category : #examples }
AlbTextEditorSegmentCollectorExamples >> segmentAt200and262 [
AlbTextEditorSegmentCollectorTest2 >> testSegmentAt200and262 [
"Retrieve the segment at line 200, followed by the segment at line 262.
This tests re-using part of the previously cached items where the index of the segments collection is not the same as the line number"
<gtExample>
<after: #deleteLargeFile>

| segmentCollector expected actual limit |

segmentCollector := self segmentCollector.

limit := (segmentCollector cacheLimit * 2) rounded.
expected := ((limit - 1) * 10) printPaddedWith: $0 to: 10.
actual := (segmentCollector segmentAt: limit) asString copyFrom: 1 to: 10.
actual := (segmentCollector segmentAt: limit) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.

limit := (segmentCollector cacheLimit * 2.62) rounded.
expected := ((limit - 1) * 10) printPaddedWith: $0 to: 10.
actual := (segmentCollector segmentAt: limit) asString copyFrom: 1 to: 10.
actual := (segmentCollector segmentAt: limit) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.

]

{ #category : #examples }
AlbTextEditorSegmentCollectorExamples >> segmentAt242and42 [
AlbTextEditorSegmentCollectorTest2 >> testSegmentAt242and42 [
"Retrieve the segment at line 2.42 times the cache limit, followed by the segment at line 42.
This tests #computeBackwardAt:."
<gtExample>
<after: #deleteLargeFile>

| expected actual segmentCollector limit |

segmentCollector := self segmentCollector.

"Retrieve several segments leading up to 2.42 times to populate the map entries"
expected := '0000000410'.
actual := (segmentCollector segmentAt: 42) asString copyFrom: 1 to: 10.
actual := (segmentCollector segmentAt: 42) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.

limit := (segmentCollector cacheLimit * 1.42) rounded.
expected := ((limit - 1) * 10) printPaddedWith: $0 to: 10.
actual := (segmentCollector segmentAt: limit) asString copyFrom: 1 to: 10.
actual := (segmentCollector segmentAt: limit) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.

limit := (segmentCollector cacheLimit * 2.42) rounded.
expected := ((limit - 1) * 10) printPaddedWith: $0 to: 10.
actual := (segmentCollector segmentAt: limit) asString copyFrom: 1 to: 10.
actual := (segmentCollector segmentAt: limit) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.

limit := (segmentCollector cacheLimit * 0.42) rounded.
expected := ((limit - 1) * 10) printPaddedWith: $0 to: 10.
actual := (segmentCollector segmentAt: limit) asString copyFrom: 1 to: 10.
actual := (segmentCollector segmentAt: limit) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.

]

{ #category : #examples }
AlbTextEditorSegmentCollectorExamples >> segmentAt42 [
AlbTextEditorSegmentCollectorTest2 >> testSegmentAt42 [
"Retrieve the segment at line 42.
Assumes the cache limit is always greater than 42."
<gtExample>
<after: #deleteLargeFile>

| expected actual |

expected := '0000000410'.
actual := (self segmentCollector segmentAt: 42) asString copyFrom: 1 to: 10.
actual := (self segmentCollector segmentAt: 42) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.
]

{ #category : #examples }
AlbTextEditorSegmentCollectorExamples >> segmentAt80and120 [
AlbTextEditorSegmentCollectorTest2 >> testSegmentAt80and120 [
"Retrieve the segment at 0.8 times the cache limit, followed by the segment at 1.2 times the cache limit.
This tests re-using part of the previously cached items"
<gtExample>
<after: #deleteLargeFile>

| segmentCollector expected actual limit |

segmentCollector := self segmentCollector.

limit := (segmentCollector cacheLimit * 0.8) rounded.
expected := (limit - 1 * 10) printPaddedWith: $0 to: 10.
actual := (segmentCollector segmentAt: limit) asString copyFrom: 1 to: 10.
actual := (segmentCollector segmentAt: limit) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.

limit := (segmentCollector cacheLimit * 1.2) rounded.
expected := (limit - 1 * 10) printPaddedWith: $0 to: 10.
actual := (segmentCollector segmentAt: limit) asString copyFrom: 1 to: 10.
actual := (segmentCollector segmentAt: limit) text asString copyFrom: 1 to: 10.
self assert: actual equals: expected.

]

{ #category : #accessing }
AlbTextEditorSegmentCollectorExamples >> segmentCollector [

^ self textEditor segmentCollector
]

{ #category : #accessing }
AlbTextEditorSegmentCollectorExamples >> textEditor [
AlbTextEditorSegmentCollectorTest2 >> textEditor [

^ AlbTextEditor new text: self largeFileRope
]
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Class {
#name : #AlbTextEditorSegmentCollectorExamples2,
#name : #AlbTextEditorSegmentCollectorTest3,
#superclass : #TestCase,
#category : #'Album-Examples-Editor'
}

{ #category : #examples }
AlbTextEditorSegmentCollectorExamples2 >> testRetrieveLimitPlusOne [
AlbTextEditorSegmentCollectorTest3 >> testRetrieveLimitPlusOne [

| string limit editor collector |
limit := 500.
Expand All @@ -31,7 +31,7 @@ AlbTextEditorSegmentCollectorExamples2 >> testRetrieveLimitPlusOne [
]

{ #category : #examples }
AlbTextEditorSegmentCollectorExamples2 >> testRetrieveWithinLimit [
AlbTextEditorSegmentCollectorTest3 >> testRetrieveWithinLimit [

<gtExample>
| string cacheLimit limit editor collector |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Class {
#name : #AlbTextEditorSurroundMapExamples,
#name : #AlbTextEditorSurroundMapTest,
#superclass : #TestCase,
#category : #'Album-Examples-Editor'
}

{ #category : #examples }
AlbTextEditorSurroundMapExamples >> surroundSet [
AlbTextEditorSurroundMapTest >> surroundSet [

| definitions |

Expand All @@ -24,7 +24,7 @@ AlbTextEditorSurroundMapExamples >> surroundSet [
]

{ #category : #examples }
AlbTextEditorSurroundMapExamples >> testSurroundSetClosing [
AlbTextEditorSurroundMapTest >> testSurroundSetClosing [

| opening |
opening := self surroundSet
Expand All @@ -36,7 +36,7 @@ AlbTextEditorSurroundMapExamples >> testSurroundSetClosing [
]

{ #category : #examples }
AlbTextEditorSurroundMapExamples >> testSurroundSetClosingAbsent [
AlbTextEditorSurroundMapTest >> testSurroundSetClosingAbsent [

| definition |
definition := self surroundSet
Expand All @@ -48,7 +48,7 @@ AlbTextEditorSurroundMapExamples >> testSurroundSetClosingAbsent [
]

{ #category : #examples }
AlbTextEditorSurroundMapExamples >> testSurroundSetOpeningAbsent [
AlbTextEditorSurroundMapTest >> testSurroundSetOpeningAbsent [

| definition |

Expand All @@ -62,7 +62,7 @@ AlbTextEditorSurroundMapExamples >> testSurroundSetOpeningAbsent [
]

{ #category : #examples }
AlbTextEditorSurroundMapExamples >> testSurroundSetOpeningConditionRejects [
AlbTextEditorSurroundMapTest >> testSurroundSetOpeningConditionRejects [

| definition |
definition := self surroundSet
Expand All @@ -75,7 +75,7 @@ AlbTextEditorSurroundMapExamples >> testSurroundSetOpeningConditionRejects [
]

{ #category : #examples }
AlbTextEditorSurroundMapExamples >> testSurroundSetOpeningPresent [
AlbTextEditorSurroundMapTest >> testSurroundSetOpeningPresent [

| closing |

Expand Down