Thanks Sven. cheers -ben On Tue, Mar 7, 2017 at 2:43 AM, Sven Van Caekenberghe <s...@stfx.eu> wrote: > Ben, > > I tried to avoid #isString and #isSymbol and I thought it was clear that > #assert:equals: used #= but I agree that I could be more explicit. Here is > the changed version of the unit test (.2 of slice): > > testConcatenationIsSymbol > "Concatenating 2 symbols results in another symbol" > self assert: (#foo , #bar) isSymbol. > self assert: (#foo , #bar) == #foobar. > > "Concatenating the empty Symbol does not change a Symbol" > self assert: (#foo , emptySymbol) == #foo. > self assert: (emptySymbol , #foo) == #foo. > > "Strings and Symbols can still be mixed, the receiver determines the > result type" > "Symbol receiver gives Symbol result" > self assert: (#foo , 'bar') isSymbol. > self assert: (#foo , 'bar') == #foobar.
> "String receiver gives String result" > self assert: ('foo' , #bar) isString. > self assert: ('foo' , #bar) = 'foobar'. > "Strings and Symbols still compare content-wise" > self assert: ('foo' , #bar) = #foobar. > "But Strings and Symbols are not identical" > self deny: ('foo' , #bar) == #foobar. > > >> On 6 Mar 2017, at 15:18, Ben Coman <b...@openinworld.com> wrote: >> >> On Mon, Mar 6, 2017 at 9:21 PM, Sven Van Caekenberghe <s...@stfx.eu> wrote: >>> >>>> On 6 Mar 2017, at 14:12, Ben Coman <b...@openinworld.com> wrote: >>>> >>>> >>>> >>>> On Mon, Mar 6, 2017 at 5:54 PM, Sven Van Caekenberghe <s...@stfx.eu> wrote: >>>> Here is a concrete proposal: >>>> >>>> https://pharo.fogbugz.com/f/cases/19802/Make-sure-Symbol-concatenation-results-in-a-Symbol-not-a-String >>>> >>>> This gives the following assertions: >>>> >>>> "Concatenating 2 symbols results in abother symbol" >>>> self assert: (#foo , #bar) == #foobar. >>>> >>>> "Concatenating the empty symbol does not change a symbol" >>>> self assert: (#foo, emptySymbol) == #foo. >>>> self assert: (emptySymbol, #foo) == #foo. >>>> >>>> "Strings and symbols can still be mixed, the receiver determines >>>> the result type" >>>> "Symbol receiver gives symbol result" >>>> self assert: (#foo , 'bar') == #foobar. >>>> "String receiver gives string result" >>>> self deny: ('foo' , #bar) == #foobar. >>>> self assert: ('foo' , #bar) equals: #foobar. >>>> self assert: ('foo' , #bar) equals: 'foobar'. >>>> >>>> >>>> Those last two seem contradictory. >>> >>> No, Symbols and String can be used interchangeably in Pharo in lots of >>> contexts. Particularly when comparing them, it makes no difference, all the >>> following are/have always been true, independent of this change: >>> >>> #foo = 'foo' >>> 'foo' = #foo >>> #foo = #foo >>> 'foo' = 'foo' >> >> Ah-ha... gotchya. always something more to learn. >> >> So those last three lines a testing that it is a String? >> This meaning is pretty well hidden in the implicit behaviour. >> Why not just... >> self assert: (#foo , 'bar') isString >> which seems to better "says what it means" >> >> If such is poor form in general, >> I'm curious to what degree such rules may be relaxed for unit tests. >> Could it be considered something like premature optimisation >> to make the test too generic?? If isString latter causes a problem later, >> deal with it then. >> >> ==== >> On another slightly different point, >> this might be one case where #assert:#equals is less clear than using "=" >> >> Its also easy to mis-think the following is contradictory >>>> self deny: ('foo' , #bar) == #foobar. >>>> self assert: ('foo' , #bar) equals: #foobar. >> >> where the alternative here makes the distinction more clear... >> self deny: ('foo' , #bar) == #foobar. >> self assert: ('foo' , #bar) = #foobar. >> >> >> cheers -ben > >