David T. Lewis uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-dtl.293.mcz ==================== Summary ==================== Name: CollectionsTests-dtl.293 Author: dtl Time: 19 July 2018, 12:41:00.027981 am UUID: 4671abff-5dac-4ad8-b907-7afbbdf39fe6 Ancestors: CollectionsTests-cmm.292 Unit tests to cover text creation from a fileIn or from parameters when the length of the text string does not match the length of the associated runarray. These tests cover the enhancement from Collections-kks.803 (treated inbox, and included in Collections-dtl.802 in trunk). =============== Diff against CollectionsTests-cmm.292 =============== Item was added: + ----- Method: TextTest>>testSetStringSetRunsChecking (in category 'tests runs checking') ----- + testSetStringSetRunsChecking + "Normal case of creating a Text from a string and a run array with matching size" + + | aString runs aText newText | + aString := 'The best way to predict the future'. + runs := (RunArray runs: #(4 4 8 7 5 6) values: ((Array new: 6) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); yourself)). + + self assert: aString size = runs size. + + aText := (Text string: 'The best way to predict the future' runs: (RunArray runs: #(4 4 8 7 5 6) values: ((Array new: 6) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); yourself))). + + newText := Text basicNew setString: aString setRunsChecking: runs. + self assert: newText equals: aText. + self assert: newText runs size = aString size. + self assert: runs equals: newText runs. + self assert: 6 equals: aText runs values size. + self assert: 6 equals: newText runs values size. + + + ! Item was added: + ----- Method: TextTest>>testSetStringSetRunsCheckingLongRuns (in category 'tests runs checking') ----- + testSetStringSetRunsCheckingLongRuns + "Creating text from a string and a long run array should create a valid Text instance, + and should retain text styling if possible." + + | aString aText newText lastRunTooLong oneRunTooMany | + aString := 'The best way to predict the future'. + lastRunTooLong := (RunArray runs: #(4 4 8 7 5 100) values: ((Array new: 6) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); yourself)). + + self deny: aString size = lastRunTooLong size. + + oneRunTooMany := (RunArray runs: #(4 4 8 7 5 6 4) values: ((Array new: 7) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 7 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself)). + + self deny: aString size = oneRunTooMany size. + + aText := (Text string: 'The best way to predict the future' runs: (RunArray runs: #(4 4 8 7 5 6) values: ((Array new: 6) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); yourself))). + + self assert: 6 equals: aText runs values size. + + newText := Text basicNew setString: aString setRunsChecking: lastRunTooLong. + self assert: newText equals: aText. + self assert: newText runs size = aString size. + self assert: 6 equals: newText runs values size. + + newText := Text basicNew setString: aString setRunsChecking: oneRunTooMany. + self assert: newText equals: aText. + self assert: newText runs size = aString size. + self assert: 6 equals: newText runs values size. + + + + ! Item was added: + ----- Method: TextTest>>testSetStringSetRunsCheckingShortRuns (in category 'tests runs checking') ----- + testSetStringSetRunsCheckingShortRuns + "Creating text from a string and a short run array should create a valid Text instance, + and should retain text styling if possible." + + | aString aText newText lastRunTooShort missingLastRun | + aString := 'The best way to predict the future'. + lastRunTooShort := (RunArray runs: #(4 4 8 7 5 1) values: ((Array new: 6) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); yourself)). + + self deny: aString size = lastRunTooShort size. + + missingLastRun := (RunArray runs: #(4 4 8 7 5) values: ((Array new: 5) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); yourself)). + + self deny: aString size = missingLastRun size. + + aText := (Text string: 'The best way to predict the future' runs: (RunArray runs: #(4 4 8 7 5 6) values: ((Array new: 6) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); yourself))). + + self assert: 6 equals: aText runs values size. + + "Compensate for short run array, either by adding a run or by extending length + of the last run. In either case, the run array should have size of 6 or greater, not + size 1 as would be the case if the text formatting had been discarded." + newText := Text basicNew setString: aString setRunsChecking: lastRunTooShort. + self assert: newText equals: aText. + self assert: newText runs size = aString size. + self assert: newText runs values size >= 6. + self assert: 7 equals: newText runs values size. "add one run to account for missing run length" + + newText := Text basicNew setString: aString setRunsChecking: missingLastRun. + self assert: newText equals: aText. "n.b. Two Texts are considered equal if they have the same characters" + self assert: newText runs size = aString size. + self assert: 6 equals: newText runs values size. + + + ! Item was added: + ----- Method: TextTest>>testWriteReadChunk (in category 'tests fileIn/Out') ----- + testWriteReadChunk + "Create a text from string and runs with matching lenghts. Verify that writing to + chunk format and reading from that chunk results in a copy of the original text." + + | aString runs aText chunk readFromChunk | + aString := 'The best way to predict the future'. + runs := (RunArray runs: #(4 4 8 7 5 6) values: ((Array new: 6) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); yourself)). + + self assert: aString size = runs size. + aText := Text basicNew setString: aString setRunsChecking: runs. + chunk := '' writeStream nextChunkPutWithStyle: aText; yourself; contents. + readFromChunk := UTF8TextConverter new nextChunkTextFromStream: (ReadStream on: chunk). + + self assert: readFromChunk equals: aText. + self assert: readFromChunk runs size = aString size. + self assert: runs equals: readFromChunk runs. + self assert: 6 equals: aText runs values size. + self assert: 6 equals: readFromChunk runs values size. + ! Item was added: + ----- Method: TextTest>>testWriteReadChunkShortRunCount (in category 'tests fileIn/Out') ----- + testWriteReadChunkShortRunCount + "Create a text from string and runs, where the string length is less than the + runs length. This is a condition that might occur if a chunk fileout was edited + by hand, leaving runs that extend beyond the bounds of the run array. In this + case, the fileIn should result in a reasonable Text instance without errors related + to the runs that exceed the string length." + + | aString runs aText chunk readFromChunk | + aString := 'The best way to predict'. " the future". + runs := (RunArray runs: #(4 4 8 7 5) values: ((Array new: 5) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); yourself)). + + self deny: aString size = runs size. + aText := Text basicNew setString: aString setRunsChecking: runs. + chunk := '' writeStream nextChunkPutWithStyle: aText; yourself; contents. + readFromChunk := UTF8TextConverter new nextChunkTextFromStream: (ReadStream on: chunk). + + self assert: readFromChunk equals: aText. + self assert: readFromChunk runs size = aString size. + self assert: readFromChunk runs size > 1. + self assert: 4 equals: aText runs values size. + self assert: 4 equals: readFromChunk runs values size. + ! Item was added: + ----- Method: TextTest>>testWriteReadChunkShortRunLength (in category 'tests fileIn/Out') ----- + testWriteReadChunkShortRunLength + "Create a text from string and runs, where the run length is less than the string + length. The fileIn should result in a reasonable Text instance without errors related + to the run length mismatch." + + | aString runs aText chunk readFromChunk | + aString := 'The best way to predict the future'. + runs := (RunArray runs: #(4 4 8 7 5 1) values: ((Array new: 6) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); yourself)). + + self deny: aString size = runs size. + aText := Text basicNew setString: aString setRunsChecking: runs. + chunk := '' writeStream nextChunkPutWithStyle: aText; yourself; contents. + readFromChunk := UTF8TextConverter new nextChunkTextFromStream: (ReadStream on: chunk). + + self assert: readFromChunk equals: aText. + self assert: readFromChunk runs size = aString size. + self assert: readFromChunk runs size > 1. + self assert: aText runs values size equals: readFromChunk runs values size. + ! Item was added: + ----- Method: TextTest>>testWriteReadChunkShortString (in category 'tests fileIn/Out') ----- + testWriteReadChunkShortString + "Create a text from string and runs, where the run entries are fewer than required + to match the string length. The fileIn should result in a reasonable Text instance + without errors related to the run length mismatch." + + | aString runs aText chunk readFromChunk | + aString := 'The best way to predict the future'. + runs := (RunArray runs: #(4 4 8 7 5 6) values: ((Array new: 6) at: 1 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 1; yourself); yourself); at: 2 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 3 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 3; yourself); yourself); at: 4 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); at: 5 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 4; yourself); yourself); at: 6 put: ((Array new: 1) at: 1 put: (TextFontChange basicNew instVarAt: 1 put: 2; yourself); yourself); yourself)). + + self assert: aString size = runs size. + aText := Text basicNew setString: aString setRunsChecking: runs. + chunk := '' writeStream nextChunkPutWithStyle: aText; yourself; contents. + readFromChunk := UTF8TextConverter new nextChunkTextFromStream: (ReadStream on: chunk). + + self assert: readFromChunk equals: aText. + self assert: readFromChunk runs size = aString size. + self assert: readFromChunk runs size > 1. + self assert: aText runs values size equals: readFromChunk runs values size. + ! |
Free forum by Nabble | Edit this page |