uses
  dbench,
  derror,
  dstream,
  dstreammem,
  dstreamfile,
  dnode,
  djson_sax,
  djson_node,
  djson;

var
  C: AnsiChar;
  Stream: PStream;
  StreamMem: TStreamMem;
  StreamFile: TStreamFile;
  Json: TJson;
  Parser: TJsonParser;
  NodeManager: TNodeManagerStatic;
  Value: TNodeValue;

procedure OldTest;
begin
  if Parser.Parse(Stream, @Json) then begin
    DumpJson(@Json);
	Json.Done;
	Writeln;
  end else
    Writeln(Parser.Error);
  Stream.Done;
end;

procedure OldTestFile(const S: AnsiString);
begin
  StreamFile.Init(S, FM_READ);
  Stream := @StreamFile;
  OldTest;
end;

procedure OldTestStr(const S: AnsiString);
begin
  StreamMem.Init(@S[1], Length(S));
  Stream := @StreamMem;
  OldTest;
end;

procedure TestStr(const S: AnsiString);
var
  Error: TError;
  OutStream: TStreamFile;
begin
  OutStream.Init('', FM_WRITE);
  StreamMem.Init(@S[1], Length(S));
  Stream := @StreamMem;
  if ParseJsonValueToNode(Stream, @NodeManager, Value, False, @Error) then begin
    NodeToJson(Value, @OutStream);
  end else
    Writeln(stderr, 'Error: ', Error.Msg);
  Stream.Done;
  OutStream.Done;
end;

begin
  //OldTestStr('{ x : 5, y : 100, name : "mr X"}');
  //OldTestStr('{x:5,y:100,name:"mr X"}');
  //OldTestStr('{ x : 5, sub : { name : "subobject" }, y : 700 }');
  //OldTestFile('map.json');

  NodeManager.Init;
  TestStr('null');
  TestStr('false');
  TestStr('true');
  TestStr('5');
  TestStr('-5');
  TestStr('+5');
  TestStr('777');
  TestStr('12.25');
  TestStr('[]');
  TestStr('[1,2,3]');
  TestStr('[1,[5,6,7],[8,9,0]]');
  TestStr('{a:1}');
  TestStr('{a:1,b:2,c:3}');
  TestStr('{a:1,b:{e:5,d:6,f:7},c:3}');
  TestStr('{a:1,b:[5,6,7],c:3}');
  TestStr('{"a":1,''b'':2}');
  TestStr('{"a":"string1",''b'':''string2''}');
  TestStr('{"a":"''string1''",''b'':''"string2"''}');
  TestStr('{"a":"\u0044\u004f\u004a\t\\\/"}');
  NodeManager.Done;
end.
