Skip to content

Commit

Permalink
C style multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzmmr committed Jan 9, 2016
1 parent b2e8089 commit 9d84d17
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "comcom",
"version": "1.0.2",
"version": "1.0.3",
"description": "A simple and easy to use comment to comment parser",
"main": "dst/lib/index.js",
"scripts": {
Expand Down
13 changes: 11 additions & 2 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
* ```
*
* @module comcom
* @version 1.0.2
* @version 1.0.3
* @author mrzmmr
*/

/*
* Imports
*/
import {through} from 'through'
import {defop} from 'defop'

Expand All @@ -24,7 +27,13 @@ import {defop} from 'defop'
*/
export const CSTYLE_SINGLE = /\s*(?=\/)\/(?=\/)\//g

export function splitLine(options) {
/*
* C style multiple line comment
*/
export const CSTYLE_MULTIPLE_BEG = /\s*(?=\/)\/(?=\*)\**/g
export const CSTYLE_MULTIPLE_END = /\s*(?=\*)\**(?=\/)\//g

export function split_line(options) {
options = defop(options)

return through(function (chunk) {
Expand Down
22 changes: 22 additions & 0 deletions src/tst/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,29 @@ import * as tap from 'tap'
tap.test('Regex#CSTYLE_SINGLE', (assert) => {
let t1 = '// Hello'
let t2 = ' // world'

assert.ok(t1.startsWith(t1.match(lib.CSTYLE_SINGLE)[0]))
assert.ok(t2.startsWith(t2.match(lib.CSTYLE_SINGLE)[0]))
assert.end()
})

tap.test('Regex#CSTYLE_MULTIPLE', (assert) => {
let t1 = '/* Hello'
let t2 = '/** World'
let t3 = ' /* Hello'
let t4 = ' /** World'
let t5 = '*/'
let t6 = '**/'
let t7 = ' */'
let t8 = ' **/'

assert.ok(t1.startsWith(t1.match(lib.CSTYLE_MULTIPLE_BEG)[0]))
assert.ok(t2.startsWith(t2.match(lib.CSTYLE_MULTIPLE_BEG)[0]))
assert.ok(t3.startsWith(t3.match(lib.CSTYLE_MULTIPLE_BEG)[0]))
assert.ok(t4.startsWith(t4.match(lib.CSTYLE_MULTIPLE_BEG)[0]))
assert.ok(t5.startsWith(t5.match(lib.CSTYLE_MULTIPLE_END)[0]))
assert.ok(t6.startsWith(t6.match(lib.CSTYLE_MULTIPLE_END)[0]))
assert.ok(t7.startsWith(t7.match(lib.CSTYLE_MULTIPLE_END)[0]))
assert.ok(t8.startsWith(t8.match(lib.CSTYLE_MULTIPLE_END)[0]))
assert.end()
})

0 comments on commit 9d84d17

Please sign in to comment.