Add math helpers, tests and checks
3 files+34−00/3 viewed
| 1 | + | name: Checks | |
| 2 | + | on: | |
| 3 | + | pull_request: | |
| 4 | + | push: | |
| 5 | + | branches: [main] | |
| 6 | + | jobs: | |
| 7 | + | test: | |
| 8 | + | runs-on: ubuntu-latest | |
| 9 | + | steps: | |
| 10 | + | - uses: actions/checkout@v4 | |
| 11 | + | - name: Unit tests | |
| 12 | + | run: node test.js | |
| 13 | + | - name: House style | |
| 14 | + | run: | | |
| 15 | + | # Every exported function is documented with a JSDoc block. | |
| 16 | + | for fn in $(grep -oE '^function [a-zA-Z]+' math.js | cut -d' ' -f2); do | |
| 17 | + | if ! grep -B1 "^function $fn" math.js | grep -q '^ \*/\|^\*/\|\*/$'; then | |
| 18 | + | echo "::error file=math.js,title=House style::$fn needs a /** JSDoc */ comment right above it" | |
| 19 | + | exit 1 | |
| 20 | + | fi | |
| 21 | + | done | |
| 22 | + | echo "house style ok" |
| 1 | + | // Small helpers for numbers. | |
| 2 | + | function add(a, b) { | |
| 3 | + | return a + b; | |
| 4 | + | } | |
| 5 | + | ||
| 6 | + | module.exports = { add }; |
| 1 | + | const assert = require("node:assert"); | |
| 2 | + | const math = require("./math"); | |
| 3 | + | ||
| 4 | + | assert.strictEqual(math.add(2, 3), 5); | |
| 5 | + | if (math.multiply) assert.strictEqual(math.multiply(4, 5), 20); | |
| 6 | + | console.log("all tests passed"); |