Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG comparing Strings and Numbers #5

Open
erdanielli opened this issue Jan 25, 2011 · 0 comments
Open

BUG comparing Strings and Numbers #5

erdanielli opened this issue Jan 25, 2011 · 0 comments

Comments

@erdanielli
Copy link

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}]"
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant