Christoph Thiede uploaded a new version of CollectionsTests to project The Trunk: http://source.squeak.org/trunk/CollectionsTests-ct.390.mcz
==================== Summary ====================
Name: CollectionsTests-ct.390 Author: ct Time: 20 May 2023, 5:43:42.758462 pm UUID: 19992341-2597-2d40-9a1d-d9d5b54680d5 Ancestors: CollectionsTests-ct.389, CollectionsTests-ct.356, CollectionsTests-ct.357
Complements Collections-ct.1036 (miscellaneous parsing improvements to HtmlReadWriter). Deduplicates and extends tests.
=============== Diff against CollectionsTests-ct.389 ===============
Item was changed: ----- Method: HtmlReadWriterTest>>setUp (in category 'running') ----- setUp
super setUp. + self setUpReadWriter. - readWriter := HtmlReadWriter new. html := ''. text := '' asText.!
Item was added: + ----- Method: HtmlReadWriterTest>>setUpReadWriter (in category 'running') ----- + setUpReadWriter + + ^ readWriter := HtmlReadWriter new!
Item was changed: ----- Method: HtmlReadWriterTest>>test01Emphasis (in category 'tests') ----- test01Emphasis
+ self testReadAndWrite: { - { '<b>Hello, World!!</b>'. 'Hello, World!!' asText addAttribute: TextEmphasis bold. '<b>Hello</b>, World!!'. 'Hello, World!!' asText addAttribute: TextEmphasis bold from: 1 to: 5. + }. + + self testRead: { + '<B>Hello</b>, World!!'. + 'Hello, World!!' asText addAttribute: TextEmphasis bold from: 1 to: 5. - } pairsDo: [:expectedHtml :expectedText | + '<b>Hello</B>, World!!'. + 'Hello, World!!' asText addAttribute: TextEmphasis bold from: 1 to: 5. + }.! - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. - - self convertText: expectedText. - self assert: expectedHtml equals: html].!
Item was changed: ----- Method: HtmlReadWriterTest>>test02Mixed (in category 'tests') ----- test02Mixed - "At the moment, the html code generation is kind of verbose..." + self testReadAndWrite: { - { '<b>Hello, </b><b><i>World!!</i></b>!!'. 'Hello, World!!!!' asText addAttribute: TextEmphasis bold from: 1 to: 13; addAttribute: TextEmphasis italic from: 8 to: 13. + }.! - } pairsDo: [:expectedHtml :expectedText | - - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. - - self convertText: expectedText. - self assert: expectedHtml equals: html].!
Item was changed: ----- Method: HtmlReadWriterTest>>test03FontTag (in category 'tests') ----- test03FontTag
+ self testReadAndWrite: { - { '<font color="#FFFF00">Hello, World!!</font>'. 'Hello, World!!' asText addAttribute: (TextColor color: Color yellow). '<font face="Accula" size="10.5">Hello, World!!</font>'. 'Hello, World!!' asText addAttribute: (TextFontReference toFont: (StrikeFont familyName: 'Accula' pointSize: 10.5)).
"Note that we cannot directly use both face/size and color in the same font tag because of how #openHtmlOn: works in fonts. Works in general, but just not in this test setup." '<font face="Accula" size="10.5"><font color="#FFFF00">Hello, World!!</font></font>'. 'Hello, World!!' asText addAttribute: (TextFontReference toFont: (StrikeFont familyName: 'Accula' pointSize: 10.5)); addAttribute: (TextColor color: Color yellow). + }. + + self testRead: { + '<font + color = "reD" >Hello, World!!</font>'. + 'Hello, World!!' asText + addAttribute: (TextColor color: Color red). + '<font color="reD">Hello, World!!</font>'. + 'Hello, World!!' asText + addAttribute: (TextColor color: Color red). - } pairsDo: [:expectedHtml :expectedText | + '<Font face=Accula size="10.5" color="#FFFF00">Hello, World!!</font>'. + 'Hello, World!!' asText + addAttribute: (TextColor color: Color yellow); + addAttribute: (TextFontReference toFont: (StrikeFont familyName: 'Accula' pointSize: 10.5)). - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. + '<font color="rgb(var(--r),1000,0)">Hello, World!!</span>'. + 'Hello, World!!' asText. + }! - self convertText: expectedText. - self assert: expectedHtml equals: html].!
Item was changed: ----- Method: HtmlReadWriterTest>>test04LineBreaks (in category 'tests') ----- test04LineBreaks
{ 'Hello, World!!<br> '. 'Hello, World!! ' asText.
'Hello, <b>World!!<br> </b>'. 'Hello, World!! ' asText addAttribute: TextEmphasis bold from: 8 to: 14. - } pairsDo: [:expectedHtml :expectedText | + 'Hello, <b>World<br> + !!</b>'. + 'Hello, World + !!' asText + addAttribute: TextEmphasis bold from: 8 to: 14. + } pairsDo: [:givenHtml :givenText | - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. + self testRead: givenHtml as: givenText. + self testWrite: givenText as: givenHtml. - self convertText: expectedText. - self assert: expectedHtml equals: html. self convertHtml: html. self convertText: text. + self assert: givenHtml equals: html]. + + self testRead: { + 'Hello<BR>World'. + 'Hello + World' asText + }.! - self assert: expectedHtml equals: html. - - - ].!
Item was changed: ----- Method: HtmlReadWriterTest>>test05Escaping (in category 'tests') ----- test05Escaping
+ self testReadAndWrite: { - { '<b>Morph>>#drawOn:</b>'. 'Morph>>#drawOn:' asText addAttribute: TextEmphasis bold. + }.! - } pairsDo: [:expectedHtml :expectedText | - - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. - - self convertText: expectedText. - self assert: expectedHtml equals: html].!
Item was changed: ----- Method: HtmlReadWriterTest>>test08MultilineCode (in category 'tests') ----- test08MultilineCode
+ self testReadAndWrite: { '<code> - { '<code> <pre>3 + 7. 3 > 4.</pre></code>' . Text string: '3 + 7. 3 > 4.' runs: (RunArray runs: #(13) values: { {TextDoIt evalString: '3 + 7. + 3 > 4. + ' } } ) + }.! - 3 > 4.' } } ) - } pairsDo: [:expectedHtml :expectedText | - - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. - - self convertText: expectedText. - self assert: expectedHtml equals: html].!
Item was changed: ----- Method: HtmlReadWriterTest>>test09StruckOut (in category 'tests') ----- test09StruckOut
+ self testReadAndWrite: { - { '<s>Hello, World!!</s>'. 'Hello, World!!' asText addAttribute: TextEmphasis struckOut. '<s>Hello</s>, World!!'. 'Hello, World!!' asText addAttribute: TextEmphasis struckOut from: 1 to: 5. + }.! - } pairsDo: [:expectedHtml :expectedText | - - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. - - self convertText: expectedText. - self assert: expectedHtml equals: html].!
Item was changed: ----- Method: HtmlReadWriterTest>>test10Underline (in category 'tests') ----- test10Underline
+ self testReadAndWrite: { - { '<u>Hello, World!!</u>'. 'Hello, World!!' asText addAttribute: TextEmphasis underlined. '<u>Hello</u>, World!!'. 'Hello, World!!' asText addAttribute: TextEmphasis underlined from: 1 to: 5. + }.! - } pairsDo: [:expectedHtml :expectedText | - - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. - - self convertText: expectedText. - self assert: expectedHtml equals: html].!
Item was changed: ----- Method: HtmlReadWriterTest>>test11Alignment (in category 'tests') ----- test11Alignment
+ self testReadAndWrite: { - { " '<center>Hello, World!!</center>'. 'Hello, World!!' asText addAttribute: TextAlignment centered. " '<div align=left>Hello, World!!</div>'. 'Hello, World!!' asText addAttribute: TextAlignment leftFlush.
'<div align=right>Hello, World!!</div>'. 'Hello, World!!' asText addAttribute: TextAlignment rightFlush.
'<div align=justify>Hello, World!!</div>'. 'Hello, World!!' asText addAttribute: TextAlignment justified. + }. + + self testRead: { + '<DIV ALIGN=RIGHT>Hello, World!!</DIV>'. + 'Hello, World!!' asText addAttribute: TextAlignment rightFlush. - } pairsDo: [:expectedHtml :expectedText | + '<div align="right">Hello, World!!</div>'. + 'Hello, World!!' asText addAttribute: TextAlignment rightFlush. + + '<div align = "justify">Hello, World!!</div>'. + 'Hello, World!!' asText addAttribute: TextAlignment justified. - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. + '<div align="center">Hello, World!!</div>'. + 'Hello, World!!' asText addAttribute: TextAlignment centered. + }.! - self convertText: expectedText. - self assert: expectedHtml equals: html].!
Item was changed: ----- Method: HtmlReadWriterTest>>test12AlignmentMixed (in category 'tests') ----- test12AlignmentMixed
+ self testReadAndWrite: { - { '<center>Hello, <i>World!!</i></center>'. 'Hello, World!!' asText addAttribute: TextAlignment centered; addAttribute: TextEmphasis italic from: 8 to: 13. + }.! - } pairsDo: [:expectedHtml :expectedText | - - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs. - - self convertText: expectedText. - self assert: expectedHtml equals: html].!
Item was changed: ----- Method: HtmlReadWriterTest>>test13SpanTag (in category 'tests') ----- test13SpanTag
+ self testRead: { + '<span style="width: 100px;color:#FFFF00; font-style : bold; font-size: 10px">Hello, World!!</span>'. - { - '<span style="width: 100px;color:#FFFF00; font-style: bold; font-size: 10px">Hello, World!!</span>'. 'Hello, World!!' asText addAttribute: (TextColor color: Color yellow); + addAttribute: TextEmphasis bold. - addAttribute: (TextEmphasis bold). - } pairsDo: [:expectedHtml :expectedText | + '<span style="width: 100px; incorrectly-empty-tag:; font-style: bold">Hello, World!!</span>'. + 'Hello, World!!' asText + addAttribute: TextEmphasis bold. + + '<span style="width: 100px; color:rgb(var(--r),1000,0); font-style: bold">Hello, World!!</span>'. + 'Hello, World!!' asText + addAttribute: TextEmphasis bold. + + '<span style="Color:Red">Hello, World!!</span>'. + 'Hello, World!!' asText + addAttribute: (TextColor color: Color red). + + '<span style="">Hello, World!!</span>'. + 'Hello, World!!' asText. + + '<span style=>Hello, World!!</span>'. + 'Hello, World!!' asText. + + '<span style>Hello, World!!</span>'. + 'Hello, World!!' asText. + + '<SPAN STYLE = "font-style: bold">Hello, World!!</SPAN>'. + 'Hello, World!!' asText + addAttribute: TextEmphasis bold. + }! - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs]!
Item was changed: ----- Method: HtmlReadWriterTest>>test14NumericalHtmlEntities (in category 'tests') ----- test14NumericalHtmlEntities
+ self testRead: { - { '.!'. '.!!' asText. + }.! - } pairsDo: [:expectedHtml :expectedText | - - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string]!
Item was changed: ----- Method: HtmlReadWriterTest>>test15NestedTagsStillEndBefore (in category 'tests') ----- test15NestedTagsStillEndBefore
+ self testRead: { - { '<span><i>Hallo</i> welt</span>'. 'Hallo welt' asText addAttribute: TextEmphasis italic from: 1 to: 5. + }.! - } pairsDo: [:expectedHtml :expectedText | - self convertHtml: expectedHtml. - self assert: expectedText string equals: text string. - self assert: expectedText runs equals: text runs]!
Item was changed: ----- Method: HtmlReadWriterTest>>test16ImgTag (in category 'tests') ----- test16ImgTag <timeout: 10>
| imgUrl imgExpression formFromUrl formFromExpression | imgUrl := 'https://squeak.org/img/downloads/image.png'. imgExpression := 'Form dotOfSize: 12@12 color: Color green'. self ensureSecureInternetConnection. formFromUrl := (Smalltalk classNamed: 'WebClient') ifNotNil: [:client | Form fromBinaryStream: (client httpGet: imgUrl) content asByteArray readStream]. formFromExpression := Compiler evaluate: imgExpression. RealEstateAgent scaleFactor = 1.0 ifFalse: [ formFromUrl := formFromUrl scaledToSize: (formFromUrl extent * RealEstateAgent scaleFactor). formFromExpression := formFromExpression scaledToSize: (formFromExpression extent * RealEstateAgent scaleFactor)]. + ({ + []. imgUrl. formFromUrl. + []. 'fantasy:wonderland/alice'. readWriter imagePlaceholder. + + []. 'code://' , imgExpression. formFromExpression. + []. 'code://Object'. readWriter imagePlaceholder. + []. 'code://' , imgExpression , ';'. readWriter imagePlaceholder. + } groupsCollect: [:prepareBlock :src :expectedForm | { + 'Hello <img src="{1}"> World' format: { src }. - { - 'Hello <img src="{1}"> World' format: { imgUrl }. ('Hello {1} World' format: { Character startOfHeader }) asText + addAttribute: expectedForm asTextAnchor from: 7 to: 7; - addAttribute: formFromUrl asTextAnchor from: 7 to: 7; addAttribute: (TextColor color: Color transparent) from: 7 to: 7. + prepareBlock}]) + + , ({ + 'Hello <img src="code://{1}"></img> World' format: { imgExpression }. - - 'Hello <img src="code://{1}"> World' format: { imgExpression }. ('Hello {1} World' format: { Character startOfHeader }) asText addAttribute: formFromExpression asTextAnchor from: 7 to: 7; addAttribute: (TextColor color: Color transparent) from: 7 to: 7. + 'Hello <img src="code://{1}"/> World' format: { imgExpression }. + ('Hello {1} World' format: { Character startOfHeader }) asText + addAttribute: formFromExpression asTextAnchor from: 7 to: 7; + addAttribute: (TextColor color: Color transparent) from: 7 to: 7. - } pairsDo: [:expectedHtml :expectedText | + 'Hello <IMG SRC = "code://{1}"> World' format: { imgExpression }. + ('Hello {1} World' format: { Character startOfHeader }) asText + addAttribute: formFromExpression asTextAnchor from: 7 to: 7; + addAttribute: (TextColor color: Color transparent) from: 7 to: 7. + + } pairsCollect: [:html :expectedText | {html. expectedText}]) + collect: [:spec | + | html expectedText prepareBlock | + html := spec first. + expectedText := spec second. + prepareBlock := spec at: 3 ifAbsent: []. + + self setUpReadWriter. + prepareBlock value. + self convertHtml: html. - self convertHtml: expectedHtml. self assert: expectedText string equals: text string. expectedText runs with: text runs do: [:expectedAttributes :actualAttributes | expectedAttributes with: actualAttributes do: [:expectedAttribute :actualAttribute | self assert: (expectedAttribute = actualAttribute or: [ ((expectedAttribute respondsTo: #anchoredMorph) and: [actualAttribute respondsTo: #anchoredMorph]) and: [(expectedAttribute anchoredMorph "aForm" unhibernate; bits) = (actualAttribute anchoredMorph "aForm" unhibernate; bits)] ]) ]]].!
Item was added: + ----- Method: HtmlReadWriterTest>>test19ExcludedTags (in category 'tests') ----- + test19ExcludedTags + + { + 'A<b>B<script>C<i>D</i>E</script>F</b>G'. + 'A<b>BF</b>G' asTextFromHtml. + + 'A<script>B<style>C</style>D</script>E'. + 'AE' asText. + } pairsDo: [:expectedHtml :expectedText | + + self convertHtml: expectedHtml. + self assert: expectedText string equals: text string. + self assert: expectedText runs equals: text runs]!
Item was added: + ----- Method: HtmlReadWriterTest>>test20Link (in category 'tests') ----- + test20Link + + self testReadAndWrite: { + '<a href="https://squeak.org">hErE</a>'. + 'hErE' asText addAttribute: (TextURL url: 'https://squeak.org'). + + '<a href="code://World explore">hErE</a>'. + 'hErE' asText addAttribute: (TextURL url: 'code://World explore'). + }. + + self testRead: { + '<a href = + "https://squeak.org%22%3EhErE</a>'. + 'hErE' asText addAttribute: (TextURL url: 'https://squeak.org'). + + '<a href=https://squeak.org>hErE</a>'. + 'hErE' asText addAttribute: (TextURL url: 'https://squeak.org'). + + '<a href="https://www.google.com/search?q="modern, open-source Smalltalk"">hErE</a>'. + 'hErE' asText addAttribute: (TextURL url: 'https://www.google.com/search?q=%22modern, open-source Smalltalk"'). + + '<alt href="https://squeak.org">hi</alt>'. "also begins with <a" + 'hi' asText. + }.!
Item was added: + ----- Method: HtmlReadWriterTest>>test21BreakLines (in category 'tests') ----- + test21BreakLines + + { + ' a b '. + 'a b' asText. + ' a b ' asText. + + ' a + + <b> b </b> + '. + 'a b' asText addAttribute: TextEmphasis bold from: 3 to: 3. + ' a + + b + ' asText addAttribute: TextEmphasis bold from: 6 to: 8. + + "breakLines is preserved after <pre> tag" + ' a <pre> b + </pre> c '. + 'a + b + + c' asText. + ' a + b + + c ' asText. + + "linebreaks in tags are NOT ignored" + 'a<s + pan>b</span>c'. + 'abc' asText addAttribute: TextEmphasis struckOut from: 2 to: 2. + 'abc' asText addAttribute: TextEmphasis struckOut from: 2 to: 2. + } groupsDo: [:givenHtml :expectedBreakLines :expectedNoBreakLines | + + self setUpReadWriter breakLines: true. + self testRead: givenHtml as: expectedBreakLines. + self setUpReadWriter breakLines: false. + self testRead: givenHtml as: expectedNoBreakLines].!
Item was added: + ----- Method: HtmlReadWriterTest>>test22LinebreakAcceptance (in category 'tests') ----- + test22LinebreakAcceptance + + self testRead: { + '<div>Hi all!!<div></div><div><br></div><div><span>Squeak.</span></div><div><span>Is.</span><br></div><div><span><b>Great.</b></span></div></div>'. + 'Hi all!! + + Squeak. + Is. + Great.' asText addAttribute: TextEmphasis bold from: 22 to: 27. + + '<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + </head> + <body> + <div class="WordSection1"> + <p>Hi all,</p> + <p><o:p> </o:p></p> + <p>You are <i>so</i> right!!</p> + </div> + </body>'. + 'Hi all, + + You are so right!!' asText addAttribute: TextEmphasis italic from: 19 to: 20. + + '<div> + <p>I agree!!</p> + <p><br> + </p> + <p>Best,</p> + <p>Everyone</p> + </div> + <hr> + <div>signature</div>'. + 'I agree!! + + Best, + Everyone + + signature' asText + }.!
Item was added: + ----- Method: HtmlReadWriterTest>>testRead: (in category 'running') ----- + testRead: pairs + + pairs pairsDo: [:givenHtml :expectedText | + self testRead: givenHtml as: expectedText].!
Item was added: + ----- Method: HtmlReadWriterTest>>testRead:as: (in category 'running') ----- + testRead: givenHtml as: expectedText + + self convertHtml: givenHtml. + self assert: expectedText string equals: text string. + self assert: expectedText runs equals: text runs.!
Item was added: + ----- Method: HtmlReadWriterTest>>testReadAndWrite: (in category 'running') ----- + testReadAndWrite: pairs + + pairs pairsDo: [:givenHtml :givenText | + self testRead: givenHtml as: givenText. + self testWrite: givenText as: givenHtml].!
Item was added: + ----- Method: HtmlReadWriterTest>>testWrite:as: (in category 'running') ----- + testWrite: givenText as: expectedHtml + + self convertText: givenText. + self assert: expectedHtml equals: html.!
packages@lists.squeakfoundation.org