PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/specs/core/util.ds

http://github.com/wilkie/djehuty
Unknown | 153 lines | 124 code | 29 blank | 0 comment | 0 complexity | 3fbd27c447fb679a0f77bc0613792517 MD5 | raw file
  1module specs.core.util;
  2
  3import core.util;
  4import data.stack;
  5import data.list;
  6import interfaces.container;
  7
  8describe util() {
  9	describe typeTemplates() {
 10		it should_determine_if_it_is_a_type () {
 11			should(IsType!(int));
 12			shouldNot(IsType!(int[]));
 13		}
 14
 15		it should_determine_if_it_is_a_class() {
 16			should(IsClass!(Stack!(int)));
 17			shouldNot(IsClass!(int));
 18		}
 19
 20		it should_determine_if_it_is_an_iterface() {
 21			should(IsInterface!(AbstractContainer));
 22			shouldNot(IsInterface!(int));
 23		}
 24
 25		it should_determine_if_it_is_an_object() {
 26			shouldNot(IsObject!(int));
 27			should(IsObject!(Stack!(int)));
 28			should(IsObject!(AbstractContainer));
 29		}
 30
 31		it should_determine_if_it_is_an_int_type() {
 32			should(IsIntType!(int));
 33			should(IsIntType!(uint));
 34			shouldNot(IsIntType!(int[]));
 35		}
 36
 37		it should_determine_if_it_is_unsigned() {
 38			should(IsUnsigned!(uint));
 39			should(IsUnsigned!(ushort));
 40			should(IsUnsigned!(ulong));
 41			should(IsUnsigned!(ubyte));
 42
 43			shouldNot(IsUnsigned!(int));
 44			shouldNot(IsUnsigned!(short));
 45			shouldNot(IsUnsigned!(long));
 46			shouldNot(IsUnsigned!(byte));
 47		}
 48
 49		it should_determine_if_it_is_signed() {
 50			should(IsSigned!(int));
 51			should(IsSigned!(short));
 52			should(IsSigned!(long));
 53			should(IsSigned!(byte));
 54
 55			shouldNot(IsSigned!(uint));
 56			shouldNot(IsSigned!(ushort));
 57			shouldNot(IsSigned!(ulong));
 58			shouldNot(IsSigned!(ubyte));
 59		}
 60
 61		it should_determine_if_it_is_float() {
 62			should(IsFloat!(float));
 63			should(IsFloat!(double));
 64			should(IsFloat!(real));
 65
 66			shouldNot(IsFloat!(int));
 67		}
 68
 69		it should_determine_if_it_is_complex {
 70			should(IsComplex!(cfloat));
 71			should(IsComplex!(cdouble));
 72			should(IsComplex!(creal));
 73
 74			shouldNot(IsComplex!(float));
 75		}
 76
 77		it should_determine_if_it_is_imaginary {
 78			should(IsImaginary!(ifloat));
 79			should(IsImaginary!(idouble));
 80			should(IsImaginary!(ireal));
 81
 82			shouldNot(IsImaginary!(float));
 83		}
 84
 85		it should_determine_if_it_is_struct {
 86			shouldNot(IsStruct!(int));
 87		}
 88
 89		it should_determine_if_it_is_array {
 90			should(IsArray!(int[]));
 91			shouldNot(IsArray!(int));
 92		}
 93		
 94		it should_determine_the_superclass {
 95			class A{}
 96			class B : A {}
 97			class C : B {}
 98
 99			should(Super!(B).stringof == "A");
100			should(Super!(C).stringof == "B");
101		}
102
103		it should_determine_the_interfaces {
104			class A {}
105			interface E {}
106			interface F {}
107			interface G {}
108			class B : A,G {}
109			class C : B,E,F {}
110
111			should(Interfaces!(C).stringof == "(E, F)");
112		}
113
114		it should_determine_the_arraytype {
115			should(ArrayType!(int[]).stringof == "int");
116		}
117	}
118
119	describe stringTemplates {
120		it should_capitalize_a_string {
121			should(Capitalize!("string") == "String");
122			should(Capitalize!("String") == "String");
123		}
124
125		it should_trim_whitespace_from_the_left {
126			should(TrimL!("string") == "string");
127			should(TrimL!("   string") == "string");
128			should(TrimL!("string   ") == "string   ");
129			should(TrimL!("   string   ") == "string   ");
130
131			should(TrimL!("\t\n\rstring") == "string");
132			should(TrimL!("string\t\n\r") == "string\t\n\r");
133			should(TrimL!("\t\n\rstring\t\n\r") == "string\t\n\r");
134		}
135
136		it should_trim_whitespace_from_the_right {
137			should(TrimR!("string") == "string");
138			should(TrimR!("   string") == "   string");
139			should(TrimR!("string   ") == "string");
140			should(TrimR!("   string   ") == "   string");
141
142			should(TrimR!("\t\n\rstring") == "\t\n\rstring");
143			should(TrimR!("string\t\n\r") == "string");
144			should(TrimR!("\t\n\rstring\t\n\r") == "\t\n\rstring");
145		}
146
147		it should_remove_spaces {
148			should(RemoveSpaces!("string") == "string");
149			should(RemoveSpaces!(" s t r i n g ") == "string");
150			should(RemoveSpaces!("\ts\nt\rr\ti\nn\rg") == "string");
151		}
152	}
153}