/* * Copyright(c) 2006-2007 the Spark project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ package org.libspark.utils.overload { import org.libspark.as3unit.test; import org.libspark.as3unit.assert.assertEquals; use namespace test; /** * OverloadSupport のテストケースです * * @author yossy */ public final class OverloadSupportTest { test function invoke():void { var hoge:Hoge = new Hoge(); Static.log = ''; hoge.func(); hoge.func('str'); hoge.func('str1', 'str2'); hoge.func(1024); hoge.func('sss', 512); assertEquals('Default String(str) String(str1)String(str2) Int(1024) String(sss)Int(512) ', Static.log); } } } import org.libspark.utils.overload.OverloadSupport; import org.libspark.utils.overload.overloadDefault; namespace overloadString; namespace overloadStringString; namespace overloadInt; namespace overloadStringInt; use namespace overloadString; use namespace overloadStringString; use namespace overloadInt; use namespace overloadStringInt; use namespace overloadDefault; class Static { public static var log:String = ''; } class Hoge { OverloadSupport.register(overloadString, String); OverloadSupport.register(overloadStringString, String, String); OverloadSupport.register(overloadInt, int); OverloadSupport.register(overloadStringInt, String, int); public function func(...args):void { OverloadSupport.invoke(this, 'func', args); } overloadDefault function func():void { Static.log += 'Default '; } overloadString function func(a:String):void { Static.log += 'String(' + a + ') '; } overloadStringString function func(a:String, b:String):void { Static.log += 'String(' + a + ')String(' + b + ') '; } overloadInt function func(a:int):void { Static.log += 'Int(' + a + ') '; } overloadStringInt function func(a:String, b:int):void { Static.log += 'String(' + a + ')Int(' + b + ') '; } }