"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy" between
apache-groovy-src-3.0.4.zip and apache-groovy-src-3.0.5.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.

FieldsAndPropertiesSTCTest.groovy  (apache-groovy-src-3.0.4):FieldsAndPropertiesSTCTest.groovy  (apache-groovy-src-3.0.5)
skipping to change at line 21 skipping to change at line 21
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package groovy.transform.stc package groovy.transform.stc
import groovy.test.NotYetImplemented
/** /**
* Unit tests for static type checking : fields and properties. * Unit tests for static type checking : fields and properties.
*/ */
class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase { class FieldsAndPropertiesSTCTest extends StaticTypeCheckingTestCase {
void testAssignFieldValue() { void testAssignFieldValue() {
assertScript """ assertScript """
class A { class A {
int x int x
} }
skipping to change at line 102 skipping to change at line 104
assertScript ''' assertScript '''
class A { class A {
String name = 'Cedric' String name = 'Cedric'
} }
A a = new A() A a = new A()
def b = a.@name def b = a.@name
b.toUpperCase() // type of b should be inferred from field type b.toUpperCase() // type of b should be inferred from field type
''' '''
} }
void testShouldComplainAboutMissingField() { void testShouldComplainAboutMissingProperty() {
shouldFailWithMessages ''' shouldFailWithMessages '''
Object o = new Object() Object o = new Object()
o.x = 0 o.x = 0
''', 'No such property: x for class: java.lang.Object' ''', 'No such property: x for class: java.lang.Object'
} }
void testShouldComplainAboutMissingField2() { void testShouldComplainAboutMissingProperty2() {
shouldFailWithMessages ''' shouldFailWithMessages '''
class A { class A {
} }
A a = new A() A a = new A()
a.x = 0 a.x = 0
''', 'No such property: x for class: A' ''', 'No such property: x for class: A'
} }
void testFieldWithInheritance() { @NotYetImplemented
void testShouldComplainAboutMissingProperty3() {
shouldFailWithMessages '''
class A {
private x
}
class B extends A {
void test() {
this.x
}
}
''', 'The field A.x is not accessible'
}
void testShouldComplainAboutMissingAttribute() {
shouldFailWithMessages '''
Object o = new Object()
o.@x = 0
''', 'No such attribute: x for class: java.lang.Object'
}
void testShouldComplainAboutMissingAttribute2() {
shouldFailWithMessages '''
class A {
}
A a = new A()
a.@x = 0
''', 'No such attribute: x for class: A'
}
void testShouldComplainAboutMissingAttribute3() {
shouldFailWithMessages '''
class A {
def getX() { }
}
A a = new A()
println a.@x
''', 'No such attribute: x for class: A'
}
void testShouldComplainAboutMissingAttribute4() {
shouldFailWithMessages '''
class A {
def setX(x) { }
}
A a = new A()
a.@x = 0
''', 'No such attribute: x for class: A'
}
void testShouldComplainAboutMissingAttribute5() {
shouldFailWithMessages '''
class A {
private x
}
class B extends A {
void test() {
this.@x
}
}
''', 'The field A.x is not accessible'
}
void testPropertyWithInheritance() {
assertScript ''' assertScript '''
class A { class A {
int x int x
} }
class B extends A { class B extends A {
} }
B b = new B() B b = new B()
assert b.x == 0
b.x = 2 b.x = 2
assert b.x == 2
''' '''
} }
void testFieldTypeWithInheritance() { void testPropertyTypeWithInheritance() {
shouldFailWithMessages ''' shouldFailWithMessages '''
class A { class A {
int x int x
} }
class B extends A { class B extends A {
} }
B b = new B() B b = new B()
b.x = '2' b.x = '2'
''', 'Cannot assign value of type java.lang.String to variable of type i nt' ''', 'Cannot assign value of type java.lang.String to variable of type i nt'
} }
void testFieldWithInheritanceFromAnotherSourceUnit() { void testPropertyWithInheritanceFromAnotherSourceUnit() {
assertScript ''' assertScript '''
class B extends groovy.transform.stc.FieldsAndPropertiesSTCTest.Base Class { class B extends groovy.transform.stc.FieldsAndPropertiesSTCTest.Base Class {
} }
B b = new B() B b = new B()
b.x = 2 b.x = 2
''' '''
} }
void testFieldWithInheritanceFromAnotherSourceUnit2() { void testPropertyWithInheritanceFromAnotherSourceUnit2() {
shouldFailWithMessages ''' shouldFailWithMessages '''
class B extends groovy.transform.stc.FieldsAndPropertiesSTCTest.Base Class { class B extends groovy.transform.stc.FieldsAndPropertiesSTCTest.Base Class {
} }
B b = new B() B b = new B()
b.x = '2' b.x = '2'
''', 'Cannot assign value of type java.lang.String to variable of type i nt' ''', 'Cannot assign value of type java.lang.String to variable of type i nt'
} }
void testFieldWithSuperInheritanceFromAnotherSourceUnit() { void testPropertyWithSuperInheritanceFromAnotherSourceUnit() {
assertScript ''' assertScript '''
class B extends groovy.transform.stc.FieldsAndPropertiesSTCTest.Base Class2 { class B extends groovy.transform.stc.FieldsAndPropertiesSTCTest.Base Class2 {
} }
B b = new B() B b = new B()
b.x = 2 b.x = 2
''' '''
} }
void testMethodUsageForProperty() { void testMethodUsageForProperty() {
assertScript ''' assertScript '''
skipping to change at line 390 skipping to change at line 459
assertScript ''' assertScript '''
class Foo implements groovy.transform.stc.FieldsAndPropertiesSTCTest .InterfaceWithField { class Foo implements groovy.transform.stc.FieldsAndPropertiesSTCTest .InterfaceWithField {
void test() { void test() {
assert boo == "I don't fancy fields in interfaces" assert boo == "I don't fancy fields in interfaces"
} }
} }
new Foo().test() new Foo().test()
''' '''
} }
void testOuterPropertyAccess1() {
assertScript '''
class Outer {
class Inner {
def m() {
p
}
}
def p = 1
}
def i = new Outer.Inner(new Outer())
def x = i.m()
assert x == 1
'''
}
// GROOVY-9598
void testOuterPropertyAccess2() {
shouldFailWithMessages '''
class Outer {
static class Inner {
def m() {
p
}
}
def p = 1
}
def i = new Outer.Inner()
def x = i.m()
''', "Apparent variable 'p' was found in a static scope but doesn't refe
r to a local variable, static field or class."
}
void testOuterPropertyAccess3() {
shouldFailWithMessages '''
class Outer {
static class Inner {
def m() {
this.p
}
}
def p = 1
}
def i = new Outer.Inner()
def x = i.m()
''', 'No such property: p for class: Outer$Inner'
}
void testPrivateFieldAccessInClosure() { void testPrivateFieldAccessInClosure() {
assertScript ''' assertScript '''
class A { class A {
private int x private int x
void foo() { void foo() {
def cl = { x = 666 } def cl = { x = 666 }
cl() cl()
} }
void ensure() { void ensure() {
assert x == 666 assert x == 666
skipping to change at line 426 skipping to change at line 542
void ensure() { void ensure() {
assert x == 666 assert x == 666
} }
} }
def a = new A() def a = new A()
a.foo() a.foo()
a.ensure() a.ensure()
''' '''
} }
// GROOVY-9562
void testSuperPropertyAccessInAIC() {
assertScript '''
abstract class One {
int prop = 1
}
abstract class Two {
int prop = 2
abstract baz()
}
class Foo extends One {
Two bar() {
new Two() {
def baz() {
prop
}
}
}
}
assert new Foo().bar().baz() == 2
'''
}
// GROOVY-5737 // GROOVY-5737
void testAccessGeneratedFieldFromClosure() { void testAccessGeneratedFieldFromClosure() {
assertScript ''' assertScript '''
import groovy.transform.* import groovy.transform.*
import groovy.util.logging.* import groovy.util.logging.*
@Log @Log
class GreetingActor { class GreetingActor {
def receive = { def receive = {
 End of changes. 13 change blocks. 
7 lines changed or deleted 151 lines changed or added

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