1 | 'use strict'
|
2 |
|
3 | var Yadda = require('yadda')
|
4 | var English = Yadda.localisation.English
|
5 | var Dictionary = Yadda.Dictionary
|
6 | var assert = require('assert')
|
7 | var safeParse = require("safe-json-parse/callback")
|
8 | var starscream = require('../..')
|
9 |
|
10 |
|
11 | module.exports = (function() {
|
12 |
|
13 | var dictionary = new Dictionary()
|
14 | .define('json', /([^\u0000]*)/, function(text, cb) {
|
15 | safeParse(text, cb)
|
16 | })
|
17 | .define('object', /([^\u0000]*)/, function(text, cb) {
|
18 | var x = 0; x + 1
|
19 | cb(null, eval('x = ' + text))
|
20 | })
|
21 |
|
22 | var library = English.library(dictionary)
|
23 |
|
24 | .when('I transform the following json:$json', function(source, cb) {
|
25 | this.ctx.source = source
|
26 | cb()
|
27 | })
|
28 |
|
29 | .define("Using the mapping:$json", function(mapping, cb) {
|
30 | this.ctx.options.mapping = mapping
|
31 | cb()
|
32 | })
|
33 |
|
34 | .then("I should get:$object", function(expected, cb) {
|
35 | starscream(this.ctx.options, this.ctx.source, function(err, output) {
|
36 | assert.ifError(err)
|
37 | assert.deepEqual(output, expected)
|
38 | cb()
|
39 | })
|
40 | })
|
41 |
|
42 | return library
|
43 | })() |
\ | No newline at end of file |