root/trunk/tests/base.md

Revision 265, 3.3 kB (checked in by JarrettBillingsley, 11 months ago)

--

Line 
1 module tests.base;
2
3 writefln("{,-5}", 10);
4 writefln("{} {} {}", null, true, []);
5 writefln("{} {} {} {} {}", 4, 5.6, 'h', "hi", 7);
6 writefln("{:10E}", 5);
7 writefln("{r}", []);
8 writefln("{{");
9 writefln("{}");
10 try writefln("{:10000000000000000000000000000000000000000000}", 4); catch(e){}
11 writefln("{,45hi");
12 write("hi");
13 writef("hi");
14 writeln("hi");
15 format("hi");
16 typeof(5);
17 toString(5);
18 rawToString(5);
19 getTraceback();
20 isInt(5);
21 assert(true);
22 try assert(false); catch(e){}
23 try assert(false, "h"); catch(e){}
24 toInt(true);
25 toInt(5);
26 toInt(4.5);
27 toInt('h');
28 toInt("45");
29 try toInt([]); catch(e){}
30 toFloat(true);
31 toFloat(4);
32 toFloat(4.5);
33 toFloat('h');
34 toFloat("4.5");
35 try toFloat([]); catch(e){}
36 toChar(4);
37 foreach(k, v; _G){}
38 fieldsOf(class{});
39 fieldsOf(class{}());
40 try fieldsOf(5); catch(e){}
41 methodsOf(class{});
42 methodsOf(class{}());
43 try methodsOf(5); catch(e){}
44 local t = coroutine function(){};
45 t.state();
46 t.isInitial();
47 t.isRunning();
48 t.isWaiting();
49 t.isSuspended();
50 t.isDead();
51 foreach(v; coroutine function countDown(x){currentThread(); yield();while(x > 0){yield(x);x--;}}, 5){}
52 t();
53 try foreach(c; t){} catch(e){}
54 t.reset();
55 currentThread();
56 curry(function(x, y){}, 3)(4);
57 try import("blahblah"); catch(e){}
58 import("tests.dummy");
59 loadString("");
60 loadString("", "h");
61 eval("5");
62 loadJSON("{}");
63
64 local tab = {x = 5};
65 removeKey(tab, "x");
66 local ns = namespace ns{x = 5;};
67 removeKey(ns, "x");
68
69 try removeKey(tab, null); catch(e){}
70 try removeKey(ns, "y"); catch(e){}
71
72 local s = StringBuffer("hello");
73 StringBuffer(5);
74 StringBuffer();
75 try StringBuffer([]); catch(e){}
76 s ~= StringBuffer("h") ~ [] ~ 3;
77 s.insert(0, StringBuffer("h"));
78 s.insert(0, []);
79 s.insert(0, 3);
80 s.remove(0);
81 s.remove(0, 1);
82 s.toString();
83 s.length(#s + 1);
84 s[0] = s[1];
85 foreach(i, v; s){}
86 foreach(i, v; s, "reverse"){}
87 s[0 .. 1] = s[2 .. 3];
88 s.reserve(100);
89 try s.insert(204059, "h"); catch(e){}
90 try s.insert(305935, StringBuffer()); catch(e){}
91 try s.insert(350156, 5); catch(e){}
92 s.remove(10, 100);
93 try s.remove(10, 0); catch(e){}
94 s.length(200);
95 s[-2] = s[-1];
96 try s[1049025] = 'h'; catch(e){}
97 try s[0] = s[95209]; catch(e){}
98 s[-4 .. -3] = s[-2 .. -1];
99 try s[0 .. 1] = "hello"; catch(e){}
100 try s[95091235 .. 5010936] = "h"; catch(e){}
101 try s[0] = s[230591 .. 019096]; catch(e){}
102 try s[-392096 .. 0] = "h"; catch(e){}
103
104 {
105     function loadMod(name, ns)
106     {
107         assert(name == "mod");
108    
109         ns.x = "I'm x";
110    
111         ns.foo = function foo()
112         {
113             writefln("foo");
114         };
115    
116         ns.bar = function bar(x)
117         {
118             return x[0];
119         };
120    
121         ns.baz = function baz()
122         {
123             writefln(x);
124         };
125    
126         foreach(k, v; ns)
127             if(isFunction(v))
128                 v.environment(ns);
129     }
130    
131     setModuleLoader("mod", loadMod);
132    
133     import mod : foo, bar;
134     foo();
135     writefln(bar([5]));
136     mod.baz();
137    
138     writefln();
139    
140     //readf("%d");
141 }
142
143 local data = [ null, true, false, 5, 4.2, 'c', "hi\b\f\n\r\t\\/\"\u5555", { x = 10, y = 20 }, [1, 2, 3] ];
144 writefln("{}", toJSON(data));
145 writefln("{}", toJSON(data, true));
146 toJSON({ x = 5, y = 10 });
147 try toJSON({[5] = 10}); catch(e){}
148 data = [0];
149 data[0] = data;
150 try toJSON(data); catch(e){}
151 data = {x = 0};
152 data.x = data;
153 try toJSON(data); catch(e){}
154 try toJSON([namespace n{}]); catch(e){}
155 try toJSON(5); catch(e){}
156 bindContext(function(x){}, this)(5);
Note: See TracBrowser for help on using the browser.