-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import message from '../library/message'; | ||
|
||
export default (parsed, when = 'never') => { | ||
const negated = when === 'always'; | ||
const notEmpty = parsed.references.length > 0; | ||
return [ | ||
negated ? !notEmpty : notEmpty, | ||
message(['references', negated ? 'must' : 'may not', 'be empty']) | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import test from 'ava'; | ||
import parse from '../library/parse'; | ||
import referencesEmpty from './references-empty'; | ||
|
||
const messages = { | ||
plain: 'foo: bar', | ||
comment: 'foo: baz\n#1 Comment', | ||
reference: '#comment\nfoo: baz \nCloses #1', | ||
references: '#comment\nfoo: bar \nCloses #1, #2, #3' | ||
}; | ||
|
||
const parsed = { | ||
plain: parse(messages.plain), | ||
comment: parse(messages.comment), | ||
reference: parse(messages.reference), | ||
references: parse(messages.references) | ||
}; | ||
|
||
test('defaults to never and fails for plain', async t => { | ||
const [actual] = referencesEmpty(await parsed.plain); | ||
const expected = false; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('defaults to never and succeeds for reference', async t => { | ||
const [actual] = referencesEmpty(await parsed.reference); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('fails for comment with never', async t => { | ||
const [actual] = referencesEmpty(await parsed.comment, 'never'); | ||
const expected = false; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('succeeds for comment with always', async t => { | ||
const [actual] = referencesEmpty(await parsed.comment, 'always'); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('succeeds for reference with never', async t => { | ||
const [actual] = referencesEmpty(await parsed.reference, 'never'); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('fails for reference with always', async t => { | ||
const [actual] = referencesEmpty(await parsed.reference, 'always'); | ||
const expected = false; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('succeeds for references with never', async t => { | ||
const [actual] = referencesEmpty(await parsed.references, 'never'); | ||
const expected = true; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('fails for references with always', async t => { | ||
const [actual] = referencesEmpty(await parsed.references, 'always'); | ||
const expected = false; | ||
t.is(actual, expected); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters