2014-01-23 13:44:49 -08:00
|
|
|
#include "spec_helper.h"
|
|
|
|
|
#include "document.h"
|
|
|
|
|
|
|
|
|
|
extern TSParseConfig ts_parse_config_json;
|
|
|
|
|
|
|
|
|
|
START_TEST
|
|
|
|
|
|
|
|
|
|
describe("json", []() {
|
|
|
|
|
TSDocument *document;
|
|
|
|
|
|
|
|
|
|
before_each([&]() {
|
|
|
|
|
document = TSDocumentMake();
|
|
|
|
|
TSDocumentSetUp(document, ts_parse_config_json);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("parses strings", [&]() {
|
2014-01-23 23:56:37 -08:00
|
|
|
TSDocumentSetText(document, "\"string\"");
|
2014-01-23 13:44:49 -08:00
|
|
|
AssertThat(string(TSDocumentToString(document)), Equals("(value (string))"));
|
|
|
|
|
});
|
2014-01-23 23:56:37 -08:00
|
|
|
|
|
|
|
|
it("parses objects", [&]() {
|
2014-01-24 18:25:56 -08:00
|
|
|
TSDocumentSetText(document, "{\"key1\":1,\"key2\":2}");
|
2014-01-28 13:27:30 -08:00
|
|
|
AssertThat(string(TSDocumentToString(document)), Equals("(value (object (token5) (string) (token6) (value (number)) (repeat_helper1 (token2) (string) (token6) (value (number))) (token7)))"));
|
|
|
|
|
|
|
|
|
|
TSDocumentSetText(document, "{\"key1\":1}");
|
|
|
|
|
AssertThat(string(TSDocumentToString(document)), Equals("(value (object (token5) (string) (token6) (value (number)) (token3) (token7)))"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("parses arrays", [&]() {
|
|
|
|
|
TSDocumentSetText(document, "[1,2,3]");
|
|
|
|
|
AssertThat(string(TSDocumentToString(document)), Equals("(value (array (token1) (value (number)) (repeat_helper2 (token2) (value (number)) (repeat_helper2 (token2) (value (number)))) (token4)))"));
|
2014-01-23 23:56:37 -08:00
|
|
|
});
|
2014-01-23 13:44:49 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
END_TEST
|