groovy

GString vs String equality in collections

Details

  • Type: Sub-task Sub-task
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.1-rc-3
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

GStrings are one of the big groovy features. But there current equals behavior in collections makes them useless for many use cases. Very confusing is also the behavioral difference between lists and other collections.

All tests fail except the first one. (Tests run against rev 9408)

class StringVersusGStringEqualsInCollections extends GroovyTestCase {

    String string
    GString gString

    void setUp() {
        def g = 'g'
        string = 'groovy'
        gString = "${g}roovy"
    }

    void testEqualsInList() {
        assertEquals([string], [gString])
    }

    void testEqualsInSet() {
        assertEquals([string] as Set, [gString] as Set)
    }

    void testKeyEqualsInMap() {
        String someValue = 'somevalue'
        Map stringMap = [(string): someValue]
        Map gStringMap = [(gString): someValue]
        assertEquals(stringMap, gStringMap)
    }

    void testValueEqualsInMap() {
        String someKey = 'somekey'
        Map stringMap = [(someKey): string]
        Map gStringMap = [(someKey): gString]
        assertEquals(stringMap, gStringMap)
    }
}

Issue Links

Activity

Hide
Hans Dockter added a comment -

I forget to set 'fix for' to 1.1

Show
Hans Dockter added a comment - I forget to set 'fix for' to 1.1

People

Vote (12)
Watch (6)

Dates

  • Created:
    Updated: