@@ -78,3 +78,78 @@ greet()`)).toThrow();
7878{foo: "bar"}` ) ) . toThrow ( ) ;
7979 } ) ;
8080} ) ;
81+
82+ describe ( 'stringify' , ( ) => {
83+ test . concurrent ( 'str' , ( ) => {
84+ expect ( AiSON . stringify ( 'Ai-chan kawaii' ) ) . toEqual ( '"Ai-chan kawaii"' ) ;
85+ } ) ;
86+
87+ test . concurrent ( 'number' , ( ) => {
88+ expect ( AiSON . stringify ( 42 ) ) . toEqual ( '42' ) ;
89+ } ) ;
90+
91+ test . concurrent ( 'bool' , ( ) => {
92+ expect ( AiSON . stringify ( true ) ) . toEqual ( 'true' ) ;
93+ } ) ;
94+
95+ test . concurrent ( 'null' , ( ) => {
96+ expect ( AiSON . stringify ( null ) ) . toEqual ( 'null' ) ;
97+ } ) ;
98+
99+ test . concurrent ( 'array' , ( ) => {
100+ expect ( AiSON . stringify ( [ 1 , 2 , 3 ] ) ) . toEqual ( '[1, 2, 3]' ) ;
101+ } ) ;
102+
103+ test . concurrent ( 'object' , ( ) => {
104+ expect ( AiSON . stringify ( { key : 'value' } ) ) . toEqual ( '{key: "value"}' ) ;
105+ } ) ;
106+
107+ test . concurrent ( 'nested' , ( ) => {
108+ expect ( AiSON . stringify ( [ { key : 'value' } ] ) ) . toEqual ( '[{key: "value"}]' ) ;
109+ } ) ;
110+
111+ test . concurrent ( 'pretty print: array' , ( ) => {
112+ expect ( AiSON . stringify ( [ 1 , 2 , 3 ] , null , 2 ) ) . toEqual ( `[
113+ 1,
114+ 2,
115+ 3
116+ ]` ) ;
117+ } ) ;
118+
119+ test . concurrent ( 'pretty print: object' , ( ) => {
120+ expect ( AiSON . stringify ( { key : 'value' , foo : 'bar' } , null , 2 ) ) . toEqual ( `{
121+ key: "value",
122+ foo: "bar"
123+ }` ) ;
124+ } ) ;
125+
126+ test . concurrent ( 'pretty print: nested' , ( ) => {
127+ expect ( AiSON . stringify ( { arr : [ 1 , 2 , { key : 'value' } ] } , null , 2 ) ) . toEqual ( `{
128+ arr: [
129+ 1,
130+ 2,
131+ {
132+ key: "value"
133+ }
134+ ]
135+ }` ) ;
136+ } ) ;
137+
138+ test . concurrent ( 'custom indent' , ( ) => {
139+ expect ( AiSON . stringify ( { key : 'value' , foo : 'bar' } , null , '\t' ) ) . toEqual ( `{
140+ \tkey: "value",
141+ \tfoo: "bar"
142+ }` ) ;
143+ } ) ;
144+
145+ test . concurrent ( 'no indent when indent is 0' , ( ) => {
146+ expect ( AiSON . stringify ( { key : 'value' , foo : 'bar' } , null , 0 ) ) . toEqual ( '{key: "value", foo: "bar"}' ) ;
147+ } ) ;
148+
149+ test . concurrent ( 'can parse generated aison' , ( ) => {
150+ const obj = { arr : [ 1 , 2 , { key : 'value' } ] } ;
151+ const aison = AiSON . stringify ( obj ) ;
152+ const parsed = AiSON . parse ( aison ) ;
153+ expect ( parsed ) . toStrictEqual ( obj ) ;
154+ } ) ;
155+ } ) ;
0 commit comments