UNPKG

1.13 kBJavaScriptView Raw
1'use strict'
2
3var Yadda = require('yadda')
4var English = Yadda.localisation.English
5var Dictionary = Yadda.Dictionary
6var assert = require('assert')
7var safeParse = require("safe-json-parse/callback")
8var starscream = require('../..')
9
10
11module.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