• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

earldouglas / codedown / #342

21 Dec 2025 02:28AM UTC coverage: 78.431%. First build
#342

Pull #38

earldouglas
Add support for multiple --section arguments
Pull Request #38: Add support for multiple --section arguments

33 of 62 branches covered (53.23%)

14 of 24 new or added lines in 2 files covered. (58.33%)

120 of 153 relevant lines covered (78.43%)

1.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.91
/test/codedown.js
1
var assert  = require('assert');
1✔
2
var process = require('child_process');
1✔
3

4
describe('codedown', function(){
1✔
5

6
  it('should require a <lang> argument', function (done) {
1✔
7
    process.exec('./codedown.js', function (err, stdout, stderr) {
1✔
8
      if (!err) {
1!
9
        assert.equal(
1✔
10
          [ 'Usage: codedown <lang> [...]'
11
          , ''
12
          , 'Options:'
13
          , '--separator <separator line>'
14
          , '--section <section number>'
15
          , ''
16
          , 'Example:'
17
          , 'cat README.md | codedown haskell --separator=----- --section 1.3'
18
          , ''
19
          ].join('\n'),
20
          stdout
21
        );
22
        done();
1✔
23
      } else {
24
        console.log(stderr);
×
25
      }
26
    });
27
  });
28

29
  it('should extract code', function (done) {
1✔
30
    process.exec('cat README.md | ./codedown.js haskell', function (err, stdout, stderr) {
1✔
31
      if (!err) {
1!
32
        assert.equal(
1✔
33
          stdout,
34
          [ 'x :: Int'
35
          , 'x = 42'
36
          , ''
37
          , 'main :: IO ()'
38
          , 'main = putStrLn $ show x'
39
          , ''
40
          ].join('\n')
41
        );
42
        done();
1✔
43
      } else {
44
        console.log(stderr);
×
45
      }
46
    });
47
  });
48

49
  it('should extract code with wildcard', function (done) {
1✔
50
    process.exec('cat README.md | ./codedown.js "**/*.js"', function (err, stdout, stderr) {
1✔
51
      if (!err) {
1!
52
        assert.equal(
1✔
53
          stdout,
54
          'var x = 42;\n'
55
        );
56
        done();
1✔
57
      } else {
58
        console.log(stderr);
×
59
      }
60
    });
61
  });
62

63
  it('should extract code with separator', function (done) {
1✔
64
    process.exec('cat README.md | ./codedown.js haskell --separator=-----', function (err, stdout, stderr) {
1✔
65
      if (!err) {
1!
66
        assert.equal(
1✔
67
          stdout,
68
          [ 'x :: Int'
69
          , 'x = 42'
70
          , '-----'
71
          , 'main :: IO ()'
72
          , 'main = putStrLn $ show x'
73
          , ''
74
          ].join('\n')
75
        );
76
        done();
1✔
77
      } else {
78
        console.log(stderr);
×
79
      }
80
    });
81
  });
82

83
  it('should extract code by section number (1)', function (done) {
1✔
84
    process.exec('cat README.md | ./codedown.js haskell --section 1', function (err, stdout, stderr) {
1✔
85
      if (!err) {
1!
86
        assert.equal(
1✔
87
          stdout,
88
          [ 'x :: Int'
89
          , 'x = 42'
90
          , ''
91
          , 'main :: IO ()'
92
          , 'main = putStrLn $ show x'
93
          , ''
94
          ].join('\n')
95
        );
96
        done();
1✔
97
      } else {
98
        console.log(stderr);
×
99
      }
100
    });
101
  });
102

103
  it('should extract code by section number (1.3)', function (done) {
1✔
104
    process.exec('cat README.md | ./codedown.js haskell --section 1.3', function (err, stdout, stderr) {
1✔
105
      if (!err) {
1!
106
        assert.equal(
1✔
107
          stdout,
108
          [ 'x :: Int'
109
          , 'x = 42'
110
          , ''
111
          , 'main :: IO ()'
112
          , 'main = putStrLn $ show x'
113
          , ''
114
          ].join('\n')
115
        );
116
        done();
1✔
117
      } else {
118
        console.log(stderr);
×
119
      }
120
    });
121
  });
122

123
  it('should extract code by section number (1.3.1)', function (done) {
1✔
124
    process.exec('cat README.md | ./codedown.js haskell --section 1.3.1', function (err, stdout, stderr) {
1✔
125
      if (!err) {
1!
126
        assert.equal(
1✔
127
          stdout,
128
          [ 'x :: Int'
129
          , 'x = 42'
130
          , ''
131
          ].join('\n')
132
        );
133
        done();
1✔
134
      } else {
135
        console.log(stderr);
×
136
      }
137
    });
138
  });
139

140
  it('should extract code by section number (1.3.2)', function (done) {
1✔
141
    process.exec('cat README.md | ./codedown.js haskell --section 1.3.2', function (err, stdout, stderr) {
1✔
142
      if (!err) {
1!
143
        assert.equal(
1✔
144
          stdout,
145
          [ 'main :: IO ()'
146
          , 'main = putStrLn $ show x'
147
          , ''
148
          ].join('\n')
149
        );
150
        done();
1✔
151
      } else {
152
        console.log(stderr);
×
153
      }
154
    });
155
  });
156

157
  it('should extract code by multiple section numbers', function (done) {
1✔
158
    process.exec('cat README.md | ./codedown.js haskell --section 1.3.1 --section 1.3.2', function (err, stdout, stderr) {
1✔
159
      if (!err) {
1!
160
        assert.equal(
1✔
161
          stdout,
162
          [ 'x :: Int'
163
          , 'x = 42'
164
          , ''
165
          , 'main :: IO ()'
166
          , 'main = putStrLn $ show x'
167
          , ''
168
          ].join('\n')
169
        );
170
        done();
1✔
171
      } else {
NEW
172
        console.log(stderr);
×
173
      }
174
    });
175
  });
176

177
  it('should extract code by section name (## Examples)', function (done) {
1✔
178
    process.exec('cat README.md | ./codedown.js haskell --section "## Examples"', function (err, stdout, stderr) {
1✔
179
      if (!err) {
1!
180
        assert.equal(
1✔
181
          stdout,
182
          [ 'x :: Int'
183
          , 'x = 42'
184
          , ''
185
          , 'main :: IO ()'
186
          , 'main = putStrLn $ show x'
187
          , ''
188
          ].join('\n')
189
        );
190
        done();
1✔
191
      } else {
192
        console.log(stderr);
×
193
      }
194
    });
195
  });
196

197
  it('should extract code by section name (### Variables in different languages)', function (done) {
1✔
198
    process.exec('cat README.md | ./codedown.js haskell --section "### Variables in different languages"', function (err, stdout, stderr) {
1✔
199
      if (!err) {
1!
200
        assert.equal(
1✔
201
          stdout,
202
          [ 'x :: Int'
203
          , 'x = 42'
204
          , ''
205
          ].join('\n')
206
        );
207
        done();
1✔
208
      } else {
209
        console.log(stderr);
×
210
      }
211
    });
212
  });
213

214
  it('should extract code by section name (### Console output in different languages)', function (done) {
1✔
215
    process.exec('cat README.md | ./codedown.js haskell --section "### Console output in different languages"', function (err, stdout, stderr) {
1✔
216
      if (!err) {
1!
217
        assert.equal(
1✔
218
          stdout,
219
          [ 'main :: IO ()'
220
          , 'main = putStrLn $ show x'
221
          , ''
222
          ].join('\n')
223
        );
224
        done();
1✔
225
      } else {
226
        console.log(stderr);
×
227
      }
228
    });
229
  });
230

231
  it('should extract code by multiple section names', function (done) {
1✔
232
    process.exec(
1✔
233
      'cat README.md | ./codedown.js haskell --section "### Variables in different languages" --section "### Console output in different languages"',
234
      function (err, stdout, stderr) {
235
        if (!err) {
1!
236
          assert.equal(
1✔
237
            stdout,
238
            [ 'x :: Int'
239
            , 'x = 42'
240
            , ''
241
            , 'main :: IO ()'
242
            , 'main = putStrLn $ show x'
243
            , ''
244
            ].join('\n')
245
          );
246
          done();
1✔
247
        } else {
NEW
248
          console.log(stderr);
×
249
        }
250
      }
251
    );
252
  });
253

254
  it('should extract any code if language is *', function (done) {
1✔
255
    process.exec('cat README.md | ./codedown.js "*"', function (err, stdout, stderr) {
1✔
256
      if (!err) {
1!
257
        assert.equal(
1✔
258
          stdout,
259
          [ 'x :: Int'
260
          , 'x = 42'
261
          , ''
262
          , 'var x = 42;'
263
          , ''
264
          , 'val x = 42'
265
          , ''
266
          , 'main :: IO ()'
267
          , 'main = putStrLn $ show x'
268
          , ''
269
          , 'console.log(x);'
270
          , ''
271
          , 'println(x)'
272
          , ''
273
          ].join('\n')
274
        );
275
        done();
1✔
276
      } else {
277
        console.log(stderr);
×
278
      }
279
    });
280
  });
281

282
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc