Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业务

源代码在线查看: multipledefinitionofsamevariabletest.groovy

软件大小: 1644 K
上传用户: maple_78
关键词: Groovy JVM 动态语言 运行
下载地址: 免注册下载 普通下载 VIP

相关代码

				package gls.scope
				
				import gls.scope.CompilableTestSupport
				
				public class MultipleDefinitionOfSameVariableTest extends CompilableTestSupport {
				
				   public void testInSameBlock() {
				     shouldNotCompile("""
				       def foo = 1
				       def foo = 2
				     """)
				      
				     shouldNotCompile("""
				       class Foo {
				         def foo() {
				           def bar=1
				           def bar=2
				         }
				       }
				     """)
				   }
				   
				   public void testInSubblocks() {
				     shouldNotCompile("""
				       def foo = 1
				       5.times { def foo=2 }
				     """)
				     
				     shouldNotCompile("""
				       def foo = 1
				       label1: { def foo=2 }
				     """)
				     
				     shouldNotCompile("""
				       def foo = 1
				       for (i in []) { def foo=2 }
				     """)
				     
				     shouldNotCompile("""
				       def foo = 1
				       while (true) { def foo=2 }
				     """)     
				   } 
				   
				   public void testInNestedClosure() {
				     shouldNotCompile("""
				       def foo = 1
				       5.times { 6.times {def foo=2 }
				     """)
				     
				     assertScript ("""
				       def foo = 1
				       5.times { 6.times {foo=2 } }
				       assert foo == 2
				     """)
				   }
				   
				   public void testBindingHiding() {
				     assertScript("""
				       foo = 1
				       def foo = 3
				       assert foo==3
				       assert this.foo == 1
				       assert binding.foo == 1
				     """)
				   }
				   
				   public void testBindingAccessInMethod() {
					   assertScript("""
					     def methodUsingBinding() {
					       try {
					         s = "  bbb  ";
					       } finally {
					         s = s.trim();
					       }
					       assert s == "bbb"
					     } 
					     methodUsingBinding()
					     assert s == "bbb"
					   """)
				   }
				   
				   public void testMultipleOfSameName() {
				   		shouldNotCompile("""
				   		  class DoubleField {
							def zero = 0
							public zero = 0
						  }
						  
				   		""")
				   
				   		shouldNotCompile("""
				   		  class DoubleField {
							def zero = 0
							def zero = 0
						  }
						  
				   		""")
				
				   }
				   
				   
				}			

相关资源