/spec/modulespecification.d

http://github.com/wilkie/djehuty · D · 54 lines · 32 code · 10 blank · 12 comment · 2 complexity · f2a3e6b2112f3aa5d8aea567c17b6653 MD5 · raw file

  1. /*
  2. * moduletester.d
  3. *
  4. * This module implements a class that will interface the testing of a module.
  5. *
  6. * Originated: May 6th, 2010
  7. *
  8. */
  9. module spec.modulespecification;
  10. import spec.itemspecification;
  11. import djehuty;
  12. import io.console;
  13. class ModuleSpecification {
  14. this(string name) {
  15. _name = name.dup;
  16. }
  17. string name() {
  18. return _name;
  19. }
  20. void add(ItemSpecification item) {
  21. _tests[item.name] = item;
  22. }
  23. // Description: This function will return a class representing the test
  24. // given by the name.
  25. // name: The name of the test.
  26. // Returns: A class that can be used to run the test.
  27. ItemSpecification retrieve(string name) {
  28. if (!(name in _tests)) {
  29. return null;
  30. }
  31. return _tests[name];
  32. }
  33. int opApply(int delegate(ref ItemSpecification) loopBody) {
  34. foreach(test; _tests.keys.sort) {
  35. if (loopBody(_tests[test])) {
  36. return 1;
  37. }
  38. }
  39. return 1;
  40. }
  41. private:
  42. string _name;
  43. ItemSpecification[string] _tests;
  44. }