Source: demo/index.js

  1. /**
  2. * @file
  3. * @fileoverview A set of example functions with attached assertions.
  4. */
  5. /**
  6. * Greets a person by name.
  7. * @param {String} name - Name of the person to greet
  8. * @returns {String}
  9. *
  10. * @assert {Assertion} Test1 - John:string=>Hello, John!
  11. * @assert {Assertion} Test2 - Ben:string=>Hello, John!
  12. * @assert Test3 - John:string,Ben=>Hello, John and Ben!
  13. * @assert Test4 - 1:bool=>Hello, true!:string
  14. * @assert - John=>Hello, John!
  15. */
  16. function greet(name) {
  17. return `Hello, ${name}!`
  18. }
  19. /**
  20. * Adds two numbers together.
  21. * @param {Number} a
  22. * @param {Number} b
  23. * @returns {Number}
  24. *
  25. * @assert - 1:number,2:number=>3:number
  26. * @assert - 1:number,2:number=>5:number
  27. */
  28. function add(a, b) {
  29. return a + b;
  30. }
  31. /**
  32. * Returns the name property of an object.
  33. * @param {Object} object - Object to read name from
  34. * @returns {String}
  35. *
  36. * @assert ObjectTestJohn - test:object=>John:string
  37. * @assert ObjectTestBlank - :object=>John:string
  38. * @assert ClassTestJohn - class:object=>John:string
  39. */
  40. function objectTest(object) {
  41. return object.name;
  42. }
  43. /**
  44. * A test class containing a name.
  45. */
  46. class TestClass {
  47. /**
  48. * A test class that has a name property.
  49. * @param {String} name - The name to be stored
  50. */
  51. constructor(name) {
  52. this.name = name;
  53. }
  54. /**
  55. * Changes the stored name.
  56. * @param {String} newName - The new name to be stored
  57. */
  58. update(newName) {
  59. this.name = newName;
  60. }
  61. }
  62. console.log(greet("John"));
  63. console.log(objectTest({name: "John"}));
  64. module.exports = {
  65. greet,
  66. add,
  67. objectTest,
  68. TestClass,
  69. }