"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/test/groovy/transform/stc/MethodReferenceTest.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.

MethodReferenceTest.groovy  (apache-groovy-src-3.0.8):MethodReferenceTest.groovy  (apache-groovy-src-3.0.9)
skipping to change at line 47 skipping to change at line 47
} }
// class::instanceMethod // class::instanceMethod
void testFunctionCI2() { void testFunctionCI2() {
assertScript ''' assertScript '''
import java.util.stream.Collectors import java.util.stream.Collectors
@groovy.transform.CompileStatic @groovy.transform.CompileStatic
void p() { void p() {
def result = [1, 2, 3].stream().map(Integer::toString).collect(C ollectors.toList()) def result = [1, 2, 3].stream().map(Integer::toString).collect(C ollectors.toList())
assert result ['1', '2', '3'] assert result == ['1', '2', '3']
} }
p() p()
''' '''
} }
// class::instanceMethod // class::instanceMethod -- GROOVY-10047
void testFunctionCI3() { void testFunctionCI3() {
assertScript '''
import java.util.function.Function
import static java.util.stream.Collectors.toMap
@groovy.transform.CompileStatic
void p() {
List<String> list = ['a','bc','def']
Function<String,String> self = str -> str // help for toMap
def map = list.stream().collect(toMap(self, String::length))
assert map == [a: 1, bc: 2, 'def': 3]
}
p()
'''
assertScript '''
import java.util.function.Function
import static java.util.stream.Collectors.toMap
@groovy.transform.CompileStatic
void p() {
List<String> list = ['a','bc','def']
// TODO: inference for T in toMap(Function<? super T,...>, Funct
ion<? super T,...>)
def map = list.stream().collect(toMap(Function.<String>identity(
), String::length))
assert map == [a: 1, bc: 2, 'def': 3]
}
p()
'''
}
// class::instanceMethod
void testFunctionCI4() {
def err = shouldFail ''' def err = shouldFail '''
import java.util.stream.Collectors import static java.util.stream.Collectors.toList
@groovy.transform.CompileStatic @groovy.transform.CompileStatic
void p() { void p() {
def result = [1, 2, 3].stream().map(String::toString).collect(Co def result = [1, 2, 3].stream().map(String::toString).collect(to
llectors.toList()) List())
assert result == ["1", "2", "3"]
} }
p() p()
''' '''
assert err =~ /Invalid receiver type: java.lang.Integer is not compatibl e with java.lang.String/ assert err =~ /Invalid receiver type: java.lang.Integer is not compatibl e with java.lang.String/
} }
// class::instanceMethod -- GROOVY-9814 // class::instanceMethod -- GROOVY-9814
void testFunctionCI4() { void testFunctionCI5() {
assertScript ''' assertScript '''
import java.util.function.* import java.util.function.*
import groovy.transform.CompileStatic import groovy.transform.*
@CompileStatic @CompileStatic
class One { String id } class One { String id }
@CompileStatic @CompileStatic
class Two extends One { } class Two extends One { }
@CompileStatic @groovy.transform.Immutable(knownImmutableClasses=[Fu nction]) @CompileStatic @Immutable(knownImmutableClasses=[Function])
class FunctionHolder<T> { class FunctionHolder<T> {
Function<T, ?> extractor Function<T, ?> extractor
def apply(T t) { def apply(T t) {
extractor.apply(t) extractor.apply(t)
} }
} }
def fh = new FunctionHolder(One::getId) def fh = new FunctionHolder(One::getId)
assert fh.apply(new One(id:'abc')) == 'abc' assert fh.apply(new One(id:'abc')) == 'abc'
skipping to change at line 125 skipping to change at line 159
void p() { void p() {
def result = [1.0G, 2.0G, 3.0G].stream().reduce(0.0G, BigDecimal ::add) def result = [1.0G, 2.0G, 3.0G].stream().reduce(0.0G, BigDecimal ::add)
assert 6.0G == result assert 6.0G == result
} }
p() p()
''' '''
} }
// class::staticMethod
void testFunctionCS() {
assertScript '''
import groovy.transform.CompileStatic
import java.util.stream.Collectors
@CompileStatic
void p() {
def result = [1, -2, 3].stream().map(Math::abs).collect(Collecto
rs.toList())
assert [1, 2, 3] == result
}
p()
'''
}
// class::staticMethod -- GROOVY-9799
void testFunctionCS2() {
assertScript '''
class C {
String x
}
class D {
String x
static D from(C c) {
new D(x: c.x)
}
}
@groovy.transform.CompileStatic
def test(C c) {
Optional.of(c).map(D::from).get()
}
def d = test(new C(x: 'x'))
assert d.x == 'x'
'''
}
// instance::instanceMethod // instance::instanceMethod
void testBinaryOperatorII() { void testBinaryOperatorII() {
assertScript ''' assertScript '''
@groovy.transform.CompileStatic @groovy.transform.CompileStatic
void p() { void p() {
Adder adder = new Adder() Adder adder = new Adder()
def result = [1.0G, 2.0G, 3.0G].stream().reduce(0.0G, adder::add ) def result = [1.0G, 2.0G, 3.0G].stream().reduce(0.0G, adder::add )
assert 6.0G == result assert 6.0G == result
} }
skipping to change at line 319 skipping to change at line 318
} }
static Adder newInstance() { static Adder newInstance() {
new Adder() new Adder()
} }
} }
''' '''
} }
// arrayClass::new // arrayClass::new
void testIntFunctionCN() { void testFunctionCN() {
assertScript ''' assertScript '''
@groovy.transform.CompileStatic @groovy.transform.CompileStatic
void p() { void p() {
assert new Integer[] { 1, 2, 3 } == [1, 2, 3].stream().toArray(I def result = [1, 2, 3].stream().toArray(Integer[]::new)
nteger[]::new) assert result == new Integer[] { 1, 2, 3 }
} }
p() p()
''' '''
} }
// class::new // class::new
void testFunctionCN() { void testFunctionCN2() {
assertScript ''' assertScript '''
import java.util.stream.Collectors import static java.util.stream.Collectors.toList
@groovy.transform.CompileStatic
void p() {
def result = ["1", "2", "3"].stream().map(Integer::new).collect(
toList())
assert result == [1, 2, 3]
}
p()
'''
}
// class::new -- GROOVY-10033
void testFunctionCN3() {
assertScript '''
import java.util.function.Function
@groovy.transform.CompileStatic
class C {
C(Function<String,Integer> f) {
def i = f.apply('42')
assert i == 42
}
static test() {
new C(Integer::new)
}
}
C.test()
'''
}
// class::new -- GROOVY-10033
void testFunctionCN4() {
assertScript '''
import java.util.function.Function
class A {
A(Function<A,B> f) {
B b = f.apply(this)
assert b instanceof X.Y
}
}
class B {
B(A a) {
assert a != null
}
}
@groovy.transform.CompileStatic
class X extends A {
public X() {
super(Y::new)
}
private static class Y extends B {
Y(A a) {
super(a)
}
}
}
new X()
'''
}
// class::staticMethod
void testFunctionCS() {
assertScript '''
import static java.util.stream.Collectors.toList
@groovy.transform.CompileStatic
void p() {
def result = [1, -2, 3].stream().map(Math::abs).collect(toList()
)
assert [1, 2, 3] == result
}
p()
'''
}
// class::staticMethod
void testFunctionCS2() {
assertScript '''
import java.util.function.Function
import static java.util.stream.Collectors.toMap
@groovy.transform.CompileStatic @groovy.transform.CompileStatic
void p() { void p() {
assert [1, 2, 3] == ["1", "2", "3"].stream().map(Integer::new).c List<String> list = ['x','y','z']
ollect(Collectors.toList()) def map = list.stream().collect(toMap(Function.identity(), Colle
ctions::singletonList))
assert map == [x: ['x'], y: ['y'], z: ['z']]
} }
p() p()
'''
}
// class::staticMethod -- GROOVY-9799
void testFunctionCS3() {
assertScript '''
class C {
String x
}
class D {
String x
static D from(C c) {
new D(x: c.x)
}
}
@groovy.transform.CompileStatic
def test(C c) {
Optional.of(c).map(D::from).get()
}
def d = test(new C(x: 'x'))
assert d.x == 'x'
''' '''
} }
// class::staticMethod // class::staticMethod
void testFunctionCS_RHS() { void testFunctionCS_RHS() {
assertScript ''' assertScript '''
import java.util.function.Function import java.util.function.Function
import java.util.stream.Collectors import java.util.stream.Collectors
@groovy.transform.CompileStatic @groovy.transform.CompileStatic
 End of changes. 17 change blocks. 
52 lines changed or deleted 160 lines changed or added

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