package org.beetl.lab;

import org.beetl.core.*;
import org.beetl.core.config.BeetlConfig;
import org.beetl.core.exception.BeetlException;
import org.beetl.core.exception.ErrorInfo;
import org.beetl.core.resource.ClasspathResourceLoader;
import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * 用于不写单元测试，快速测试
 * @author xiandafu
 */
class Test {

    /** DEBUG flag */
    private static final boolean DEBUG = BeetlConfig.DEBUG;
    /** Log TAG */
    private static final String TAG = "org.beetl.core.lab.Test";

    public static void main(String[] args) throws Exception {

        ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader("lab/");
        Configuration cfg = Configuration.defaultConfiguration();

        GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
		gt.setNativeSecurity(null);

		Template t = gt.getTemplate("/hello.txt");
		t.binding("test",new Test());
		System.out.println(t.render());



//		Class klass = Unsafe.class;
//		Field field = klass.getDeclaredField("theUnsafe");
//		field.setAccessible(true);
//		Unsafe unsafe = (Unsafe) field.get(null);
//
//		// 获取count域的Field
//		Class unsafeTestClass = String.class;
//		Field fieldCount = unsafeTestClass.getDeclaredField("value");
//		fieldCount.setAccessible(true);
//
//		// 计算count的内存偏移量
//		long countOffset = (int) unsafe.objectFieldOffset(fieldCount);
//		System.out.println(countOffset);
//
//		String hello ="test12323";
//		Object o = unsafe.getObject(hello,countOffset);
//		System.out.println(o);





    }
	public static void print(String a){
		System.out.println(a);
	}

	public void  set(String a,Context ctx){
		System.out.println(a+ctx.gt);
	}

}
