Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: runtime/vm/json_test.cc

Issue 23439002: JSON string decoding for VM debugger (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "platform/json.h" 6 #include "platform/json.h"
7 #include "vm/json_stream.h" 7 #include "vm/json_stream.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 9
10 namespace dart { 10 namespace dart {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 67
68 TEST_CASE(JSON_JSONReader) { 68 TEST_CASE(JSON_JSONReader) {
69 const char* jobj = "{ \"id\": 5, " 69 const char* jobj = "{ \"id\": 5, "
70 " \"command\" : \"Debugger.setBreakpoint\"," 70 " \"command\" : \"Debugger.setBreakpoint\","
71 " \"params\" : { " 71 " \"params\" : { "
72 " \"url\" : \"blah.dart\", " 72 " \"url\" : \"blah.dart\", "
73 " \"foo\" : [null, 1, { }, \"bar\", true, false]," 73 " \"foo\" : [null, 1, { }, \"bar\", true, false],"
74 " \"line\": 111, " 74 " \"line\": 111, "
75 " }," 75 " },"
76 " \"foo\": \"outer foo\", " 76 " \"foo\": \"outer foo\", "
77 " \"quote\": \"\\\"\", "
78 " \"white\": \"\\t \\n\", "
77 "}"; 79 "}";
78 80
79 JSONReader reader(jobj); 81 JSONReader reader(jobj);
80 bool found; 82 bool found;
83 char s[128];
81 84
82 found = reader.Seek("id"); 85 found = reader.Seek("id");
83 EXPECT(found); 86 EXPECT(found);
84 EXPECT_EQ(reader.Type(), JSONReader::kInteger); 87 EXPECT_EQ(reader.Type(), JSONReader::kInteger);
85 found = reader.Seek("foo"); 88 found = reader.Seek("foo");
86 EXPECT(found); 89 EXPECT(found);
87 EXPECT_EQ(reader.Type(), JSONReader::kString); 90 EXPECT_EQ(reader.Type(), JSONReader::kString);
88 EXPECT(reader.IsStringLiteral("outer foo")); 91 EXPECT(reader.IsStringLiteral("outer foo"));
92
93 found = reader.Seek("quote");
94 EXPECT(found);
95 EXPECT_EQ(reader.Type(), JSONReader::kString);
96 reader.GetRawValueChars(s, sizeof s);
97 EXPECT_STREQ("\\\"", s);
98 reader.GetDecodedValueChars(s, sizeof s);
99 EXPECT_STREQ("\"", s);
100
101 found = reader.Seek("white");
102 EXPECT(found);
103 EXPECT_EQ(reader.Type(), JSONReader::kString);
104 reader.GetRawValueChars(s, sizeof s);
105 EXPECT_STREQ("\\t \\n", s);
106 reader.GetDecodedValueChars(s, sizeof s);
107 EXPECT_STREQ("\t \n", s);
108
89 found = reader.Seek("line"); 109 found = reader.Seek("line");
90 EXPECT(!found); 110 EXPECT(!found);
91 found = reader.Seek("params"); 111 found = reader.Seek("params");
92 EXPECT(found); 112 EXPECT(found);
93 EXPECT_EQ(reader.Type(), JSONReader::kObject); 113 EXPECT_EQ(reader.Type(), JSONReader::kObject);
94 reader.Set(reader.ValueChars()); 114 reader.Set(reader.ValueChars());
95 found = reader.Seek("foo"); 115 found = reader.Seek("foo");
96 EXPECT(found); 116 EXPECT(found);
97 EXPECT_EQ(reader.Type(), JSONReader::kArray); 117 EXPECT_EQ(reader.Type(), JSONReader::kArray);
98 found = reader.Seek("non-existing"); 118 found = reader.Seek("non-existing");
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 273
254 TEST_CASE(JSON_JSONStream_EscapedString) { 274 TEST_CASE(JSON_JSONStream_EscapedString) {
255 TextBuffer tb(256); 275 TextBuffer tb(256);
256 JSONStream js(&tb); 276 JSONStream js(&tb);
257 js.PrintValue("Hel\"\"lo\r\n\t"); 277 js.PrintValue("Hel\"\"lo\r\n\t");
258 EXPECT_STREQ("\"Hel\\\"\\\"lo\\r\\n\\t\"", tb.buf()); 278 EXPECT_STREQ("\"Hel\\\"\\\"lo\\r\\n\\t\"", tb.buf());
259 } 279 }
260 280
261 281
262 } // namespace dart 282 } // namespace dart
OLDNEW
« runtime/platform/json.cc ('K') | « runtime/vm/debugger_api_impl_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698