"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/test/groovy/transform/stc/DefaultGroovyMethodsSTCTest.groovy" between
apache-groovy-src-3.0.8.zip and apache-groovy-src-3.0.9.zip

About: Groovy is an agile dynamic (scripting) language for the Java Platform. It has features similar to those of Python, Ruby, Perl, and Smalltalk. Source release.

DefaultGroovyMethodsSTCTest.groovy  (apache-groovy-src-3.0.8):DefaultGroovyMethodsSTCTest.groovy  (apache-groovy-src-3.0.9)
skipping to change at line 27 skipping to change at line 27
* under the License. * under the License.
*/ */
package groovy.transform.stc package groovy.transform.stc
/** /**
* Unit tests for static type checking : default groovy methods. * Unit tests for static type checking : default groovy methods.
*/ */
class DefaultGroovyMethodsSTCTest extends StaticTypeCheckingTestCase { class DefaultGroovyMethodsSTCTest extends StaticTypeCheckingTestCase {
void testEach() { void testEach() {
assertScript """ assertScript '''
['a','b'].each { // DGM#each(Object, Closure) ['a','b'].each { // DGM#each(Object, Closure)
println it // DGM#println(Object,Object) println it // DGM#println(Object,Object)
} }
""" '''
assertScript """ assertScript '''
['a','b'].eachWithIndex { it, i ->// DGM#eachWithIndex(Object, Closu re) ['a','b'].eachWithIndex { it, i ->// DGM#eachWithIndex(Object, Closu re)
println it // DGM#println(Object,Object) println it // DGM#println(Object,Object)
} }
""" '''
} }
void testStringToInteger() { void testStringToInteger() {
assertScript """ assertScript '''
String name = "123" String name = "123"
name.toInteger() // toInteger() is defined by DGM name.toInteger() // toInteger() is defined by DGM
""" '''
} }
void testVariousAssignmentsThenToInteger() { void testVariousAssignmentsThenToInteger() {
assertScript """ assertScript '''
class A { class A {
void foo() {} void foo() {}
} }
def name = new A() def name = new A()
name.foo() name.foo()
name = 1 name = 1
name = '123' name = '123'
name.toInteger() // toInteger() is defined by DGM name.toInteger() // toInteger() is defined by DGM
""" '''
} }
void testMethodsOnPrimitiveTypes() { void testMethodsOnPrimitiveTypes() {
assertScript ''' assertScript '''
1.times { it } 1.times { it }
''' '''
assertScript ''' assertScript '''
true.equals { it } true.equals { it }
''' '''
skipping to change at line 79 skipping to change at line 79
void testShouldAcceptMethodFromDefaultDateMethods() { void testShouldAcceptMethodFromDefaultDateMethods() {
assertScript ''' assertScript '''
def s = new Date() def s = new Date()
println s.year println s.year
println s.format("yyyyMMdd") println s.format("yyyyMMdd")
''' '''
} }
// GROOVY-5568 // GROOVY-5568
void testDGMMethodAsProperty() { void testPropertySemantics1() {
assertScript ''' assertScript '''
String foo(InputStream input) { String test(InputStream input) {
input.text input.text // IOGroovyMethods#getText(InputStream)
} }
def text = new ByteArrayInputStream('foo'.getBytes()) assert test(new ByteArrayInputStream('foo'.bytes)) == 'foo'
assert foo(text) == 'foo'
''' '''
assertScript '''
def chars = new StringBuilder('foo').chars // StringGroovyMethods#ge
tChars(CharSequence)
assert chars == new char[] {'f','o','o'}
'''
assertScript '''
def a = Character.valueOf((char) 'a')
assert a.letter // DefaultGroovyMethods#isLetter(Character)
'''
}
// GROOVY-10075
void testPropertySemantics2() {
// see org.codehaus.groovy.runtime.m12n.TestStringExtension
assertScript '''
List<String> strings = ['x','y','z']
assert strings.getSequence() == 'x'
assert strings.getString() == 'x'
//assert strings.sequence == 'x'
//assert strings.string == 'x'
'''
shouldFailWithMessages '''
List<Number> numbers = [(Number)1, 2, 3]
numbers.getSequence()
numbers.getString()
numbers.sequence
numbers.string
''',
'Cannot call <CS extends java.lang.CharSequence> java.util.List <java.la
ng.Number>#getSequence() with arguments []',
'Cannot call java.util.List <java.lang.Number>#getString() with argument
s []',
'No such property: sequence for class: java.util.List <java.lang.Number>
',
'No such property: string for class: java.util.List <java.lang.Number>'
} }
// GROOVY-5584 // GROOVY-5584
void testEachOnMap() { void testEachOnMap() {
assertScript ''' assertScript '''
import org.codehaus.groovy.transform.stc.ExtensionMethodNode import org.codehaus.groovy.transform.stc.ExtensionMethodNode
import org.codehaus.groovy.runtime.DefaultGroovyMethods import org.codehaus.groovy.runtime.DefaultGroovyMethods
@ASTTest(phase=INSTRUCTION_SELECTION, value= { @ASTTest(phase=INSTRUCTION_SELECTION, value= {
def mn = node.rightExpression.getNodeMetaData(DIRECT_METHOD_CALL _TARGET) def mn = node.rightExpression.getNodeMetaData(DIRECT_METHOD_CALL _TARGET)
 End of changes. 10 change blocks. 
23 lines changed or deleted 61 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)