Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gen-cast-test.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d1f9531d2f11d37492957b210c8a9b31f00e0a33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;

class Stress {

	static string mode = "unchecked";
	
	static string [] types = {
		"int",   "uint",
		"short", "ushort",
		"long",  "ulong",
		"sbyte", "byte", "char"
		};
	

	static void w (string s)
	{
		Console.Write (s);
	}

	static void wl (string s)
	{
		Console.WriteLine (s);
	}
	
	static void generate_receptors ()
	{
		foreach (string t in types){
			w ("\tstatic void receive_" + t + " (" + t + " a)\n\t{\n");
			w ("\t\tConsole.Write (\"        \");\n");
			w ("\t\tConsole.WriteLine (a);\n");
			w ("\t}\n\n");
		}
		
	}

	static void var (string type, string name, string init)
	{
		w ("\t\t" + type + " " + name + " = (" + type + ") " + init + ";\n");
	}

	static void call (string type, string name)
	{
		w ("\t\treceive_" + type + " (" + mode + "((" + type + ") " + name + "));\n");
	}
	
	static void generate_emision ()
	{
		foreach (string type in types){
			w ("\tstatic void probe_" + type + "()\n\t{\n");
			var (type, "zero", "0");
			var (type, "min", type + ".MinValue");
			var (type, "max", type + ".MaxValue");
			wl ("");

			wl ("\t\tConsole.WriteLine (\"Testing: " + type + "\");\n");
			foreach (string t in types){
				wl ("\t\tConsole.WriteLine (\"   arg: " + t + " (" + type + ")\");\n");
				call (t, "zero");
				call (t, "min");
				call (t, "max");
			}
			
			w ("\t}\n\n");
		}
	}

	static void generate_main ()
	{
		wl ("\tstatic void Main ()\n\t{");

		foreach (string t in types){
			w ("\t\tprobe_" + t + " ();\n");
		}
		wl ("\t}");
	}
	
	static void Main (string [] args)
	{
		foreach (string arg in args){
			if (arg == "-h" || arg == "--help"){
				Console.WriteLine ("-h, --help     Shows help");
				Console.WriteLine ("-c, --checked  Generate checked contexts");
				return;
			}
			if (arg == "--checked" || arg == "-c"){
				mode = "checked";
				continue;
			}
		}
		wl ("using System;\nclass Test {\n");

		generate_receptors ();
		generate_emision ();

		generate_main ();
			       
		wl ("}\n");
	}
}