/specs/core/util.ds

http://github.com/wilkie/djehuty · Unknown · 153 lines · 124 code · 29 blank · 0 comment · 0 complexity · 3fbd27c447fb679a0f77bc0613792517 MD5 · raw file

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