-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(en): Adding repeating graph builder
- Loading branch information
1 parent
b37f557
commit a6f6e09
Showing
6 changed files
with
208 additions
and
15 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,27 @@ | ||
import GraphBuilder from '../../graph/builder'; | ||
|
||
export default function(language) { | ||
return function(graph) { | ||
const builder = new GraphBuilder(language) | ||
.name('repeating[' + graph.options.name + ']') | ||
|
||
.skipPunctuation(); | ||
|
||
// If the value supports partial matching so does this repeating value | ||
if(graph.options.supportsPartial) { | ||
builder.allowPartial(); | ||
} | ||
|
||
if(graph.options.mapper) { | ||
// If the graph has requested that matches are mapped - map each match | ||
builder.mapResults(values => values.map(graph.options.mapper)); | ||
} | ||
|
||
// Add the value and how it can be repeated | ||
return builder | ||
.add(graph, v => [ v[0] ]) | ||
|
||
.add([ GraphBuilder.result(), GraphBuilder.result() ], v => v[0].concat(v[1])) | ||
.add([ GraphBuilder.result(), 'and', GraphBuilder.result() ], v => v[0].concat(v[1])); | ||
}; | ||
} |
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
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,46 @@ | ||
import en from '../../../src/language/en'; | ||
import { testRunner } from '../helpers'; | ||
import GraphBuilder from '../../../src/graph/builder'; | ||
|
||
const phrase = new GraphBuilder(en) | ||
.name('phrase') | ||
|
||
.allowPartial() | ||
|
||
.add('Hello', () => 1) | ||
.add('World', () => 2) | ||
|
||
.toMatcher(); | ||
|
||
const test = testRunner(en.repeating(phrase) | ||
.onlyBest() | ||
.toMatcher() | ||
); | ||
|
||
describe('English', function() { | ||
|
||
describe('Repeating', function() { | ||
test('Hello', {}, [ 1 ]); | ||
|
||
test('World', {}, [ 2 ]); | ||
|
||
test('Hello and World', {}, [ 1, 2 ]); | ||
|
||
test('Hello World', {}, [ 1, 2 ]); | ||
|
||
test('World, Hello', {}, [ 2, 1 ]); | ||
|
||
test('Hello and World Hello', {}, [ 1, 2, 1 ]); | ||
|
||
test('Hel', { partial: false }, null); | ||
|
||
test('Hel', { partial: true }, [ 1 ]); | ||
|
||
test('Hello Wo', { partial: true }, [ 1, 2 ]); | ||
|
||
test('Hello and Wo', { partial: true }, [ 1, 2 ]); | ||
|
||
test('He and Wo', { partial: true }, null); | ||
}); | ||
|
||
}); |
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