1
+ import json5Patcher = require( "../../Tasks/JsonPatch/json5Patcher" ) ;
2
+ var JSON5 = require ( "../../Tasks/JsonPatch/node_modules/json5" ) ;
3
+
4
+
5
+
6
+ describe ( "JSON5 Patcher" , ( ) => {
7
+
8
+ describe ( "Operations" , ( ) => {
9
+
10
+ var source : string ;
11
+
12
+ beforeEach ( function ( ) {
13
+ source = JSON5 . stringify ( {
14
+ sampleValue : "12"
15
+ } ) ;
16
+ } ) ;
17
+
18
+ describe ( "JSON5 Output Enabled" , ( ) => {
19
+ describe ( "Add" , ( ) => {
20
+ it ( ": should support basic add." , ( ) => {
21
+ var patcher = new json5Patcher . Json5Patcher ( [
22
+ {
23
+ op : "add" , path : "/added" , value : { }
24
+ } , {
25
+ op : "add" , path : "/added/value" , value : "42"
26
+ }
27
+ ] , true ) ;
28
+ var result = JSON5 . parse ( patcher . apply ( source ) ) ;
29
+
30
+ expect ( result ) . toBeDefined ( ) ;
31
+ expect ( result . sampleValue ) . toBeDefined ( ) ;
32
+ expect ( result . sampleValue ) . toEqual ( "12" ) ;
33
+ expect ( result . added . value ) . toEqual ( "42" ) ;
34
+ } ) ;
35
+ } ) ;
36
+ } ) ;
37
+
38
+ describe ( "JSON5 Output Disabled" , ( ) => {
39
+ describe ( "Add" , ( ) => {
40
+ it ( ": should support basic add." , ( ) => {
41
+ var patcher = new json5Patcher . Json5Patcher ( [
42
+ {
43
+ op : "add" , path : "/added" , value : { }
44
+ } , {
45
+ op : "add" , path : "/added/value" , value : "42"
46
+ }
47
+ ] , false ) ;
48
+ var result = JSON . parse ( patcher . apply ( source ) ) ;
49
+
50
+ expect ( result ) . toBeDefined ( ) ;
51
+ expect ( result . sampleValue ) . toBeDefined ( ) ;
52
+ expect ( result . sampleValue ) . toEqual ( "12" ) ;
53
+ expect ( result . added . value ) . toEqual ( "42" ) ;
54
+ } ) ;
55
+ } ) ;
56
+ } ) ;
57
+ } ) ;
58
+ } ) ;
0 commit comments