tanob/GrooBe

BUG comparing Strings and Numbers

Opened this issue · 0 comments

import com.github.tanob.groobe.GrooBe

class GrooBeFailingTests extends GroovyTestCase {

    static {
        GrooBe.activate()
    }

    void testShouldBeBetweenStrings() {
        def string1 = "My String A"
        def string1AsGString = "$string1"
        def string1AsMultiline = """$string1"""

        def sameStrings = [string1, string1AsGString, string1AsMultiline]

        // using Groovy simple assertions, they're all equals
        sameStrings.each { left ->
            sameStrings.each { right ->
                assert left == right : "\n\t'$left' [${left.class.simpleName}] should be equals to\n\t'$right' [${right.class.simpleName}]"
            }
        }

        // GrooBe fails because GStrings ARE NOT Strings
        // http://groovy.codehaus.org/Strings+and+GString
        sameStrings.each { left ->
            sameStrings.each { right ->
                left.shouldBe right, "\n\t'$left' [${left.class.simpleName}] should be equals to\n\t'$right' [${right.class.simpleName}]"
            }
        }
    }

    void testShouldBeBetweenNumbers() {
        def zeroes = [
            new Byte("0"),
            new Short("0"),
            new Integer(0),
            new Float("0.0"),
            new Long(0),
            new Double("0.00"),
            new BigDecimal("0.000"),
            new BigInteger("0000000000")
        ]

        // using Groovy simple assertions, they're all equals
        zeroes.each { left ->
            zeroes.each { right ->
                assert left == right : "\n\t'$left' [${left.class.simpleName}] should be equals to\n\t'$right' [${right.class.simpleName}]"
            }
        }

        // GrooBe fails
        zeroes.each { left ->
            zeroes.each { right ->
                left.shouldBe right, "\n\t'$left' [${left.class.simpleName}] should be equals to\n\t'$right' [${right.class.simpleName}]"
            }
        }
    }
}